@@ -14,6 +14,48 @@ import semmle.code.java.dataflow.TaintTracking
14
14
import semmle.code.java.dataflow.FlowSources
15
15
import DataFlow:: PathGraph
16
16
17
+ /**
18
+ * A message interpolator Type that perform Expression Language (EL) evaluations
19
+ */
20
+ class ELMessageInterpolatorType extends RefType {
21
+ ELMessageInterpolatorType ( ) {
22
+ this
23
+ .getASourceSupertype * ( )
24
+ .hasQualifiedName ( "org.hibernate.validator.messageinterpolation" ,
25
+ [ "ResourceBundleMessageInterpolator" , "ValueFormatterMessageInterpolator" ] )
26
+ }
27
+ }
28
+
29
+ /**
30
+ * A method call that sets the application's default message interpolator.
31
+ */
32
+ class SetMessageInterpolatorCall extends MethodAccess {
33
+ SetMessageInterpolatorCall ( ) {
34
+ exists ( Method m , RefType t |
35
+ this .getMethod ( ) = m and
36
+ m .getDeclaringType ( ) .getASourceSupertype * ( ) = t and
37
+ (
38
+ t .hasQualifiedName ( "javax.validation" , [ "Configuration" , "ValidatorContext" ] ) and
39
+ m .getName ( ) = "messageInterpolator"
40
+ or
41
+ t
42
+ .hasQualifiedName ( "org.springframework.validation.beanvalidation" ,
43
+ [ "CustomValidatorBean" , "LocalValidatorFactoryBean" ] ) and
44
+ m .getName ( ) = "setMessageInterpolator"
45
+ )
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 ( ) { not this .getAnArgument ( ) .getType ( ) instanceof ELMessageInterpolatorType }
53
+ }
54
+
55
+ /**
56
+ * A method named `buildConstraintViolationWithTemplate` declared on a subtype
57
+ * of `javax.validation.ConstraintValidatorContext`.
58
+ */
17
59
class BuildConstraintViolationWithTemplateMethod extends Method {
18
60
BuildConstraintViolationWithTemplateMethod ( ) {
19
61
this
@@ -24,6 +66,10 @@ class BuildConstraintViolationWithTemplateMethod extends Method {
24
66
}
25
67
}
26
68
69
+ /**
70
+ * Taint tracking BeanValidationConfiguration describing the flow of data from user input
71
+ * to the argument of a method that builds constraint error messages.
72
+ */
27
73
class BeanValidationConfig extends TaintTracking:: Configuration {
28
74
BeanValidationConfig ( ) { this = "BeanValidationConfig" }
29
75
@@ -38,5 +84,12 @@ class BeanValidationConfig extends TaintTracking::Configuration {
38
84
}
39
85
40
86
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"
87
+ where
88
+ (
89
+ not exists ( SetMessageInterpolatorCall c )
90
+ or
91
+ exists ( SetMessageInterpolatorCall c | not c .isSafe ( ) )
92
+ ) and
93
+ cfg .hasFlowPath ( source , sink )
94
+ select sink .getNode ( ) , source , sink ,
95
+ "Custom constraint error message contains unsanitized user data"
0 commit comments