Java: fix @Pattern sanitization for java/path-injection#22119
Open
owen-mc wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the java/path-injection sanitizer modeling so that regex constraints expressed via @javax.validation.constraints.Pattern are treated as sanitizers, and extends the Java query tests accordingly.
Changes:
- Update
PathSanitizer.qllto handle@Pattern-based regex checks as sanitizers in the directory-characters sanitizer logic. - Add a new Spring controller test case exercising a vulnerable flow and a
@Pattern-constrained variant, and extend the test classpath with a Bean Validation stub. - Update the expected results and add a change note documenting the analysis behavior change.
Show a summary per file
| File | Description |
|---|---|
| java/ql/test/query-tests/security/CWE-022/semmle/tests/TaintedPath.expected | Updates expected results to include the new test case output. |
| java/ql/test/query-tests/security/CWE-022/semmle/tests/SanitizationTests2.java | Adds a new test controller covering @Pattern sanitization behavior. |
| java/ql/test/query-tests/security/CWE-022/semmle/tests/options | Adds the javax-validation-constraints stub to the test compilation classpath. |
| java/ql/lib/semmle/code/java/security/PathSanitizer.qll | Adjusts sanitizer logic to recognize annotation-based regex checks appropriately. |
| java/ql/lib/change-notes/2026-07-03-fix-pattern-sanitizer-tainted-path.md | Documents the analysis change in a new change note. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Low
a21389f to
e5bd62d
Compare
It is better to have the logic in one place, to avoid encountering this bug again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a bug in the way this was previously implemented for this query. This PR adds a test showing the bug, fixes the bug and the test, and then refactors how barrier nodes should be created for
RegexMatchs to avoid the same bug happening in future.