Skip to content

Java: fix @Pattern sanitization for java/path-injection#22119

Open
owen-mc wants to merge 5 commits into
github:mainfrom
owen-mc:java/fix-tainted-path-pattern-sanitization
Open

Java: fix @Pattern sanitization for java/path-injection#22119
owen-mc wants to merge 5 commits into
github:mainfrom
owen-mc:java/fix-tainted-path-pattern-sanitization

Conversation

@owen-mc

@owen-mc owen-mc commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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.

@owen-mc owen-mc requested a review from a team as a code owner July 3, 2026 10:15
Copilot AI review requested due to automatic review settings July 3, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.qll to 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

Comment thread java/ql/test/query-tests/security/CWE-022/semmle/tests/SanitizationTests2.java Outdated
Comment thread java/ql/test/query-tests/security/CWE-022/semmle/tests/SanitizationTests2.java Outdated
Comment thread java/ql/lib/change-notes/2026-07-03-fix-pattern-sanitizer-tainted-path.md Outdated
@owen-mc owen-mc force-pushed the java/fix-tainted-path-pattern-sanitization branch from a21389f to e5bd62d Compare July 3, 2026 10:35
It is better to have the logic in one place, to avoid encountering this
bug again.
Comment thread java/ql/lib/semmle/code/java/security/Sanitizers.qll Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants