Skip to content

Commit dca7046

Browse files
committed
Make inline expectation comments specify query
1 parent 29b07d5 commit dca7046

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

java/ql/test/query-tests/security/CWE-023/semmle/tests/PartialPathTraversalTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
public class PartialPathTraversalTest {
1212
public void esapiExample(File parent) throws IOException {
13-
if (!dir().getCanonicalPath().startsWith(parent.getCanonicalPath())) { // $ Alert
13+
if (!dir().getCanonicalPath().startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
1414
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
1515
}
1616
}
1717

1818
@SuppressWarnings("ResultOfMethodCallIgnored")
1919
void foo1(File parent) throws IOException {
20-
(dir().getCanonicalPath()).startsWith((parent.getCanonicalPath())); // $ Alert
20+
(dir().getCanonicalPath()).startsWith((parent.getCanonicalPath())); // $ Alert[java/partial-path-traversal-from-remote]
2121
}
2222

2323
void foo2(File parent) throws IOException {
@@ -29,42 +29,42 @@ void foo2(File parent) throws IOException {
2929

3030
void foo3(File parent) throws IOException {
3131
String parentPath = parent.getCanonicalPath();
32-
if (!dir().getCanonicalPath().startsWith(parentPath)) { // $ Alert
32+
if (!dir().getCanonicalPath().startsWith(parentPath)) { // $ Alert[java/partial-path-traversal-from-remote]
3333
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
3434
}
3535
}
3636

3737
void foo4() throws IOException {
38-
if (!dir().getCanonicalPath().startsWith("/usr" + "/dir")) { // $ Alert
38+
if (!dir().getCanonicalPath().startsWith("/usr" + "/dir")) { // $ Alert[java/partial-path-traversal-from-remote]
3939
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
4040
}
4141
}
4242

4343
void foo5(File parent) throws IOException {
4444
String canonicalPath = dir().getCanonicalPath();
45-
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert
45+
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
4646
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
4747
}
4848
}
4949

5050
void foo6(File parent) throws IOException {
5151
String canonicalPath = dir().getCanonicalPath();
52-
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert
52+
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
5353
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
5454
}
5555
String canonicalPath2 = dir().getCanonicalPath();
56-
if (!canonicalPath2.startsWith(parent.getCanonicalPath())) { // $ Alert
56+
if (!canonicalPath2.startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
5757
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
5858
}
5959
}
6060

6161
void foo7(File dir, File parent) throws IOException {
6262
String canonicalPath = dir().getCanonicalPath();
6363
String canonicalPath2 = dir().getCanonicalPath();
64-
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert
64+
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
6565
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
6666
}
67-
if (!canonicalPath2.startsWith(parent.getCanonicalPath())) { // $ Alert
67+
if (!canonicalPath2.startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
6868
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
6969
}
7070
}
@@ -94,18 +94,18 @@ void foo10(File parent) throws IOException {
9494

9595
void foo11(File parent) throws IOException {
9696
String parentCanonical = parent.getCanonicalPath();
97-
if (!dir().getCanonicalPath().startsWith(parentCanonical)) { // $ Alert
97+
if (!dir().getCanonicalPath().startsWith(parentCanonical)) { // $ Alert[java/partial-path-traversal-from-remote]
9898
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
9999
}
100100
}
101101

102102
void foo12(File parent) throws IOException {
103103
String parentCanonical = parent.getCanonicalPath();
104104
String parentCanonical2 = parent.getCanonicalPath();
105-
if (!dir().getCanonicalPath().startsWith(parentCanonical)) { // $ Alert
105+
if (!dir().getCanonicalPath().startsWith(parentCanonical)) { // $ Alert[java/partial-path-traversal-from-remote]
106106
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
107107
}
108-
if (!dir().getCanonicalPath().startsWith(parentCanonical2)) { // $ Alert
108+
if (!dir().getCanonicalPath().startsWith(parentCanonical2)) { // $ Alert[java/partial-path-traversal-from-remote]
109109
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
110110
}
111111
}
@@ -173,7 +173,7 @@ void foo18(File dir, File parent, boolean branch) throws IOException {
173173

174174
void foo19(File parent) throws IOException {
175175
String parentCanonical = parent.getCanonicalPath() + "/potato";
176-
if (!dir().getCanonicalPath().startsWith(parentCanonical)) { // $ Alert
176+
if (!dir().getCanonicalPath().startsWith(parentCanonical)) { // $ Alert[java/partial-path-traversal-from-remote]
177177
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
178178
}
179179
}
@@ -191,7 +191,7 @@ InputStream foo20() {
191191
String filePath = sb.toString();
192192
File encodedFile = new File(filePath);
193193
try {
194-
if (!encodedFile.getCanonicalPath().startsWith(cacheDir.getCanonicalPath())) { // $ Alert
194+
if (!encodedFile.getCanonicalPath().startsWith(cacheDir.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
195195
return null;
196196
}
197197
return Files.newInputStream(encodedFile.toPath());
@@ -209,7 +209,7 @@ void foo21(File parent) throws IOException {
209209

210210
void foo22(File dir2, File parent, boolean conditional) throws IOException {
211211
String canonicalPath = conditional ? dir().getCanonicalPath() : dir2.getCanonicalPath();
212-
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert
212+
if (!canonicalPath.startsWith(parent.getCanonicalPath())) { // $ Alert[java/partial-path-traversal-from-remote]
213213
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
214214
}
215215
}

0 commit comments

Comments
 (0)