Skip to content

Commit b49c6dc

Browse files
committed
Add @pattern annotation test case and javax-validation-constraints stub
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.
1 parent 258a53e commit b49c6dc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

java/ql/test/query-tests/security/CWE-501/TrustBoundaryViolations.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
3838
request.getSession().setAttribute("input4", input4);
3939
}
4040
}
41+
42+
@javax.validation.constraints.Pattern(regexp = "^[a-zA-Z0-9]+$")
43+
String validatedField;
44+
45+
public void doPost(HttpServletRequest request, HttpServletResponse response) {
46+
// GOOD: The field is constrained by a @Pattern annotation.
47+
request.getSession().setAttribute("validated", validatedField);
48+
}
4149
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/esapi-2.0.1:${testdir}/../../../stubs/javax-servlet-2.5
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/esapi-2.0.1:${testdir}/../../../stubs/javax-servlet-2.5:${testdir}/../../../stubs/javax-validation-constraints

0 commit comments

Comments
 (0)