|
24 | 24 | import org.json.JSONArray; |
25 | 25 | import org.json.JSONException; |
26 | 26 | import org.json.JSONObject; |
| 27 | +import org.owasp.benchmarkutils.score.CweNumber; |
27 | 28 |
|
28 | 29 | public class CodeSonarReader extends SarifReader { |
29 | 30 |
|
@@ -68,6 +69,31 @@ public Map<String, Integer> customRuleCweMappings(JSONObject tool) { |
68 | 69 | } |
69 | 70 | } |
70 | 71 |
|
| 72 | + // CodeSonar has some non-security rules that don't map to CWEs. So we manaully add those as |
| 73 | + // DONTCARES |
| 74 | + mappings.put("Avoid zero-length array allocations (C#)", CweNumber.DONTCARE); |
| 75 | + mappings.put("Do not initialize unnecessarily (C#)", CweNumber.DONTCARE); |
| 76 | + mappings.put("Do not raise reserved exception types (C#)", CweNumber.DONTCARE); |
| 77 | + mappings.put("Do not use 'WaitAll' with a single task (C#)", CweNumber.DONTCARE); |
| 78 | + mappings.put("Identifiers should not contain underscores (C#)", CweNumber.DONTCARE); |
| 79 | + mappings.put("Mark members as static (C#)", CweNumber.DONTCARE); |
| 80 | + mappings.put("Seal internal types (C#)", CweNumber.DONTCARE); // Improves performance |
| 81 | + mappings.put( |
| 82 | + "Specify IFormatProvider (C#)", CweNumber.DONTCARE); // Localization Issue (fonts) |
| 83 | + mappings.put("Use ordinal string comparison (C#)", CweNumber.DONTCARE); |
| 84 | + mappings.put("Use XmlReader for XPathDocument constructor (C#)", CweNumber.DONTCARE); |
| 85 | + |
| 86 | + // CodeSonar has numerous security rules that map to ROSLYN.SECURITY rules. For example, |
| 87 | + // they have a rule: "ROSLYN.SECURITY.CA5350 : Do Not Use Weak Cryptographic Algorithms |
| 88 | + // (C#)" that is described at: |
| 89 | + // https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca5350 |
| 90 | + // Unfortunately, they don't seem to be mapped to CWEs, so we have to map them manually. |
| 91 | + mappings.put("Do Not Use Broken Cryptographic Algorithms (C#)", CweNumber.WEAK_CRYPTO_ALGO); |
| 92 | + mappings.put("Do Not Use Weak Cryptographic Algorithms (C#)", CweNumber.WEAK_CRYPTO_ALGO); |
| 93 | + mappings.put("Insecure DTD processing in XML (C#)", CweNumber.XXE); |
| 94 | + mappings.put( |
| 95 | + "Rethrow to preserve stack details (C#)", |
| 96 | + 392); // CWE-392: Missing Report of Error Condition |
71 | 97 | return mappings; |
72 | 98 | } |
73 | 99 | } |
0 commit comments