Skip to content

Commit 9db340c

Browse files
committed
add some improvements to the bean validation query
1 parent 9f2eb84 commit 9db340c

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

java/ql/src/Security/CWE/CWE-094/InsecureBeanValidation.ql

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ import semmle.code.java.dataflow.TaintTracking
1414
import semmle.code.java.dataflow.FlowSources
1515
import DataFlow::PathGraph
1616

17+
class ELMessageInterpolatorType extends RefType {
18+
ELMessageInterpolatorType() {
19+
this
20+
.getASourceSupertype*()
21+
.hasQualifiedName("org.hibernate.validator.messageinterpolation",
22+
["ResourceBundleMessageInterpolator", "ValueFormatterMessageInterpolator"])
23+
}
24+
}
25+
26+
class SetSafeMessageInterpolator extends MethodAccess {
27+
SetSafeMessageInterpolator() {
28+
exists(Method m |
29+
this.getMethod() = m and
30+
(
31+
m
32+
.getDeclaringType()
33+
.getASourceSupertype*()
34+
.hasQualifiedName("javax.validation", ["Configuration", "ValidatorContext"]) and
35+
m.getName() = "messageInterpolator"
36+
or
37+
m
38+
.getDeclaringType()
39+
.getASourceSupertype*()
40+
.hasQualifiedName("org.springframework.validation.beanvalidation",
41+
["CustomValidatorBean", "LocalValidatorFactoryBean"]) and
42+
m.getName() = "setMessageInterpolator"
43+
)
44+
) and
45+
not this.getAnArgument().getType() instanceof ELMessageInterpolatorType
46+
}
47+
}
48+
1749
class BuildConstraintViolationWithTemplateMethod extends Method {
1850
BuildConstraintViolationWithTemplateMethod() {
1951
this
@@ -38,5 +70,8 @@ class BeanValidationConfig extends TaintTracking::Configuration {
3870
}
3971

4072
from BeanValidationConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
41-
where cfg.hasFlowPath(source, sink)
42-
select sink, source, sink, "Custom constraint error message contains unsanitized user data"
73+
where
74+
not exists(SetSafeMessageInterpolator ma) and
75+
cfg.hasFlowPath(source, sink)
76+
select sink.getNode(), source, sink,
77+
"Custom constraint error message contains unsanitized user data"

0 commit comments

Comments
 (0)