Skip to content

Commit 7ff4d36

Browse files
committed
Fix tests
1 parent 6f926e1 commit 7ff4d36

File tree

4 files changed

+253
-81
lines changed

4 files changed

+253
-81
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class GroovyClassLoaderTest extends HttpServlet {
1212

1313
protected void doGet(HttpServletRequest request, HttpServletResponse response)
1414
throws ServletException, IOException {
15+
// "groovy.lang;GroovyClassLoader;false;parseClass;;;Argument[0];groovy",
1516
try {
1617
String script = request.getParameter("script");
1718
final GroovyClassLoader classLoader = new GroovyClassLoader();
@@ -21,10 +22,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
2122
} catch (Exception e) {
2223
// Ignore
2324
}
24-
}
25-
26-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
27-
throws ServletException, IOException {
2825
try {
2926
String script = request.getParameter("script");
3027
final GroovyClassLoader classLoader = new GroovyClassLoader();
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import java.io.ByteArrayInputStream;
2+
import java.io.IOException;
3+
import java.net.URL;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
import org.codehaus.groovy.control.CompilationUnit;
9+
import org.codehaus.groovy.control.SourceUnit;
10+
import org.codehaus.groovy.control.io.ReaderSource;
11+
import org.codehaus.groovy.control.io.StringReaderSource;
12+
13+
public class GroovyCompilationUnitTest extends HttpServlet {
14+
public void doGet(HttpServletRequest request, HttpServletResponse response)
15+
throws ServletException, IOException {
16+
// "org.codehaus.groovy.control;CompilationUnit;false;compile;;;Argument[-1];groovy"
17+
{
18+
CompilationUnit cu = new CompilationUnit();
19+
cu.addSource("test", request.getParameter("source"));
20+
cu.compile(); // $hasGroovyInjection
21+
}
22+
{
23+
CompilationUnit cu = new CompilationUnit();
24+
cu.addSource(request.getParameter("source"), "safe");
25+
cu.compile(); // Safe
26+
}
27+
{
28+
CompilationUnit cu = new CompilationUnit();
29+
cu.addSource("test",
30+
new ByteArrayInputStream(request.getParameter("source").getBytes()));
31+
cu.compile(); // $hasGroovyInjection
32+
}
33+
{
34+
CompilationUnit cu = new CompilationUnit();
35+
cu.addSource(new URL(request.getParameter("source")));
36+
cu.compile(); // $hasGroovyInjection
37+
}
38+
{
39+
CompilationUnit cu = new CompilationUnit();
40+
SourceUnit su =
41+
new SourceUnit("test", request.getParameter("source"), null, null, null);
42+
cu.addSource(su);
43+
cu.compile(); // $hasGroovyInjection
44+
}
45+
{
46+
CompilationUnit cu = new CompilationUnit();
47+
SourceUnit su =
48+
new SourceUnit(request.getParameter("source"), "safe", null, null, null);
49+
cu.addSource(su);
50+
cu.compile(); // Safe
51+
}
52+
{
53+
CompilationUnit cu = new CompilationUnit();
54+
ReaderSource rs = new StringReaderSource(request.getParameter("source"), null);
55+
SourceUnit su = new SourceUnit("test", rs, null, null, null);
56+
cu.addSource(su);
57+
cu.compile(); // $hasGroovyInjection
58+
}
59+
{
60+
CompilationUnit cu = new CompilationUnit();
61+
SourceUnit su =
62+
new SourceUnit(new URL(request.getParameter("source")), null, null, null);
63+
cu.addSource(su);
64+
cu.compile(); // $hasGroovyInjection
65+
}
66+
{
67+
CompilationUnit cu = new CompilationUnit();
68+
SourceUnit su = SourceUnit.create("test", request.getParameter("source"));
69+
cu.addSource(su);
70+
cu.compile(); // $hasGroovyInjection
71+
}
72+
{
73+
CompilationUnit cu = new CompilationUnit();
74+
SourceUnit su = SourceUnit.create("test", request.getParameter("source"), 0);
75+
cu.addSource(su);
76+
cu.compile(); // $hasGroovyInjection
77+
}
78+
{
79+
CompilationUnit cu = new CompilationUnit();
80+
SourceUnit su = SourceUnit.create(request.getParameter("source"), "safe", 0);
81+
cu.addSource(su);
82+
cu.compile(); // Safe
83+
}
84+
}
85+
}

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

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,32 @@ public class GroovyEvalTest extends HttpServlet {
99

1010
protected void doGet(HttpServletRequest request, HttpServletResponse response)
1111
throws ServletException, IOException {
12-
String script = request.getParameter("script");
13-
Eval.me(script); // $hasGroovyInjection
14-
}
15-
16-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
17-
throws ServletException, IOException {
18-
String script = request.getParameter("script");
19-
Eval.me("test", "result", script); // $hasGroovyInjection
20-
}
21-
22-
protected void doPut(HttpServletRequest request, HttpServletResponse response)
23-
throws ServletException, IOException {
24-
String script = request.getParameter("script");
25-
Eval.x("result2", script); // $hasGroovyInjection
26-
27-
}
28-
29-
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
30-
throws ServletException, IOException {
31-
String script = request.getParameter("script");
32-
Eval.xy("result3", "result4", script); // $hasGroovyInjection
33-
}
34-
35-
protected void doPatch(HttpServletRequest request, HttpServletResponse response)
36-
throws ServletException, IOException {
37-
String script = request.getParameter("script");
38-
Eval.xyz("result3", "result4", "aaa", script); // $hasGroovyInjection
12+
// "groovy.util;Eval;false;me;(String);;Argument[0];groovy",
13+
{
14+
String script = request.getParameter("script");
15+
Eval.me(script); // $hasGroovyInjection
16+
}
17+
// "groovy.util;Eval;false;me;(String,Object,String);;Argument[2];groovy",
18+
{
19+
String script = request.getParameter("script");
20+
Eval.me("test", "result", script); // $hasGroovyInjection
21+
}
22+
// "groovy.util;Eval;false;x;(Object,String);;Argument[1];groovy",
23+
{
24+
String script = request.getParameter("script");
25+
Eval.x("result2", script); // $hasGroovyInjection
26+
27+
}
28+
// "groovy.util;Eval;false;xy;(Object,Object,String);;Argument[2];groovy",
29+
{
30+
String script = request.getParameter("script");
31+
Eval.xy("result3", "result4", script); // $hasGroovyInjection
32+
}
33+
// "groovy.util;Eval;false;xyz;(Object,Object,Object,String);;Argument[3];groovy",
34+
{
35+
String script = request.getParameter("script");
36+
Eval.xyz("result3", "result4", "aaa", script); // $hasGroovyInjection
37+
}
3938
}
4039
}
4140

Lines changed: 141 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,154 @@
1-
import groovy.lang.GroovyCodeSource;
2-
import groovy.lang.GroovyShell;
3-
1+
import java.io.IOException;
2+
import java.io.Reader;
3+
import java.io.StringReader;
4+
import java.net.URI;
5+
import java.net.URISyntaxException;
6+
import java.util.ArrayList;
47
import javax.servlet.ServletException;
58
import javax.servlet.http.HttpServlet;
69
import javax.servlet.http.HttpServletRequest;
710
import javax.servlet.http.HttpServletResponse;
8-
import java.io.IOException;
11+
import groovy.lang.GroovyCodeSource;
12+
import groovy.lang.GroovyShell;
913

1014
public class GroovyShellTest extends HttpServlet {
1115

1216
protected void doGet(HttpServletRequest request, HttpServletResponse response)
1317
throws ServletException, IOException {
14-
GroovyShell shell = new GroovyShell();
15-
String script = request.getParameter("script");
16-
shell.evaluate(script); // $hasGroovyInjection
17-
}
18-
19-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
20-
throws ServletException, IOException {
21-
GroovyShell shell = new GroovyShell();
22-
String script = request.getParameter("script");
23-
shell.evaluate(script, "test"); // $hasGroovyInjection
24-
}
25-
26-
protected void doPut(HttpServletRequest request, HttpServletResponse response)
27-
throws ServletException, IOException {
28-
GroovyShell shell = new GroovyShell();
29-
String script = request.getParameter("script");
30-
shell.evaluate(script, "test", "test2"); // $hasGroovyInjection
31-
}
32-
33-
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
34-
throws ServletException, IOException {
35-
GroovyShell shell = new GroovyShell();
36-
String script = request.getParameter("script");
37-
shell.run(script, "_", new String[] {}); // $hasGroovyInjection
38-
}
39-
40-
protected void doHead(HttpServletRequest request, HttpServletResponse response)
41-
throws ServletException, IOException {
42-
GroovyShell shell = new GroovyShell();
43-
String script = request.getParameter("script");
44-
GroovyCodeSource gcs = new GroovyCodeSource(script, "test", "Test");
45-
shell.run(gcs, new String[] {}); // $hasGroovyInjection
46-
}
47-
48-
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
49-
throws ServletException, IOException {
50-
GroovyShell shell = new GroovyShell();
51-
String script = request.getParameter("script");
52-
GroovyCodeSource gcs = new GroovyCodeSource(script, "test", "Test");
53-
shell.evaluate(gcs); // $hasGroovyInjection
54-
}
5518

56-
protected void doPatch(HttpServletRequest request, HttpServletResponse response)
57-
throws ServletException, IOException {
58-
GroovyShell shell = new GroovyShell();
59-
String script = request.getParameter("script");
60-
shell.parse(script); // $hasGroovyInjection
19+
// "groovy.lang;GroovyShell;false;evaluate;(GroovyCodeSource);;Argument[0];groovy",
20+
{
21+
GroovyShell shell = new GroovyShell();
22+
String script = request.getParameter("script");
23+
GroovyCodeSource gcs = new GroovyCodeSource(script, "test", "Test");
24+
shell.evaluate(gcs); // $hasGroovyInjection
25+
}
26+
// "groovy.lang;GroovyShell;false;evaluate;(Reader);;Argument[0];groovy",
27+
{
28+
GroovyShell shell = new GroovyShell();
29+
String script = request.getParameter("script");
30+
Reader reader = new StringReader(script);
31+
shell.evaluate(reader); // $hasGroovyInjection
32+
}
33+
// "groovy.lang;GroovyShell;false;evaluate;(Reader,String);;Argument[0];groovy",
34+
{
35+
GroovyShell shell = new GroovyShell();
36+
String script = request.getParameter("script");
37+
Reader reader = new StringReader(script);
38+
shell.evaluate(reader, "_"); // $hasGroovyInjection
39+
}
40+
// "groovy.lang;GroovyShell;false;evaluate;(String);;Argument[0];groovy",
41+
{
42+
GroovyShell shell = new GroovyShell();
43+
String script = request.getParameter("script");
44+
shell.evaluate(script); // $hasGroovyInjection
45+
}
46+
// "groovy.lang;GroovyShell;false;evaluate;(String,String);;Argument[0];groovy",
47+
{
48+
GroovyShell shell = new GroovyShell();
49+
String script = request.getParameter("script");
50+
shell.evaluate(script, "test"); // $hasGroovyInjection
51+
}
52+
// "groovy.lang;GroovyShell;false;evaluate;(String,String,String);;Argument[0];groovy",
53+
{
54+
GroovyShell shell = new GroovyShell();
55+
String script = request.getParameter("script");
56+
shell.evaluate(script, "test", "test2"); // $hasGroovyInjection
57+
}
58+
// "groovy.lang;GroovyShell;false;evaluate;(URI);;Argument[0];groovy",
59+
try {
60+
GroovyShell shell = new GroovyShell();
61+
String script = request.getParameter("script");
62+
shell.parse(new URI(script)); // $hasGroovyInjection
63+
} catch (URISyntaxException e) {
64+
}
65+
// "groovy.lang;GroovyShell;false;parse;(Reader);;Argument[0];groovy",
66+
{
67+
GroovyShell shell = new GroovyShell();
68+
String script = request.getParameter("script");
69+
Reader reader = new StringReader(script);
70+
shell.parse(reader); // $hasGroovyInjection
71+
}
72+
// "groovy.lang;GroovyShell;false;parse;(Reader,String);;Argument[0];groovy",
73+
{
74+
GroovyShell shell = new GroovyShell();
75+
String script = request.getParameter("script");
76+
Reader reader = new StringReader(script);
77+
shell.parse(reader, "_"); // $hasGroovyInjection
78+
}
79+
// "groovy.lang;GroovyShell;false;parse;(String);;Argument[0];groovy",
80+
{
81+
GroovyShell shell = new GroovyShell();
82+
String script = request.getParameter("script");
83+
shell.parse(script); // $hasGroovyInjection
84+
}
85+
// "groovy.lang;GroovyShell;false;parse;(String,String);;Argument[0];groovy",
86+
{
87+
GroovyShell shell = new GroovyShell();
88+
String script = request.getParameter("script");
89+
shell.parse(script, "_"); // $hasGroovyInjection
90+
}
91+
// "groovy.lang;GroovyShell;false;parse;(URI);;Argument[0];groovy",
92+
try {
93+
GroovyShell shell = new GroovyShell();
94+
String script = request.getParameter("script");
95+
shell.parse(new URI(script)); // $hasGroovyInjection
96+
} catch (URISyntaxException e) {
97+
}
98+
// "groovy.lang;GroovyShell;false;run;(GroovyCodeSource,String[]);;Argument[0];groovy",
99+
{
100+
GroovyShell shell = new GroovyShell();
101+
String script = request.getParameter("script");
102+
GroovyCodeSource gcs = new GroovyCodeSource(script, "test", "Test");
103+
shell.run(gcs, new String[] {}); // $hasGroovyInjection
104+
}
105+
// "groovy.lang;GroovyShell;false;run;(GroovyCodeSource,List);;Argument[0];groovy",
106+
{
107+
GroovyShell shell = new GroovyShell();
108+
String script = request.getParameter("script");
109+
GroovyCodeSource gcs = new GroovyCodeSource(script, "test", "Test");
110+
shell.run(gcs, new ArrayList<String>()); // $hasGroovyInjection
111+
}
112+
// "groovy.lang;GroovyShell;false;run;(Reader,String,String[]);;Argument[0];groovy",
113+
{
114+
GroovyShell shell = new GroovyShell();
115+
String script = request.getParameter("script");
116+
Reader reader = new StringReader(script);
117+
shell.run(reader, "test", new String[] {}); // $hasGroovyInjection
118+
}
119+
// "groovy.lang;GroovyShell;false;run;(Reader,String,List);;Argument[0];groovy",
120+
{
121+
GroovyShell shell = new GroovyShell();
122+
String script = request.getParameter("script");
123+
Reader reader = new StringReader(script);
124+
shell.run(reader, "test", new ArrayList<String>()); // $hasGroovyInjection
125+
}
126+
// "groovy.lang;GroovyShell;false;run;(String,String,String[]);;Argument[0];groovy",
127+
{
128+
GroovyShell shell = new GroovyShell();
129+
String script = request.getParameter("script");
130+
shell.run(script, "_", new String[] {}); // $hasGroovyInjection
131+
}
132+
// "groovy.lang;GroovyShell;false;run;(String,String,List);;Argument[0];groovy",
133+
{
134+
GroovyShell shell = new GroovyShell();
135+
String script = request.getParameter("script");
136+
shell.run(script, "_", new ArrayList<String>()); // $hasGroovyInjection
137+
}
138+
// "groovy.lang;GroovyShell;false;run;(URI,String[]);;Argument[0];groovy",
139+
try {
140+
GroovyShell shell = new GroovyShell();
141+
String script = request.getParameter("script");
142+
shell.run(new URI(script), new String[] {}); // $hasGroovyInjection
143+
} catch (URISyntaxException e) {
144+
}
145+
// "groovy.lang;GroovyShell;false;run;(URI,List);;Argument[0];groovy",
146+
try {
147+
GroovyShell shell = new GroovyShell();
148+
String script = request.getParameter("script");
149+
shell.run(new URI(script), new ArrayList<String>()); // $hasGroovyInjection
150+
} catch (URISyntaxException e) {
151+
}
61152
}
62153
}
63154

0 commit comments

Comments
 (0)