Skip to content

Commit 01cec04

Browse files
authored
Abbreviate qhelp
1 parent 65b9947 commit 01cec04

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

java/ql/src/Security/CWE/CWE-023/PartialPathTraversal.qhelp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
"qhelp.dtd">
44
<qhelp>
55
<overview>
6-
<p>User supplied file paths can often pose security risks if a program does not handle them correctly. In particular, if a user
7-
is meant to access files under a certain directory but does not enter a path under that directory, they can
8-
unexpectedly gain access to (and potentially modify/delete) possibly sensitive resources. </p>
9-
10-
<p>Suppose a program is to only accept paths that point to files/folders within directory <code>DIR</code>.
11-
To ensure that a user supplied path, say <code>SUBDIR</code>, is a subdirectory of <code>DIR</code>, the
12-
program verifies, using string comparisons, that <code>DIR</code> is a prefix of <code>SUBDIR</code>.
13-
However, if <code>DIR</code> is not slash-terminated, such a check would not be sufficient.
14-
<code>SUBDIR</code> may be allowed to also access siblings of <code>DIR</code> and not
15-
just children of <code>DIR</code>, which is a security vulnerability.</p>
16-
6+
<p>A common way to check that a user-supplied path <code>SUBDIR</code> falls inside a directory <code>DIR</code>
7+
is to use <code>getCanonicalPath()</code> to remove any path-traversal elements and then check that <code>DIR</code>
8+
is a prefix. However, if <code>DIR</code> is not slash-terminated, this can unexpectedly allow accessing siblings of <code>DIR</code>.</p>
179
</overview>
1810
<recommendation>
1911

20-
<p>If the user should only access items within a certain directory <code>DIR</code>, first ensure that <code>DIR</code> is slash-terminated,
21-
and then proceed (as normal) to verify that <code>DIR</code> is a prefix of the user-provided path, <code>SUBDIR</code>. Note, Java's <code>getCanonicalPath()</code>
22-
returns a <b>non</b>-slash-terminated path string, so a <code>"/"</code> must be added to <code>DIR</code> if that method is used. </p>
12+
<p>If the user should only access items within a certain directory <code>DIR</code>, ensure that <code>DIR</code> is slash-terminated
13+
before checking that <code>DIR</code> is a prefix of the user-provided path, <code>SUBDIR</code>. Note, Java's <code>getCanonicalPath()</code>
14+
returns a <b>non</b>-slash-terminated path string, so a slash must be added to <code>DIR</code> if that method is used.</p>
2315

2416
</recommendation>
2517
<example>

0 commit comments

Comments
 (0)