@@ -131,43 +131,40 @@ private predicate isSafeEngine(Expr expr) {
131131private class SandboxedJexlFlowConfig extends DataFlow2:: Configuration {
132132 SandboxedJexlFlowConfig ( ) { this = "JexlInjection::SandboxedJexlFlowConfig" }
133133
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+ }
137145
138146 override predicate isAdditionalFlowStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
139147 createJexlEngineStep ( fromNode , toNode )
140148 }
141149}
142150
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+ )
171168 }
172169}
173170
@@ -238,6 +235,13 @@ private class UnifiedJexl extends JexlRefType {
238235 UnifiedJexl ( ) { hasName ( "UnifiedJEXL" ) }
239236}
240237
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+
241245private class Reader extends RefType {
242246 Reader ( ) { hasQualifiedName ( "java.io" , "Reader" ) }
243247}
0 commit comments