Skip to content

Commit 6e7c7c2

Browse files
atorralbasubatoi
andauthored
Update swift/ql/src/queries/Security/CWE-022/PathInjection.qhelp
Co-authored-by: Ben Ahmady <[email protected]>
1 parent 6bb54f0 commit 6e7c7c2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

swift/ql/src/queries/Security/CWE-022/PathInjection.qhelp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,29 @@ such as <code>..</code>. Such a path could point to any directory on the file sy
2626

2727
<example>
2828
<p>
29-
In the first example, a file name is read from an HTTP request and then used to access a file.
30-
However, a malicious response could include a file name that is an absolute path, such as
29+
The following code shows two bad examples.
30+
31+
<sample src="PathInjectionBad.swift" />
32+
33+
In the first, a file name is read from an HTTP request and then used to access a file. In this case, a malicious response could include a file name that is an absolute path, such as
3134
<code>"/Applications/(current_application)/Documents/sensitive.data"</code>.
3235
</p>
3336

3437
<p>
35-
In the second example, it appears that the user is restricted to opening a file within the
36-
<code>"/Library/Caches"</code> home directory. However, a malicious response could contain a file name containing
38+
In the second bad example, it appears that the user is restricted to opening a file within the
39+
<code>"/Library/Caches"</code> home directory. In this case, a malicious response could contain a file name containing
3740
special characters. For example, the string <code>"../../Documents/sensitive.data"</code> will result in the code
3841
reading the file located at <code>"/Applications/(current_application)/Library/Caches/../../Documents/sensitive.data"</code>,
39-
which contains users' sensitive data. This file may then be made accesible to an attacker, giving them access to all this data.
42+
which contains users' sensitive data. This file may then be made accessible to an attacker, giving them access to all this data.
4043
</p>
4144

42-
<sample src="PathInjectionBad.swift" />
43-
4445
<p>
45-
In the third example, the path used to access the file system is normalized <em>before</em> being checked against a
46+
In the following (good) example, the path used to access the file system is normalized <em>before</em> being checked against a
4647
known prefix. This ensures that regardless of the user input, the resulting path is safe.
4748
</p>
4849

4950
<sample src="PathInjectionGood.swift" />
50-
51+
```suggestion
5152
</example>
5253

5354
<references>

0 commit comments

Comments
 (0)