Skip to content

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

Merged
owen-mc merged 6 commits intogithub:mainfrom
MarkLee131:fix/trust-boundary-regexp-barrier
Apr 29, 2026
Merged

Java: add RegexpCheckBarrier to trust-boundary-violation sanitizers#21656
owen-mc merged 6 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.

Comment thread java/ql/test/query-tests/security/CWE-501/TrustBoundaryViolations.java Outdated
Comment thread java/ql/test/query-tests/security/CWE-501/TrustBoundaryViolations.java Outdated
…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.
owen-mc
owen-mc previously approved these changes Apr 29, 2026
Copy link
Copy Markdown
Contributor

@owen-mc owen-mc left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution. One small stylistic point, which doesn't block the PR.

Comment on lines +41 to +44
node instanceof TrustBoundaryValidationSanitizer or
node.getType() instanceof HttpServletSession or
node instanceof SimpleTypeSanitizer
node instanceof SimpleTypeSanitizer or
node instanceof RegexpCheckBarrier
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.

Suggested change
node instanceof TrustBoundaryValidationSanitizer or
node.getType() instanceof HttpServletSession or
node instanceof SimpleTypeSanitizer
node instanceof SimpleTypeSanitizer or
node instanceof RegexpCheckBarrier
node instanceof TrustBoundaryValidationSanitizer

It is slightly preferable to define these sanitizers by introducing classes which extend TrustBoundaryValidationSanitizer. It wasn't done this way before, but if you could tidy it up that would be great. So you'll need to add

class SimpleTypeTrustBoundaryValidationSanitizer extends TrustBoundaryValidationSanitizer instanceof SimpleTypeSanitizer
{ }

class RegexpCheckTrustBoundaryValidationSanitizer extends TrustBoundaryValidationSanitizer instanceof RegexpCheckBarrier
{ }

class HttpServletSessionTypeTrustBoundaryValidationSanitizer extends TrustBoundaryValidationSanitizer
{
  HttpServletSessionTypeTrustBoundaryValidationSanitizer() {
    this.getType() instanceof HttpServletSession
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, GitHub didn't let me apply the suggestion directly from the web UI, so I redid it locally and pushed in d27ee86. Pulled the three sanitizers out into their own classes as you suggested.

…Sanitizer subclasses

Address review feedback by introducing dedicated subclasses of
TrustBoundaryValidationSanitizer for SimpleTypeSanitizer, RegexpCheckBarrier,
and the HttpServletSession type check, so isBarrier only references the
abstract class.
@owen-mc owen-mc merged commit fed42d6 into github:main Apr 29, 2026
21 checks passed
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