Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `java/trust-boundary-violation` query now recognizes regular expression checks (including `String.matches()` guards and `@javax.validation.constraints.Pattern` annotations) as sanitizers, consistent with the existing treatment of ESAPI validators. This reduces false positives when input is validated against a pattern before being stored in a session.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module TrustBoundaryConfig implements DataFlow::ConfigSig {
predicate isBarrier(DataFlow::Node node) {
node instanceof TrustBoundaryValidationSanitizer or
node.getType() instanceof HttpServletSession or
node instanceof SimpleTypeSanitizer
node instanceof SimpleTypeSanitizer or
node instanceof RegexpCheckBarrier
}

predicate isSink(DataFlow::Node sink) { sink instanceof TrustBoundaryViolationSink }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,19 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
}
} catch (Exception e) {
}

// GOOD: A direct String.matches(...) regex check constrains the input before it is written to the session.
String input4 = request.getParameter("input4");
if (input4.matches("[a-zA-Z0-9]+")) {
request.getSession().setAttribute("input4", input4);
}
}

@javax.validation.constraints.Pattern(regexp = "^[a-zA-Z0-9]+$")
String validatedField;

public void doPost(HttpServletRequest request, HttpServletResponse response) {
// GOOD: The field is constrained by a @Pattern annotation.
request.getSession().setAttribute("validated", validatedField);
}
}
2 changes: 1 addition & 1 deletion java/ql/test/query-tests/security/CWE-501/options
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/esapi-2.0.1:${testdir}/../../../stubs/javax-servlet-2.5
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/esapi-2.0.1:${testdir}/../../../stubs/javax-servlet-2.5:${testdir}/../../../stubs/javax-validation-constraints
Loading