diff --git a/java/ql/src/Security/CWE/CWE-023/PartialPathTraversal.qhelp b/java/ql/src/Security/CWE/CWE-023/PartialPathTraversal.qhelp index 7a11f3a0f71..902d0fc682c 100644 --- a/java/ql/src/Security/CWE/CWE-023/PartialPathTraversal.qhelp +++ b/java/ql/src/Security/CWE/CWE-023/PartialPathTraversal.qhelp @@ -3,23 +3,15 @@ "qhelp.dtd"> -

User supplied file paths can often pose security risks if a program does not handle them correctly. In particular, if a user -is meant to access files under a certain directory but does not enter a path under that directory, they can -unexpectedly gain access to (and potentially modify/delete) possibly sensitive resources.

- -

Suppose a program is to only accept paths that point to files/folders within directory DIR. -To ensure that a user supplied path, say SUBDIR, is a subdirectory of DIR, the -program verifies, using string comparisons, that DIR is a prefix of SUBDIR. -However, if DIR is not slash-terminated, such a check would not be sufficient. -SUBDIR may be allowed to also access siblings of DIR and not -just children of DIR, which is a security vulnerability.

- +

A common way to check that a user-supplied path SUBDIR falls inside a directory DIR +is to use getCanonicalPath() to remove any path-traversal elements and then check that DIR +is a prefix. However, if DIR is not slash-terminated, this can unexpectedly allow accessing siblings of DIR.

-

If the user should only access items within a certain directory DIR, first ensure that DIR is slash-terminated, -and then proceed (as normal) to verify that DIR is a prefix of the user-provided path, SUBDIR. Note, Java's getCanonicalPath() -returns a non-slash-terminated path string, so a "/" must be added to DIR if that method is used.

+

If the user should only access items within a certain directory DIR, ensure that DIR is slash-terminated +before checking that DIR is a prefix of the user-provided path, SUBDIR. Note, Java's getCanonicalPath() +returns a non-slash-terminated path string, so a slash must be added to DIR if that method is used.