Version: SonarQube 8.9.5, Azure DevOps Server 2020.1.1 using SonarQube build tasks
What am I trying to achieve: After enabling rule CA3147 in the Roslyn scanner, and seeing the results show up in SonarQube, I’d like to classify those issues as Vulnerability instead of Code Smell.
What have I tried so far:
- Added the Microsoft.CodeAnalysis.NetAnalyzers NuGet package to my project
- Configured the .ruleset and .editorconfig files to include CA3147 as a warning
- Confirmed that the compiler finds associated issues
- Confirmed that those issues show up in SonarQube after a build & code analysis
- Reviewed Importing Third-Party Issues | SonarQube Docs (.NET section at the bottom)
- Reviewed CA3147: Mark verb handlers with ValidateAntiForgeryToken (code analysis) - .NET | Microsoft Docs, where the rule category is listed as “Security”
- Added sonar.cs.roslyn.vulnerabilityCategories=Microsoft.CodeAnalysis.NetAnalyzers.Security,Security to the code analysis configuration
- Added “Microsoft.CodeAnalysis.NetAnalyzers.Security” and “Security” in the “Rule categories associated with Vulnerabilities” section in Administration - External Analyzers in SonarQube
- Reviewed various articles on Google, but I seem to be either the first person to try this or I’m missing something really obvious.
The issues still show up as Code Smell. I have a feeling that the category identifier used by SonarQube is something other than “Microsoft.CodeAnalysis.NetAnalyzers.Security” or just “Security”. Where can I find this category? Neither the build log nor the code analysis log seem to include it. In Visual Studio, the category is just listed as “Security”.
In the issues itself, when I click on “Why is this an issue?”, I see roslyn:CA3147 as a rule identifier in the top right corner. As a future improvement, could you add the category identifier there?
Edit: Here’s an excerpt from the issues.json that Roslyn creates during the analysis, and that is then processed by SonarQube. The category is set as “Security” there:
"CA3147": {
"id": "CA3147",
"shortDescription": "Mark Verb Handlers With Validate Antiforgery Token",
"defaultLevel": "warning",
"helpUri": "https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca3147",
"properties": {
"category": "Security",
"isEnabledByDefault": true,
"tags": [
"Telemetry",
"EnabledRuleInAggressiveMode"
]
}
},