7
7
8
8
public class PartialPathTraversalTest {
9
9
public void esapiExample (File dir , File parent ) throws IOException {
10
- if (!dir .getCanonicalPath ().startsWith (parent .getCanonicalPath ())) {
10
+ if (!dir .getCanonicalPath ().startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
11
11
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
12
12
}
13
13
}
14
14
15
15
@ SuppressWarnings ("ResultOfMethodCallIgnored" )
16
16
void foo1 (File dir , File parent ) throws IOException {
17
- (dir .getCanonicalPath ()).startsWith ((parent .getCanonicalPath ()));
17
+ (dir .getCanonicalPath ()).startsWith ((parent .getCanonicalPath ())); // $hasTaintFlow
18
18
}
19
19
20
20
void foo2 (File dir , File parent ) throws IOException {
@@ -26,42 +26,42 @@ void foo2(File dir, File parent) throws IOException {
26
26
27
27
void foo3 (File dir , File parent ) throws IOException {
28
28
String parentPath = parent .getCanonicalPath ();
29
- if (!dir .getCanonicalPath ().startsWith (parentPath )) {
29
+ if (!dir .getCanonicalPath ().startsWith (parentPath )) { // $hasTaintFlow
30
30
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
31
31
}
32
32
}
33
33
34
34
void foo4 (File dir ) throws IOException {
35
- if (!dir .getCanonicalPath ().startsWith ("/usr" + "/dir" )) {
35
+ if (!dir .getCanonicalPath ().startsWith ("/usr" + "/dir" )) { // $hasTaintFlow
36
36
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
37
37
}
38
38
}
39
39
40
40
void foo5 (File dir , File parent ) throws IOException {
41
41
String canonicalPath = dir .getCanonicalPath ();
42
- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
42
+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
43
43
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
44
44
}
45
45
}
46
46
47
47
void foo6 (File dir , File parent ) throws IOException {
48
48
String canonicalPath = dir .getCanonicalPath ();
49
- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
49
+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
50
50
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
51
51
}
52
52
String canonicalPath2 = dir .getCanonicalPath ();
53
- if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) {
53
+ if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
54
54
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
55
55
}
56
56
}
57
57
58
58
void foo7 (File dir , File parent ) throws IOException {
59
59
String canonicalPath = dir .getCanonicalPath ();
60
60
String canonicalPath2 = dir .getCanonicalPath ();
61
- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
61
+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
62
62
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
63
63
}
64
- if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) {
64
+ if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
65
65
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
66
66
}
67
67
}
@@ -72,7 +72,7 @@ File getChild() {
72
72
73
73
void foo8 (File parent ) throws IOException {
74
74
String canonicalPath = getChild ().getCanonicalPath ();
75
- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
75
+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
76
76
throw new IOException ("Invalid directory: " + getChild ().getCanonicalPath ());
77
77
}
78
78
}
@@ -91,18 +91,18 @@ void foo10(File dir, File parent) throws IOException {
91
91
92
92
void foo11 (File dir , File parent ) throws IOException {
93
93
String parentCanonical = parent .getCanonicalPath ();
94
- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
94
+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) { // $hasTaintFlow
95
95
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
96
96
}
97
97
}
98
98
99
99
void foo12 (File dir , File parent ) throws IOException {
100
100
String parentCanonical = parent .getCanonicalPath ();
101
101
String parentCanonical2 = parent .getCanonicalPath ();
102
- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
102
+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) { // $hasTaintFlow
103
103
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
104
104
}
105
- if (!dir .getCanonicalPath ().startsWith (parentCanonical2 )) {
105
+ if (!dir .getCanonicalPath ().startsWith (parentCanonical2 )) { // $hasTaintFlow
106
106
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
107
107
}
108
108
}
@@ -116,7 +116,7 @@ void foo13(File dir, File parent) throws IOException {
116
116
117
117
void foo14 (File dir , File parent ) throws IOException {
118
118
String parentCanonical = parent .getCanonicalPath () + separatorChar ;
119
- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
119
+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
120
120
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
121
121
}
122
122
}
@@ -170,7 +170,7 @@ void foo18(File dir, File parent, boolean branch) throws IOException {
170
170
171
171
void foo19 (File dir , File parent ) throws IOException {
172
172
String parentCanonical = parent .getCanonicalPath () + "/potato" ;
173
- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
173
+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) { // $hasTaintFlow
174
174
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
175
175
}
176
176
}
@@ -188,7 +188,7 @@ InputStream foo20(String... path) {
188
188
String filePath = sb .toString ();
189
189
File encodedFile = new File (filePath );
190
190
try {
191
- if (!encodedFile .getCanonicalPath ().startsWith (cacheDir .getCanonicalPath ())) {
191
+ if (!encodedFile .getCanonicalPath ().startsWith (cacheDir .getCanonicalPath ())) { // $hasTaintFlow
192
192
return null ;
193
193
}
194
194
return Files .newInputStream (encodedFile .toPath ());
@@ -206,7 +206,7 @@ void foo21(File dir, File parent) throws IOException {
206
206
207
207
void foo22 (File dir , File dir2 , File parent , boolean conditional ) throws IOException {
208
208
String canonicalPath = conditional ? dir .getCanonicalPath () : dir2 .getCanonicalPath ();
209
- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
209
+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
210
210
throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
211
211
}
212
212
}
0 commit comments