Skip to content

Commit 2942598

Browse files
authored
Merge pull request #11899 from ataillefer/patch-1
Fix partial path traversal Java example
2 parents 51bd1ef + 660e6d7 commit 2942598

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

java/ql/src/Security/CWE/CWE-023/PartialPathTraversalGood.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
public class PartialPathTraversalGood {
22
public void example(File dir, File parent) throws IOException {
3-
if (!dir.getCanonicalPath().toPath().startsWith(parent.getCanonicalPath().toPath())) {
3+
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath() + File.separator)) {
44
throw new IOException("Invalid directory: " + dir.getCanonicalPath());
55
}
66
}

java/ql/src/Security/CWE/CWE-023/PartialPathTraversalRemainder.inc.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ and not just children of <code>parent</code>, which is a security issue.
2727
<p>
2828

2929
In this example, the <code>if</code> statement checks if <code>parent.getCanonicalPath() + File.separator </code>
30-
is a prefix of <code>dir.getCanonicalPath()</code>. Because <code>parent.getCanonicalPath().toPath()</code> is
30+
is a prefix of <code>dir.getCanonicalPath()</code>. Because <code>parent.getCanonicalPath() + File.separator</code> is
3131
indeed slash-terminated, the user supplying <code>dir</code> can only access children of
3232
<code>parent</code>, as desired.
3333

0 commit comments

Comments
 (0)