add some improvements to the bean validation query

This commit is contained in:
Alvaro Muñoz
2020-11-06 13:08:45 +01:00
parent 9f2eb84f2b
commit 9db340c9ca

View File

@@ -14,6 +14,38 @@ import semmle.code.java.dataflow.TaintTracking
import semmle.code.java.dataflow.FlowSources import semmle.code.java.dataflow.FlowSources
import DataFlow::PathGraph import DataFlow::PathGraph
class ELMessageInterpolatorType extends RefType {
ELMessageInterpolatorType() {
this
.getASourceSupertype*()
.hasQualifiedName("org.hibernate.validator.messageinterpolation",
["ResourceBundleMessageInterpolator", "ValueFormatterMessageInterpolator"])
}
}
class SetSafeMessageInterpolator extends MethodAccess {
SetSafeMessageInterpolator() {
exists(Method m |
this.getMethod() = m and
(
m
.getDeclaringType()
.getASourceSupertype*()
.hasQualifiedName("javax.validation", ["Configuration", "ValidatorContext"]) and
m.getName() = "messageInterpolator"
or
m
.getDeclaringType()
.getASourceSupertype*()
.hasQualifiedName("org.springframework.validation.beanvalidation",
["CustomValidatorBean", "LocalValidatorFactoryBean"]) and
m.getName() = "setMessageInterpolator"
)
) and
not this.getAnArgument().getType() instanceof ELMessageInterpolatorType
}
}
class BuildConstraintViolationWithTemplateMethod extends Method { class BuildConstraintViolationWithTemplateMethod extends Method {
BuildConstraintViolationWithTemplateMethod() { BuildConstraintViolationWithTemplateMethod() {
this this
@@ -38,5 +70,8 @@ class BeanValidationConfig extends TaintTracking::Configuration {
} }
from BeanValidationConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink from BeanValidationConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink) where
select sink, source, sink, "Custom constraint error message contains unsanitized user data" not exists(SetSafeMessageInterpolator ma) and
cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink,
"Custom constraint error message contains unsanitized user data"