mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Fix duplicate class header and better fix using toPath()
This commit is contained in:
@@ -39,7 +39,7 @@ and not just children of <code>parent</code>, which is a security issue.
|
||||
<p>
|
||||
|
||||
In this example, the <code>if</code> statement checks if <code>parent.getCanonicalPath() + File.separator </code>
|
||||
is a prefix of <code>dir.getCanonicalPath()</code>. Because <code>parent.getCanonicalPath() + File.separator</code> is
|
||||
is a prefix of <code>dir.getCanonicalPath()</code>. Because <code>parent.getCanonicalPath().toPath()</code> is
|
||||
indeed slash-terminated, the user supplying <code>dir</code> can only access children of
|
||||
<code>parent</code>, as desired.
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import java.io.File;
|
||||
|
||||
public class PartialPathTraversalBad {
|
||||
public class PartialPathTraversalGood {
|
||||
public void esapiExample(File dir, File parent) throws IOException {
|
||||
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath() + File.separator)) {
|
||||
if (!dir.getCanonicalPath().startsWith(parent.getCanonicalPath().toPath())) {
|
||||
throw new IOException("Invalid directory: " + dir.getCanonicalPath());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user