Skip to content

Commit 3275b0d

Browse files
committed
fix java tests
1 parent b06ad53 commit 3275b0d

File tree

2 files changed

+9
-76
lines changed

2 files changed

+9
-76
lines changed

java/test/query-tests/security/PotentiallyUnguardedProtocolHandler/PotentiallyUnguardedProtocolHandler.expected

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ edges
55
| PotentiallyUnguardedProtocolHandler.java:21:19:21:30 | new URI(...) : URI | PotentiallyUnguardedProtocolHandler.java:23:41:23:43 | uri | provenance | Sink:MaD:43969 |
66
| PotentiallyUnguardedProtocolHandler.java:21:27:21:29 | url : String | PotentiallyUnguardedProtocolHandler.java:21:19:21:30 | new URI(...) : URI | provenance | MaD:44428 |
77
| PotentiallyUnguardedProtocolHandler.java:34:22:34:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:35:27:35:29 | url : String | provenance | Src:MaD:46190 |
8-
| PotentiallyUnguardedProtocolHandler.java:35:19:35:30 | new URI(...) : URI | PotentiallyUnguardedProtocolHandler.java:39:41:39:43 | uri | provenance | Sink:MaD:43969 |
8+
| PotentiallyUnguardedProtocolHandler.java:35:19:35:30 | new URI(...) : URI | PotentiallyUnguardedProtocolHandler.java:38:41:38:43 | uri | provenance | Sink:MaD:43969 |
99
| PotentiallyUnguardedProtocolHandler.java:35:27:35:29 | url : String | PotentiallyUnguardedProtocolHandler.java:35:19:35:30 | new URI(...) : URI | provenance | MaD:44428 |
10-
| PotentiallyUnguardedProtocolHandler.java:58:22:58:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:60:35:60:79 | ... + ... | provenance | Src:MaD:46190 Sink:MaD:44131 |
11-
| PotentiallyUnguardedProtocolHandler.java:77:22:77:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:80:39:80:83 | ... + ... | provenance | Src:MaD:46190 Sink:MaD:44131 |
12-
| PotentiallyUnguardedProtocolHandler.java:97:22:97:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:98:35:98:51 | ... + ... | provenance | Src:MaD:46190 Sink:MaD:44131 |
13-
| PotentiallyUnguardedProtocolHandler.java:107:22:107:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:110:39:110:55 | ... + ... | provenance | Src:MaD:46190 Sink:MaD:44131 |
14-
| PotentiallyUnguardedProtocolHandler.java:120:22:120:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:121:35:121:47 | ... + ... | provenance | Src:MaD:46190 Sink:MaD:44131 |
15-
| PotentiallyUnguardedProtocolHandler.java:130:22:130:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:132:39:132:60 | ... + ... | provenance | Src:MaD:46190 Sink:MaD:44131 |
1610
nodes
1711
| PotentiallyUnguardedProtocolHandler.java:10:22:10:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
1812
| PotentiallyUnguardedProtocolHandler.java:11:37:11:48 | new URI(...) | semmle.label | new URI(...) |
@@ -24,29 +18,9 @@ nodes
2418
| PotentiallyUnguardedProtocolHandler.java:34:22:34:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
2519
| PotentiallyUnguardedProtocolHandler.java:35:19:35:30 | new URI(...) : URI | semmle.label | new URI(...) : URI |
2620
| PotentiallyUnguardedProtocolHandler.java:35:27:35:29 | url : String | semmle.label | url : String |
27-
| PotentiallyUnguardedProtocolHandler.java:39:41:39:43 | uri | semmle.label | uri |
28-
| PotentiallyUnguardedProtocolHandler.java:58:22:58:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
29-
| PotentiallyUnguardedProtocolHandler.java:60:35:60:79 | ... + ... | semmle.label | ... + ... |
30-
| PotentiallyUnguardedProtocolHandler.java:77:22:77:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
31-
| PotentiallyUnguardedProtocolHandler.java:80:39:80:83 | ... + ... | semmle.label | ... + ... |
32-
| PotentiallyUnguardedProtocolHandler.java:97:22:97:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
33-
| PotentiallyUnguardedProtocolHandler.java:98:35:98:51 | ... + ... | semmle.label | ... + ... |
34-
| PotentiallyUnguardedProtocolHandler.java:107:22:107:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
35-
| PotentiallyUnguardedProtocolHandler.java:110:39:110:55 | ... + ... | semmle.label | ... + ... |
36-
| PotentiallyUnguardedProtocolHandler.java:120:22:120:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
37-
| PotentiallyUnguardedProtocolHandler.java:121:35:121:47 | ... + ... | semmle.label | ... + ... |
38-
| PotentiallyUnguardedProtocolHandler.java:130:22:130:48 | getParameter(...) : String | semmle.label | getParameter(...) : String |
39-
| PotentiallyUnguardedProtocolHandler.java:132:39:132:60 | ... + ... | semmle.label | ... + ... |
21+
| PotentiallyUnguardedProtocolHandler.java:38:41:38:43 | uri | semmle.label | uri |
4022
subpaths
4123
#select
4224
| PotentiallyUnguardedProtocolHandler.java:11:9:11:49 | browse(...) | PotentiallyUnguardedProtocolHandler.java:10:22:10:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:11:37:11:48 | new URI(...) | Desktop.browse() is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:10:22:10:48 | getParameter(...) | this source |
4325
| PotentiallyUnguardedProtocolHandler.java:23:13:23:44 | browse(...) | PotentiallyUnguardedProtocolHandler.java:20:22:20:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:23:41:23:43 | uri | Desktop.browse() is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:20:22:20:48 | getParameter(...) | this source |
44-
| PotentiallyUnguardedProtocolHandler.java:39:13:39:44 | browse(...) | PotentiallyUnguardedProtocolHandler.java:34:22:34:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:39:41:39:43 | uri | Desktop.browse() is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:34:22:34:48 | getParameter(...) | this source |
45-
| PotentiallyUnguardedProtocolHandler.java:60:35:60:79 | ... + ... | PotentiallyUnguardedProtocolHandler.java:58:22:58:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:60:35:60:79 | ... + ... | rundll32 url.dll,FileProtocolHandler is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:58:22:58:48 | getParameter(...) | this source |
46-
| PotentiallyUnguardedProtocolHandler.java:80:39:80:83 | ... + ... | PotentiallyUnguardedProtocolHandler.java:77:22:77:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:80:39:80:83 | ... + ... | rundll32 url.dll,FileProtocolHandler is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:77:22:77:48 | getParameter(...) | this source |
47-
| PotentiallyUnguardedProtocolHandler.java:98:35:98:51 | ... + ... | PotentiallyUnguardedProtocolHandler.java:97:22:97:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:98:35:98:51 | ... + ... | open is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:97:22:97:48 | getParameter(...) | this source |
48-
| PotentiallyUnguardedProtocolHandler.java:98:35:98:51 | ... + ... | PotentiallyUnguardedProtocolHandler.java:97:22:97:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:98:35:98:51 | ... + ... | xdg-open is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:97:22:97:48 | getParameter(...) | this source |
49-
| PotentiallyUnguardedProtocolHandler.java:110:39:110:55 | ... + ... | PotentiallyUnguardedProtocolHandler.java:107:22:107:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:110:39:110:55 | ... + ... | open is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:107:22:107:48 | getParameter(...) | this source |
50-
| PotentiallyUnguardedProtocolHandler.java:110:39:110:55 | ... + ... | PotentiallyUnguardedProtocolHandler.java:107:22:107:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:110:39:110:55 | ... + ... | xdg-open is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:107:22:107:48 | getParameter(...) | this source |
51-
| PotentiallyUnguardedProtocolHandler.java:121:35:121:47 | ... + ... | PotentiallyUnguardedProtocolHandler.java:120:22:120:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:121:35:121:47 | ... + ... | open is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:120:22:120:48 | getParameter(...) | this source |
52-
| PotentiallyUnguardedProtocolHandler.java:132:39:132:60 | ... + ... | PotentiallyUnguardedProtocolHandler.java:130:22:130:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:132:39:132:60 | ... + ... | open is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:130:22:130:48 | getParameter(...) | this source |
26+
| PotentiallyUnguardedProtocolHandler.java:38:13:38:44 | browse(...) | PotentiallyUnguardedProtocolHandler.java:34:22:34:48 | getParameter(...) : String | PotentiallyUnguardedProtocolHandler.java:38:41:38:43 | uri | Desktop.browse() is called with untrusted input from $@ without proper URL scheme validation. | PotentiallyUnguardedProtocolHandler.java:34:22:34:48 | getParameter(...) | this source |

java/test/query-tests/security/PotentiallyUnguardedProtocolHandler/PotentiallyUnguardedProtocolHandler.java

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public void safe2(String userInput) throws IOException, URISyntaxException {
3333
public void bad3(HttpServletRequest request) throws IOException, URISyntaxException {
3434
String url = request.getParameter("url");
3535
URI uri = new URI(url);
36-
3736
// Weak check - only checks if scheme exists, not what it is
3837
if (uri.getScheme() != null) {
3938
Desktop.getDesktop().browse(uri);
@@ -43,7 +42,6 @@ public void bad3(HttpServletRequest request) throws IOException, URISyntaxExcept
4342
public void safe3(String userInput) throws IOException, URISyntaxException {
4443
URI uri = new URI(userInput);
4544
String scheme = uri.getScheme();
46-
4745
if (scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) {
4846
Desktop.getDesktop().browse(uri);
4947
}
@@ -53,22 +51,13 @@ public void safe4() throws IOException, URISyntaxException {
5351
Desktop.getDesktop().browse(new URI("https://example.com"));
5452
}
5553

56-
// rundll32 test cases
57-
public void bad4_rundll32(HttpServletRequest request) throws IOException {
58-
String url = request.getParameter("url");
59-
// Single string command with concatenation
60-
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
61-
}
62-
63-
public void bad5_rundll32(String userInput) throws IOException {
64-
// Array-based command
54+
public void bad4_rundll32(String userInput) throws IOException {
6555
String[] cmd = { "rundll32", "url.dll,FileProtocolHandler", userInput };
6656
Runtime.getRuntime().exec(cmd);
6757
}
6858

6959
public void bad6_rundll32(HttpServletRequest request) throws IOException {
7060
String url = request.getParameter("url");
71-
// ProcessBuilder with list
7261
ProcessBuilder pb = new ProcessBuilder("rundll32", "url.dll,FileProtocolHandler", url);
7362
pb.start();
7463
}
@@ -77,7 +66,8 @@ public void safe5_rundll32(HttpServletRequest request) throws IOException, URISy
7766
String url = request.getParameter("url");
7867
URI uri = new URI(url);
7968
if (uri.getScheme().equals("https") || uri.getScheme().equals("http")) {
80-
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
69+
String[] cmd = { "rundll32", "url.dll,FileProtocolHandler", url };
70+
Runtime.getRuntime().exec(cmd);
8171
}
8272
}
8373

@@ -92,13 +82,7 @@ public void safe7_rundll32() throws IOException {
9282
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler https://example.com");
9383
}
9484

95-
// xdg-open test cases (Linux)
96-
public void bad7_xdgopen(HttpServletRequest request) throws IOException {
97-
String url = request.getParameter("url");
98-
Runtime.getRuntime().exec("xdg-open " + url);
99-
}
100-
101-
public void bad8_xdgopen(String userInput) throws IOException {
85+
public void bad7_xdgopen(String userInput) throws IOException {
10286
String[] cmd = { "xdg-open", userInput };
10387
Runtime.getRuntime().exec(cmd);
10488
}
@@ -107,33 +91,8 @@ public void safe8_xdgopen(HttpServletRequest request) throws IOException, URISyn
10791
String url = request.getParameter("url");
10892
URI uri = new URI(url);
10993
if (uri.getScheme().equals("https") || uri.getScheme().equals("http")) {
110-
Runtime.getRuntime().exec("xdg-open " + url);
111-
}
112-
}
113-
114-
public void safe9_xdgopen() throws IOException {
115-
Runtime.getRuntime().exec("xdg-open https://example.com");
116-
}
117-
118-
// open test cases (macOS)
119-
public void bad9_open(HttpServletRequest request) throws IOException {
120-
String url = request.getParameter("url");
121-
Runtime.getRuntime().exec("open " + url);
122-
}
123-
124-
public void bad10_open(String userInput) throws IOException {
125-
ProcessBuilder pb = new ProcessBuilder("open", userInput);
126-
pb.start();
127-
}
128-
129-
public void safe10_open(HttpServletRequest request) throws IOException, URISyntaxException {
130-
String url = request.getParameter("url");
131-
if (url.startsWith("https://") || url.startsWith("http://")) {
132-
Runtime.getRuntime().exec("/usr/bin/open " + url);
94+
String[] cmd = { "xdg-open", url };
95+
Runtime.getRuntime().exec(cmd);
13396
}
13497
}
135-
136-
public void safe11_open() throws IOException {
137-
Runtime.getRuntime().exec("open https://example.com");
138-
}
13998
}

0 commit comments

Comments
 (0)