|
2 | 2 |
|
3 | 3 | import java |
4 | 4 | import semmle.code.java.dataflow.DataFlow |
5 | | -import semmle.code.java.dataflow.ExternalFlow |
6 | 5 | import semmle.code.java.dataflow.FlowSources |
7 | 6 |
|
8 | 7 | /** A data flow sink for unvalidated user input that is used to construct SpEL expressions. */ |
9 | 8 | abstract class SpelExpressionEvaluationSink extends DataFlow::ExprNode { } |
10 | 9 |
|
11 | | -private class SpelExpressionEvaluationModel extends SinkModelCsv { |
12 | | - override predicate row(string row) { |
13 | | - row = |
14 | | - [ |
15 | | - "org.springframework.expression;Expression;true;getValue;;;Argument[-1];spel", |
16 | | - "org.springframework.expression;Expression;true;getValueTypeDescriptor;;;Argument[-1];spel", |
17 | | - "org.springframework.expression;Expression;true;getValueType;;;Argument[-1];spel", |
18 | | - "org.springframework.expression;Expression;true;setValue;;;Argument[-1];spel" |
19 | | - ] |
20 | | - } |
21 | | -} |
22 | | - |
23 | 10 | /** Default sink for SpEL injection vulnerabilities. */ |
24 | 11 | private class DefaultSpelExpressionEvaluationSink extends SpelExpressionEvaluationSink { |
25 | 12 | DefaultSpelExpressionEvaluationSink() { |
@@ -53,6 +40,22 @@ private class DefaultSpelExpressionInjectionAdditionalTaintStep extends SpelExpr |
53 | 40 | } |
54 | 41 | } |
55 | 42 |
|
| 43 | +/** |
| 44 | + * A taint-tracking configuration for unsafe user input |
| 45 | + * that is used to construct and evaluate a SpEL expression. |
| 46 | + */ |
| 47 | +class SpelInjectionConfig extends TaintTracking::Configuration { |
| 48 | + SpelInjectionConfig() { this = "SpelInjectionConfig" } |
| 49 | + |
| 50 | + override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } |
| 51 | + |
| 52 | + override predicate isSink(DataFlow::Node sink) { sink instanceof SpelExpressionEvaluationSink } |
| 53 | + |
| 54 | + override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 55 | + any(SpelExpressionInjectionAdditionalTaintStep c).step(node1, node2) |
| 56 | + } |
| 57 | +} |
| 58 | + |
56 | 59 | /** |
57 | 60 | * A configuration for safe evaluation context that may be used in expression evaluation. |
58 | 61 | */ |
|
0 commit comments