@@ -18,7 +18,9 @@ class MvelInjectionConfig extends TaintTracking::Configuration {
18
18
expressionCompilationStep ( node1 , node2 ) or
19
19
createExpressionCompilerStep ( node1 , node2 ) or
20
20
expressionCompilerCompileStep ( node1 , node2 ) or
21
- createCompiledAccExpressionStep ( node1 , node2 )
21
+ createCompiledAccExpressionStep ( node1 , node2 ) or
22
+ scriptCompileStep ( node1 , node2 ) or
23
+ createMvelCompiledScriptStep ( node1 , node2 )
22
24
}
23
25
}
24
26
@@ -30,15 +32,22 @@ class MvelEvaluationSink extends DataFlow::ExprNode {
30
32
MvelEvaluationSink ( ) {
31
33
exists ( StaticMethodAccess ma , Method m | m = ma .getMethod ( ) |
32
34
m instanceof MvelEvalMethod and
33
- ma .getAnArgument ( ) = asExpr ( )
35
+ ma .getArgument ( 0 ) = asExpr ( )
36
+ )
37
+ or
38
+ exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
39
+ m instanceof MvelScriptEngineEvaluationMethod and
40
+ ma .getArgument ( 0 ) = asExpr ( )
34
41
)
35
42
or
36
43
exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
37
44
(
38
45
m instanceof ExecutableStatementEvaluationMethod or
39
46
m instanceof CompiledExpressionEvaluationMethod or
40
47
m instanceof CompiledAccExpressionEvaluationMethod or
41
- m instanceof AccessorEvaluationMethod
48
+ m instanceof AccessorEvaluationMethod or
49
+ m instanceof CompiledScriptEvaluationMethod or
50
+ m instanceof MvelCompiledScriptEvaluationMethod
42
51
) and
43
52
( ma = asExpr ( ) or ma .getQualifier ( ) = asExpr ( ) )
44
53
)
@@ -99,6 +108,30 @@ predicate expressionCompilerCompileStep(DataFlow::Node node1, DataFlow::Node nod
99
108
)
100
109
}
101
110
111
+ /**
112
+ * Holds if `node1` to `node2` is a dataflow step that compiles a script via `MvelScriptEngine`,
113
+ * i.e. `engine.compile(tainted)` or `engine.compiledScript(tainted)`.
114
+ */
115
+ predicate scriptCompileStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
116
+ exists ( MethodAccess ma , Method m | ma .getMethod ( ) = m |
117
+ m instanceof MvelScriptEngineCompilationnMethod and
118
+ ( ma = node2 .asExpr ( ) or ma .getQualifier ( ) = node2 .asExpr ( ) ) and
119
+ ma .getArgument ( 0 ) = node1 .asExpr ( )
120
+ )
121
+ }
122
+
123
+ /**
124
+ * Holds if `node1` to `node2` is a dataflow step creates `MvelCompiledScript`,
125
+ * i.e. `new MvelCompiledScript(engine, tainted)`.
126
+ */
127
+ predicate createMvelCompiledScriptStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
128
+ exists ( ConstructorCall cc |
129
+ cc .getConstructedType ( ) instanceof MvelCompiledScript and
130
+ ( cc = node2 .asExpr ( ) or cc .getQualifier ( ) = node2 .asExpr ( ) ) and
131
+ cc .getArgument ( 1 ) = node1 .asExpr ( )
132
+ )
133
+ }
134
+
102
135
/**
103
136
* Methods in the MVEL class that evaluate a MVEL expression.
104
137
*/
@@ -131,7 +164,7 @@ class MvelCompileExpressionMethod extends Method {
131
164
}
132
165
133
166
/**
134
- * Methods in `ExecutableStatement` that trigger evaluating a MVEL expression.
167
+ * Methods in `ExecutableStatement` that evaluate a MVEL expression.
135
168
*/
136
169
class ExecutableStatementEvaluationMethod extends Method {
137
170
ExecutableStatementEvaluationMethod ( ) {
@@ -141,7 +174,7 @@ class ExecutableStatementEvaluationMethod extends Method {
141
174
}
142
175
143
176
/**
144
- * Methods in `CompiledExpression` that trigger evaluating a MVEL expression.
177
+ * Methods in `CompiledExpression` that evaluate a MVEL expression.
145
178
*/
146
179
class CompiledExpressionEvaluationMethod extends Method {
147
180
CompiledExpressionEvaluationMethod ( ) {
@@ -151,7 +184,7 @@ class CompiledExpressionEvaluationMethod extends Method {
151
184
}
152
185
153
186
/**
154
- * Methods in `CompiledAccExpression` that trigger evaluating a MVEL expression.
187
+ * Methods in `CompiledAccExpression` that evaluate a MVEL expression.
155
188
*/
156
189
class CompiledAccExpressionEvaluationMethod extends Method {
157
190
CompiledAccExpressionEvaluationMethod ( ) {
@@ -161,7 +194,7 @@ class CompiledAccExpressionEvaluationMethod extends Method {
161
194
}
162
195
163
196
/**
164
- * Methods in `Accessor` that trigger evaluating a MVEL expression.
197
+ * Methods in `Accessor` that evaluate a MVEL expression.
165
198
*/
166
199
class AccessorEvaluationMethod extends Method {
167
200
AccessorEvaluationMethod ( ) {
@@ -170,6 +203,46 @@ class AccessorEvaluationMethod extends Method {
170
203
}
171
204
}
172
205
206
+ /**
207
+ * Methods in `MvelScriptEngine` that evaluate a MVEL expression.
208
+ */
209
+ class MvelScriptEngineEvaluationMethod extends Method {
210
+ MvelScriptEngineEvaluationMethod ( ) {
211
+ getDeclaringType ( ) instanceof MvelScriptEngine and
212
+ ( hasName ( "eval" ) or hasName ( "evaluate" ) )
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Methods in `MvelScriptEngine` that compile a MVEL expression.
218
+ */
219
+ class MvelScriptEngineCompilationnMethod extends Method {
220
+ MvelScriptEngineCompilationnMethod ( ) {
221
+ getDeclaringType ( ) instanceof MvelScriptEngine and
222
+ ( hasName ( "compile" ) or hasName ( "compiledScript" ) )
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Methods in `CompiledScript` that evaluate a MVEL expression.
228
+ */
229
+ class CompiledScriptEvaluationMethod extends Method {
230
+ CompiledScriptEvaluationMethod ( ) {
231
+ getDeclaringType ( ) instanceof CompiledScript and
232
+ hasName ( "eval" )
233
+ }
234
+ }
235
+
236
+ /**
237
+ * Methods in `MvelCompiledScript` that evaluate a MVEL expression.
238
+ */
239
+ class MvelCompiledScriptEvaluationMethod extends Method {
240
+ MvelCompiledScriptEvaluationMethod ( ) {
241
+ getDeclaringType ( ) instanceof MvelCompiledScript and
242
+ hasName ( "eval" )
243
+ }
244
+ }
245
+
173
246
class MVEL extends RefType {
174
247
MVEL ( ) { hasQualifiedName ( "org.mvel2" , "MVEL" ) }
175
248
}
@@ -193,3 +266,15 @@ class CompiledAccExpression extends RefType {
193
266
class Accessor extends RefType {
194
267
Accessor ( ) { hasQualifiedName ( "org.mvel2.compiler" , "Accessor" ) }
195
268
}
269
+
270
+ class CompiledScript extends RefType {
271
+ CompiledScript ( ) { hasQualifiedName ( "javax.script" , "CompiledScript" ) }
272
+ }
273
+
274
+ class MvelScriptEngine extends RefType {
275
+ MvelScriptEngine ( ) { hasQualifiedName ( "org.mvel2.jsr223" , "MvelScriptEngine" ) }
276
+ }
277
+
278
+ class MvelCompiledScript extends RefType {
279
+ MvelCompiledScript ( ) { hasQualifiedName ( "org.mvel2.jsr223" , "MvelCompiledScript" ) }
280
+ }
0 commit comments