Skip to content

Commit 71e5cb4

Browse files
Simplified method and class definitions for JEXL
1 parent 03348b1 commit 71e5cb4

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

java/ql/src/experimental/Security/CWE/CWE-094/JexlInjectionLib.qll

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,36 @@ private class CallableCallMethod extends Method {
196196
CallableCallMethod() { getDeclaringType() instanceof CallableInterface and hasName("call") }
197197
}
198198

199+
/**
200+
* Defines methods that create a Jexl script.
201+
*/
199202
private class CreateJexlScriptMethod extends Method {
200203
CreateJexlScriptMethod() { getDeclaringType() instanceof JexlEngine and hasName("createScript") }
201204
}
202205

206+
/**
207+
* Defines methods that creates a `Callable` for a Jexl expression or script.
208+
*/
203209
private class CreateJexlCallableMethod extends Method {
204210
CreateJexlCallableMethod() {
205211
(getDeclaringType() instanceof JexlExpression or getDeclaringType() instanceof JexlScript) and
206212
hasName("callable")
207213
}
208214
}
209215

216+
/**
217+
* Defines methods that create a Jexl template.
218+
*/
210219
private class CreateJexlTemplateMethod extends Method {
211220
CreateJexlTemplateMethod() {
212221
(getDeclaringType() instanceof JxltEngine or getDeclaringType() instanceof UnifiedJexl) and
213222
hasName("createTemplate")
214223
}
215224
}
216225

226+
/**
227+
* Defines methods that create a Jexl expression.
228+
*/
217229
private class CreateJexlExpressionMethod extends Method {
218230
CreateJexlExpressionMethod() {
219231
(getDeclaringType() instanceof JexlEngine or getDeclaringType() instanceof JxltEngine) and
@@ -223,33 +235,28 @@ private class CreateJexlExpressionMethod extends Method {
223235
}
224236
}
225237

226-
private class JexlExpression extends RefType {
227-
JexlExpression() {
228-
hasQualifiedName("org.apache.commons.jexl3", "JexlExpression") or
229-
hasQualifiedName("org.apache.commons.jexl2", "Expression")
230-
}
238+
private class JexlRefType extends RefType {
239+
JexlRefType() { getPackage().hasName(["org.apache.commons.jexl2", "org.apache.commons.jexl3"]) }
231240
}
232241

233-
private class JexlScript extends RefType {
234-
JexlScript() {
235-
hasQualifiedName("org.apache.commons.jexl3", "JexlScript") or
236-
hasQualifiedName("org.apache.commons.jexl2", "Script")
237-
}
242+
private class JexlExpression extends JexlRefType {
243+
JexlExpression() { hasName(["Expression", "JexlExpression"]) }
238244
}
239245

240-
private class JexlEngine extends RefType {
241-
JexlEngine() {
242-
hasQualifiedName("org.apache.commons.jexl3", "JexlEngine") or
243-
hasQualifiedName("org.apache.commons.jexl2", "JexlEngine")
244-
}
246+
private class JexlScript extends JexlRefType {
247+
JexlScript() { hasName(["Script", "JexlScript"]) }
248+
}
249+
250+
private class JexlEngine extends JexlRefType {
251+
JexlEngine() { hasName("JexlEngine") }
245252
}
246253

247-
private class JxltEngine extends RefType {
248-
JxltEngine() { hasQualifiedName("org.apache.commons.jexl3", "JxltEngine") }
254+
private class JxltEngine extends JexlRefType {
255+
JxltEngine() { hasName("JxltEngine") }
249256
}
250257

251-
private class UnifiedJexl extends RefType {
252-
UnifiedJexl() { hasQualifiedName("org.apache.commons.jexl2", "UnifiedJEXL") }
258+
private class UnifiedJexl extends JexlRefType {
259+
UnifiedJexl() { hasName("UnifiedJEXL") }
253260
}
254261

255262
private class JxltEngineExpression extends NestedType {

0 commit comments

Comments
 (0)