7
7
can result in sensitive information being revealed or deleted, or an attacker being able to influence
8
8
behavior by modifying unexpected files.</p >
9
9
10
- <p >Paths that are naively constructed from data controlled by a user may be absolute paths or contain
11
- unexpected special characters, such as "..". Such a path may potentially point anywhere on the file system.</p >
10
+ <p >Paths that are naively constructed from data controlled by a user may be absolute paths, or may contain
11
+ unexpected special characters such as "..". Such a path could point anywhere on the file system.</p >
12
12
13
13
</overview >
14
14
<recommendation >
15
15
16
16
<p >Validate user input before using it to construct a file path.</p >
17
17
18
18
<p >Common validation methods include checking that the normalized path is relative and does not contain
19
- any ".." components, or that the path is contained within a safe folder. The validation method to use depends
20
- on how the path is used in the application and whether the path is supposed to be a single path component.
21
- </p >
19
+ any ".." components, or checking that the path is contained within a safe folder. The method you should use depends
20
+ on how the path is used in the application, and whether the path should be a single path component.
22
21
23
- <p >If the path is supposed to be a single path component (such as a file name) you can check for the existence
24
- of any path separators ("/" or "\") or ".." sequences in the input, and reject the input if any are found.
22
+ <p >If the path should be a single path component (such as a file name), you can check for the existence
23
+ of any path separators ("/" or "\"), or ".." sequences in the input, and reject the input if any are found.
25
24
</p >
26
25
27
26
<p >
@@ -43,14 +42,13 @@ such as "/etc/passwd" or "../../../etc/passwd".</p>
43
42
<sample src =" examples/TaintedPath.java" />
44
43
45
44
<p >
46
- If the input is just supposed to be a file name, you can check that it doesn't contain any path separators
47
- or ".." sequences.
45
+ If the input should only be a file name, you can check that it doesn't contain any path separators or ".." sequences.
48
46
</p >
49
47
50
48
<sample src =" examples/TaintedPathGoodNormalize.java" />
51
49
52
50
<p >
53
- If the input is supposed to be found within a specific directory, you can check that the resolved path
51
+ If the input should be within a specific directory, you can check that the resolved path
54
52
is still contained within that directory.
55
53
</p >
56
54
0 commit comments