Skip to content

Commit dc28695

Browse files
committed
fix(rules): correct path-traversal StartsWith sanitizer in dotnet rule
The $X.StartsWith($BASE) sanitizer was matching the boolean expression instead of marking the checked path variable as sanitized, so correctly validated paths were still flagged as tainted. Use focus-metavariable + by-side-effect so the sanitizer applies to $X itself. Verified with a synthetic test case: scans of an unsanitized File.ReadAllText still fire, but the same call guarded by full.StartsWith("/var/data/") no longer does. Juliet CWE-23/36 results unchanged at 432 findings (Juliet test cases do not exercise StartsWith validation). opengrep --validate and pytest pass.
1 parent 5b3c12b commit dc28695

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

socket_basics/rules/dotnet.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,14 @@ rules:
406406
- pattern: Directory.GetFiles(...)
407407
- pattern: Directory.EnumerateFiles(...)
408408
pattern-sanitizers:
409-
- pattern-either:
410-
- pattern: Path.GetFileName(...)
411-
# Framework-provided base paths are safe sources, not sanitizers,
412-
# but if the result is validated against a base we consider it sanitized
409+
- pattern: Path.GetFileName(...)
410+
# Treat the checked path variable as sanitized after a base-path validation.
411+
# focus-metavariable + by-side-effect cleans $X itself, not just the
412+
# StartsWith(...) boolean expression.
413+
- patterns:
413414
- pattern: $X.StartsWith($BASE)
415+
- focus-metavariable: $X
416+
by-side-effect: true
414417
metadata:
415418
category: security
416419
cwe: CWE-22

0 commit comments

Comments
 (0)