@@ -131,43 +131,40 @@ private predicate isSafeEngine(Expr expr) {
131
131
private class SandboxedJexlFlowConfig extends DataFlow2:: Configuration {
132
132
SandboxedJexlFlowConfig ( ) { this = "JexlInjection::SandboxedJexlFlowConfig" }
133
133
134
- override predicate isSource ( DataFlow:: Node node ) { sourceNode ( node , "sandboxed-jexl" ) }
135
-
136
- override predicate isSink ( DataFlow:: Node node ) { sinkNode ( node , "sandboxed-jexl" ) }
134
+ override predicate isSource ( DataFlow:: Node node ) { node instanceof SandboxedJexlSource }
135
+
136
+ override predicate isSink ( DataFlow:: Node node ) {
137
+ exists ( MethodAccess ma , Method m |
138
+ m instanceof CreateJexlScriptMethod or
139
+ m instanceof CreateJexlExpressionMethod or
140
+ m instanceof CreateJexlTemplateMethod
141
+ |
142
+ ma .getMethod ( ) = m and ma .getQualifier ( ) = node .asExpr ( )
143
+ )
144
+ }
137
145
138
146
override predicate isAdditionalFlowStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
139
147
createJexlEngineStep ( fromNode , toNode )
140
148
}
141
149
}
142
150
143
- private class SandoboxedJexlSourceModel extends SourceModelCsv {
144
- override predicate row ( string row ) {
145
- row =
146
- [
147
- // JEXL2
148
- "org.apache.commons.jexl2;JexlEngine;false;JexlEngine;(Uberspect,JexlArithmetic,Map<String,Object>,Log);;ReturnValue;sandboxed-jexl" ,
149
- // JEXL3
150
- "org.apache.commons.jexl3;JexlBuilder;false;uberspect;(JexlUberspect);;ReturnValue;sandboxed-jexl" ,
151
- "org.apache.commons.jexl3;JexlBuilder;false;sandbox;(JexlSandbox);;ReturnValue;sandboxed-jexl"
152
- ]
153
- }
154
- }
155
-
156
- private class SandoboxedJexlSinkModel extends SinkModelCsv {
157
- override predicate row ( string row ) {
158
- row =
159
- [
160
- // JEXL2
161
- "org.apache.commons.jexl2;JexlEngine;false;createScript;;;Argument[-1];sandboxed-jexl" ,
162
- "org.apache.commons.jexl2;JexlEngine;false;createExpression;;;Argument[-1];sandboxed-jexl" ,
163
- "org.apache.commons.jexl2;UnifiedJEXL;false;parse;;;Argument[-1];sandboxed-jexl" ,
164
- "org.apache.commons.jexl2;UnifiedJEXL;false;createTemplate;;;Argument[-1];sandboxed-jexl" ,
165
- // JEXL3
166
- "org.apache.commons.jexl3;JexlEngine;false;createScript;;;Argument[-1];sandboxed-jexl" ,
167
- "org.apache.commons.jexl3;JexlEngine;false;createExpression;;;Argument[-1];sandboxed-jexl" ,
168
- "org.apache.commons.jexl3;JxltEngine;false;createExpression;;;Argument[-1];sandboxed-jexl" ,
169
- "org.apache.commons.jexl3;JxltEngine;false;createTemplate;;;Argument[-1];sandboxed-jexl"
170
- ]
151
+ /**
152
+ * Defines a data flow source for JEXL engines configured with a sandbox.
153
+ */
154
+ private class SandboxedJexlSource extends DataFlow:: ExprNode {
155
+ SandboxedJexlSource ( ) {
156
+ exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
157
+ m .getDeclaringType ( ) instanceof JexlBuilder and
158
+ m .hasName ( [ "uberspect" , "sandbox" ] ) and
159
+ m .getReturnType ( ) instanceof JexlBuilder and
160
+ this .asExpr ( ) = [ ma , ma .getQualifier ( ) ]
161
+ )
162
+ or
163
+ exists ( ConstructorCall cc |
164
+ cc .getConstructedType ( ) instanceof JexlEngine and
165
+ cc .getArgument ( 0 ) .getType ( ) instanceof JexlUberspect and
166
+ cc = this .asExpr ( )
167
+ )
171
168
}
172
169
}
173
170
@@ -238,6 +235,13 @@ private class UnifiedJexl extends JexlRefType {
238
235
UnifiedJexl ( ) { hasName ( "UnifiedJEXL" ) }
239
236
}
240
237
238
+ private class JexlUberspect extends Interface {
239
+ JexlUberspect ( ) {
240
+ hasQualifiedName ( "org.apache.commons.jexl2.introspection" , "Uberspect" ) or
241
+ hasQualifiedName ( "org.apache.commons.jexl3.introspection" , "JexlUberspect" )
242
+ }
243
+ }
244
+
241
245
private class Reader extends RefType {
242
246
Reader ( ) { hasQualifiedName ( "java.io" , "Reader" ) }
243
247
}
0 commit comments