@@ -14,6 +14,38 @@ import semmle.code.java.dataflow.TaintTracking
1414import semmle.code.java.dataflow.FlowSources
1515import 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+
1749class BuildConstraintViolationWithTemplateMethod extends Method {
1850 BuildConstraintViolationWithTemplateMethod ( ) {
1951 this
@@ -38,5 +70,8 @@ class BeanValidationConfig extends TaintTracking::Configuration {
3870}
3971
4072from 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