Skip to content

Commit f329c3f

Browse files
committed
Java: Convert insecure bean validation sink to CSV format
1 parent 9e2832a commit f329c3f

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java
1313
import semmle.code.java.dataflow.TaintTracking
1414
import semmle.code.java.dataflow.FlowSources
1515
import DataFlow::PathGraph
16+
private import semmle.code.java.dataflow.ExternalFlow
1617

1718
/**
1819
* A message interpolator Type that perform Expression Language (EL) evaluations
@@ -50,19 +51,6 @@ class SetMessageInterpolatorCall extends MethodAccess {
5051
predicate isSafe() { not this.getAnArgument().getType() instanceof ELMessageInterpolatorType }
5152
}
5253

53-
/**
54-
* A method named `buildConstraintViolationWithTemplate` declared on a subtype
55-
* of `javax.validation.ConstraintValidatorContext`.
56-
*/
57-
class BuildConstraintViolationWithTemplateMethod extends Method {
58-
BuildConstraintViolationWithTemplateMethod() {
59-
this.getDeclaringType()
60-
.getASupertype*()
61-
.hasQualifiedName("javax.validation", "ConstraintValidatorContext") and
62-
this.hasName("buildConstraintViolationWithTemplate")
63-
}
64-
}
65-
6654
/**
6755
* Taint tracking BeanValidationConfiguration describing the flow of data from user input
6856
* to the argument of a method that builds constraint error messages.
@@ -72,12 +60,7 @@ class BeanValidationConfig extends TaintTracking::Configuration {
7260

7361
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
7462

75-
override predicate isSink(DataFlow::Node sink) {
76-
exists(MethodAccess ma |
77-
ma.getMethod() instanceof BuildConstraintViolationWithTemplateMethod and
78-
sink.asExpr() = ma.getArgument(0)
79-
)
80-
}
63+
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, "bean-validation") }
8164
}
8265

8366
from BeanValidationConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink

java/ql/src/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ private predicate sinkModelCsv(string row) {
203203
"java.nio.file;Files;false;createLink;;;Argument[0];create-file",
204204
"java.nio.file;Files;false;createSymbolicLink;;;Argument[0];create-file",
205205
"java.nio.file;Files;false;createTempDirectory;;;Argument[0];create-file",
206-
"java.nio.file;Files;false;createTempFile;;;Argument[0];create-file"
206+
"java.nio.file;Files;false;createTempFile;;;Argument[0];create-file",
207+
// Bean validation
208+
"javax.validation;ConstraintValidatorContext;true;buildConstraintViolationWithTemplate;;;Argument[0];bean-validation"
207209
]
208210
}
209211

0 commit comments

Comments
 (0)