Skip to content

Commit af6bd0b

Browse files
committed
Consider subtypes of ReaderSource
1 parent 87dfc92 commit af6bd0b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

java/ql/src/semmle/code/java/security/GroovyInjection.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ private predicate groovySourceUnitTaintStep(DataFlow::Node fromNode, DataFlow::N
116116
index = 0 and arg.getType() instanceof TypeUrl
117117
or
118118
index = 1 and
119-
(arg.getType() instanceof TypeString or arg.getType() instanceof TypeReaderSource)
119+
(
120+
arg.getType() instanceof TypeString or
121+
arg.getType() instanceof TypeReaderSource
122+
)
120123
)
121124
|
122125
fromNode.asExpr() = arg and
@@ -137,9 +140,7 @@ private predicate groovySourceUnitTaintStep(DataFlow::Node fromNode, DataFlow::N
137140
* a `ReaderSource` instance by calling `new *ReaderSource(tainted, ...)`
138141
*/
139142
private predicate groovyReaderSourceTaintStep(DataFlow::Node fromNode, DataFlow::Node toNode) {
140-
exists(ClassInstanceExpr cie |
141-
cie.getConstructedType().getASupertype*() instanceof TypeReaderSource
142-
|
143+
exists(ClassInstanceExpr cie | cie.getConstructedType() instanceof TypeReaderSource |
143144
fromNode.asExpr() = cie.getArgument(0) and toNode.asExpr() = cie
144145
)
145146
}
@@ -163,5 +164,7 @@ private class TypeGroovySourceUnit extends RefType {
163164

164165
/** The class `org.codehaus.groovy.control.io.ReaderSource`. */
165166
private class TypeReaderSource extends RefType {
166-
TypeReaderSource() { this.hasQualifiedName("org.codehaus.groovy.control.io", "ReaderSource") }
167+
TypeReaderSource() {
168+
this.getASupertype*().hasQualifiedName("org.codehaus.groovy.control.io", "ReaderSource")
169+
}
167170
}

java/ql/test/query-tests/security/CWE-094/GroovyCompilationUnitTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.codehaus.groovy.control.SourceUnit;
1010
import org.codehaus.groovy.control.io.ReaderSource;
1111
import org.codehaus.groovy.control.io.StringReaderSource;
12+
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
13+
import org.codehaus.groovy.tools.javac.JavaStubCompilationUnit;
1214

1315
public class GroovyCompilationUnitTest extends HttpServlet {
1416
public void doGet(HttpServletRequest request, HttpServletResponse response)
@@ -51,7 +53,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
5153
}
5254
{
5355
CompilationUnit cu = new CompilationUnit();
54-
ReaderSource rs = new StringReaderSource(request.getParameter("source"), null);
56+
StringReaderSource rs = new StringReaderSource(request.getParameter("source"), null);
5557
SourceUnit su = new SourceUnit("test", rs, null, null, null);
5658
cu.addSource(su);
5759
cu.compile(); // $hasGroovyInjection

0 commit comments

Comments
 (0)