You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(rules): improve precision of 4 high-FP dotnet opengrep rules
Addresses customer SAST evaluation feedback where 4 rules produced 150/170
false positives (88% of all FPs), inflating the reported FP rate to 91%.
Rules fixed:
- dotnet-xss-response-write: Convert to taint mode. Previously matched any
.Write() call including Serilog ITextFormatter log sinks. Now requires
data flow from user input sources to Response.Write sinks.
- dotnet-hardcoded-credentials: Add value inspection and credential API
patterns. Previously matched on variable names alone, flagging config
key paths like "UseCaptchaOnResetPassword".
- dotnet-crypto-failures: Target actual weak algorithms (3DES, DES, RC2,
RijndaelManaged) instead of Encoding.UTF8.GetBytes() which flagged the
recommended SHA256.HashData(Encoding.UTF8.GetBytes(...)) pattern.
- dotnet-path-traversal: Convert to taint mode. Previously matched all
Path.Combine() calls including those using framework-provided paths
like _env.WebRootPath.
Validated with opengrep v1.19.0 against NIST Juliet C# test suite:
xss-response-write: Prec 41.6% -> 100%, Recall 47.8% -> 24.3%
hardcoded-credentials: Prec 0.0% -> 100%, Recall 0.0% -> 3.6%
crypto-failures: Prec 36.7% -> 100%, Recall 51.4% -> 50.0%
path-traversal: Prec 0.0% -> 100%, Recall 0.0% -> 45.2%
# Hardcoded credentials - matches both variable-name patterns AND credential API usage
145
145
- id: dotnet-hardcoded-credentials
146
146
message: "Hard-coded credentials detected. Embedding secrets in source code makes them easily discoverable and impossible to rotate. Use environment variables or a secrets manager instead."
# Pattern 2: Credential APIs called with hardcoded string literals
171
+
- pattern: new NetworkCredential($USER, "...", ...)
172
+
- pattern: new NetworkCredential("...", "...", ...)
173
+
- pattern: new SqlConnection("...");
174
+
- pattern: new PasswordDeriveBytes("...", ...)
161
175
metadata:
162
176
category: security
163
177
cwe: CWE-798
@@ -223,35 +237,129 @@ rules:
223
237
owasp: "A07:2021"
224
238
fix: "Never return true from ServerCertificateCustomValidationCallback. Use the default certificate validation from ServicePointManager."
225
239
226
-
# XSS vulnerabilities
240
+
# XSS vulnerabilities - taint mode for accurate user-input tracking
227
241
- id: dotnet-xss-response-write
228
242
message: "Cross-site scripting (XSS) vulnerability detected. User input is rendered in HTML output without proper escaping, allowing attackers to inject malicious scripts. Sanitize or escape all user input before rendering."
# HttpResponse parameter pattern (Juliet, ASP.NET handlers)
288
+
- pattern: $RESP.Write(...)
289
+
pattern-sanitizers:
290
+
- pattern-either:
291
+
- pattern: HttpUtility.HtmlEncode(...)
292
+
- pattern: HtmlEncoder.Default.Encode(...)
293
+
- pattern: WebUtility.HtmlEncode(...)
294
+
- pattern: Server.HtmlEncode(...)
295
+
- pattern: AntiXssEncoder.HtmlEncode(...)
235
296
metadata:
236
297
category: security
237
298
cwe: CWE-79
238
-
confidence: medium
299
+
confidence: high
239
300
subcategory: xss
240
301
vulnerability_class: "Cross-Site Scripting (XSS)"
241
302
owasp: "A03:2021"
242
303
fix: "Use Razor auto-encoding or HtmlEncoder.Default.Encode(). Never use Html.Raw() with user input. Validate input on both client and server."
243
304
244
-
# Path traversal
305
+
# Path traversal - taint mode for accurate user-input tracking
245
306
- id: dotnet-path-traversal
246
307
message: "Path traversal vulnerability detected. User input is used in file paths without validation, allowing attackers to access files outside the intended directory. Validate and canonicalize paths before use."
# Framework-provided base paths are safe sources, not sanitizers,
361
+
# but if the result is validated against a base we consider it sanitized
362
+
- pattern: $X.StartsWith($BASE)
255
363
metadata:
256
364
category: security
257
365
cwe: CWE-22
@@ -623,23 +731,34 @@ rules:
623
731
vulnerability_class: "Access Control Violation"
624
732
fix: "Review authorization logic for bypass conditions. Use policy-based authorization with IAuthorizationHandler. Test authorization with different user roles."
625
733
626
-
# A02: Cryptographic Failures
734
+
# A02: Cryptographic Failures - targets actual weak algorithm usage
627
735
- id: dotnet-crypto-failures
628
736
message: "Weak cryptographic algorithm detected. Using broken or outdated algorithms may allow attackers to decrypt data or forge signatures. Use modern algorithms like AES-256, SHA-256, or Ed25519."
fix: "Use SHA256.Create() instead of MD5/SHA1. Use Aes.Create() with CipherMode.CBC or AesGcm for encryption."
761
+
fix: "Use Aes.Create() instead of 3DES/DES/RC2. Use Rfc2898DeriveBytes or HKDF for key derivation from passwords. Never use raw Encoding.GetBytes() as a crypto key."
0 commit comments