Skip to content

Commit 2c1374b

Browse files
committed
Use inline implementation for ScriptEngineFactory
1 parent 0ac8453 commit 2c1374b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

java/ql/src/experimental/Security/CWE/CWE-094/ScriptInjection.ql

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ class ScriptEngineMethod extends Method {
2626
this.getDeclaringType().getASupertype*().hasQualifiedName("javax.script", "ScriptEngineFactory") and
2727
this.hasName(["getProgram", "getMethodCallSyntax"])
2828
}
29-
30-
/** Holds if the index is for an injectable parameter. */
31-
bindingset[index]
32-
predicate isInjectableArgIndex(int index) {
33-
if
34-
this.getDeclaringType()
35-
.getASupertype*()
36-
.hasQualifiedName("javax.script", "ScriptEngineFactory")
37-
then any()
38-
else index = 0
39-
}
4029
}
4130

4231
/** The context class `org.mozilla.javascript.Context` of Rhino Java Script Engine. */
@@ -82,10 +71,11 @@ class RhinoDefineClassMethod extends Method {
8271

8372
/** Holds if `ma` is a method access of `ScriptEngineMethod`. */
8473
predicate scriptEngine(MethodAccess ma, Expr sink) {
85-
exists(ScriptEngineMethod m, int index |
74+
exists(ScriptEngineMethod m |
8675
m = ma.getMethod() and
87-
m.isInjectableArgIndex(index) and
88-
sink = ma.getArgument(index)
76+
if m.getDeclaringType().getASupertype*().hasQualifiedName("javax.script", "ScriptEngineFactory")
77+
then sink = ma.getArgument(_) // all arguments allow script injection
78+
else sink = ma.getArgument(0)
8979
)
9080
}
9181

0 commit comments

Comments
 (0)