Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ab8f02

Browse files
committed
Fix duplicate class header and better fix using toPath()
1 parent 955e614 commit 7ab8f02

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

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

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

4141
In this example, the <code>if</code> statement checks if <code>parent.getCanonicalPath() + File.separator </code>
42-
is a prefix of <code>dir.getCanonicalPath()</code>. Because <code>parent.getCanonicalPath() + File.separator</code> is
42+
is a prefix of <code>dir.getCanonicalPath()</code>. Because <code>parent.getCanonicalPath().toPath()</code> is
4343
indeed slash-terminated, the user supplying <code>dir</code> can only access children of
4444
<code>parent</code>, as desired.
4545

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import java.io.File;
22

3-
public class PartialPathTraversalBad {
3+
public class PartialPathTraversalGood {
44
public void esapiExample(File dir, File parent) throws IOException {
5-
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath() + File.separator)) {
5+
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath().toPath())) {
66
throw new IOException("Invalid directory: " + dir.getCanonicalPath());
77
}
88
}

0 commit comments

Comments
 (0)