Skip to content

Commit 5b1858a

Browse files
committed
Do not report the issue only if all message interpolators are secure
1 parent 02cf49a commit 5b1858a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ class ELMessageInterpolatorType extends RefType {
2727
}
2828

2929
/**
30-
* A method call that sets the application's default message interpolator to an interpolator type that is likely to be safe,
31-
* because it does not process Java Expression Language expressions.
30+
* A method call that sets the application's default message interpolator.
3231
*/
33-
class SetSafeMessageInterpolatorCall extends MethodAccess {
34-
SetSafeMessageInterpolatorCall() {
32+
class SetMessageInterpolatorCall extends MethodAccess {
33+
SetMessageInterpolatorCall() {
3534
exists(Method m, RefType t |
3635
this.getMethod() = m and
3736
m.getDeclaringType().getASourceSupertype*() = t and
@@ -44,7 +43,13 @@ class SetSafeMessageInterpolatorCall extends MethodAccess {
4443
["CustomValidatorBean", "LocalValidatorFactoryBean"]) and
4544
m.getName() = "setMessageInterpolator"
4645
)
47-
) and
46+
)
47+
}
48+
49+
/**
50+
* The message interpolator is likely to be safe, because it does not process Java Expression Language expressions.
51+
*/
52+
predicate isSafe() {
4853
not this.getAnArgument().getType() instanceof ELMessageInterpolatorType
4954
}
5055
}
@@ -82,7 +87,7 @@ class BeanValidationConfig extends TaintTracking::Configuration {
8287

8388
from BeanValidationConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
8489
where
85-
not exists(SetSafeMessageInterpolatorCall ma) and
90+
not forall(SetMessageInterpolatorCall c | c.isSafe()) and
8691
cfg.hasFlowPath(source, sink)
8792
select sink.getNode(), source, sink,
8893
"Custom constraint error message contains unsanitized user data"

0 commit comments

Comments
 (0)