Skip to content

Java: add RegexpCheckBarrier to trust-boundary-violation sanitizers#21656

Open
MarkLee131 wants to merge 3 commits intogithub:mainfrom
MarkLee131:fix/trust-boundary-regexp-barrier
Open

Java: add RegexpCheckBarrier to trust-boundary-violation sanitizers#21656
MarkLee131 wants to merge 3 commits intogithub:mainfrom
MarkLee131:fix/trust-boundary-regexp-barrier

Conversation

@MarkLee131
Copy link
Copy Markdown
Contributor

This is an experimental fix for #21655:

The trust-boundary-violation query only recognized OWASP ESAPI validators as sanitizers. ESAPI is rarely used in modern Java projects, while regex validation via String.matches() and @javax.validation.constraints.Pattern is the standard approach in Spring/Jakarta applications.

RegexpCheckBarrier already exists in Sanitizers.qll and is used by other queries (e.g., RequestForgery). This wires it into TrustBoundaryConfig, so patterns like input.matches("[a-zA-Z0-9]+") and @pattern annotations are recognized as sanitizers, consistent with the existing ESAPI treatment.

The trust-boundary-violation query only recognized OWASP ESAPI validators
as sanitizers. ESAPI is rarely used in modern Java projects, while regex
validation via String.matches() and @javax.validation.constraints.Pattern
is the standard approach in Spring/Jakarta applications.

RegexpCheckBarrier already exists in Sanitizers.qll and is used by other
queries (e.g., RequestForgery). This wires it into TrustBoundaryConfig,
so patterns like input.matches("[a-zA-Z0-9]+") and @pattern annotations
are recognized as sanitizers, consistent with the existing ESAPI treatment.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Java trust-boundary-violation query to treat regex-based validation as a sanitizer/barrier, aligning it with common Spring/Jakarta validation patterns and reducing false positives compared to ESAPI-only recognition.

Changes:

  • Wire RegexpCheckBarrier into TrustBoundaryConfig.isBarrier(...) for java/trust-boundary-violation.
  • Add a query-test scenario intended to demonstrate regex guard sanitization.
  • Add a change-note documenting the expanded sanitizer recognition.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
java/ql/lib/semmle/code/java/security/TrustBoundaryViolationQuery.qll Extends the trust-boundary barrier set to include RegexpCheckBarrier.
java/ql/test/query-tests/security/CWE-501/TrustBoundaryViolations.java Adds a “GOOD” case using a String.matches(...) guard for session writes.
java/ql/lib/change-notes/2026-04-04-trust-boundary-regexp-barrier.md Documents the query behavior change as a minor analysis improvement.

…ons.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MarkLee131 MarkLee131 requested a review from a team as a code owner April 4, 2026 14:02
Adds a dedicated test verifying that fields annotated with
@javax.validation.constraints.Pattern are recognized as sanitized
by RegexpCheckBarrier, in addition to the existing String.matches()
guard test.
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.

2 participants