Skip to content

Commit 5f970d9

Browse files
authored
Rewordings per copilot
1 parent bed1ec8 commit 5f970d9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

python/ql/src/Security/CWE-022/PathInjection.qhelp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ The choice of validation depends on the use case.
2323
<p>
2424
If you want to allow paths spanning multiple folders, a common strategy is to make sure that the constructed
2525
file path is contained within a safe root folder. First, normalize the path using <code>os.path.normpath</code> or
26-
<code>os.path.realpath</code> to remove any ".." segments. Then check that the normalized path starts with the
26+
<code>os.path.realpath</code> (make sure to use the latter if symlinks are a consideration)
27+
to remove any internal ".." segments and/or follow links. Then check that the normalized path starts with the
2728
root folder. Note that the normalization step is important, since otherwise even a path that starts with the root
2829
folder could be used to access files outside the root folder.
2930
</p>
3031

3132
<p>
3233
More restrictive options include using a library function like <code>werkzeug.utils.secure_filename</code> to eliminate
33-
any special characters from the file path, or restricting the path to an allow list of safe paths. These options are
34+
any special characters from the file path, or restricting the path to a known list of safe paths. These options are
3435
safe, but can only be used in particular circumstances.
3536
</p>
3637
</recommendation>

0 commit comments

Comments
 (0)