File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
python/ql/src/Security/CWE-022 Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -23,14 +23,15 @@ The choice of validation depends on the use case.
2323<p >
2424If you want to allow paths spanning multiple folders, a common strategy is to make sure that the constructed
2525file 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
2728root folder. Note that the normalization step is important, since otherwise even a path that starts with the root
2829folder could be used to access files outside the root folder.
2930</p >
3031
3132<p >
3233More 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
3435safe, but can only be used in particular circumstances.
3536</p >
3637</recommendation >
You can’t perform that action at this time.
0 commit comments