Fix partial path traversal Java example Again

The original wouldn't compile, and the fix made by #11899 is sub-optimal.
This keeps the entire comparision using the Java `Path` object, which is optimal.

Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
This commit is contained in:
Jonathan Leitschuh
2023-03-31 11:05:28 -04:00
committed by Jonathan Leitschuh
parent b9d409279b
commit 0d774a647c

View File

@@ -225,6 +225,12 @@ public class PartialPathTraversalTest {
}
}
public void doesNotFlagOptimalSafeVersion(File dir, File parent) throws IOException {
if (!dir.toPath().normalize().startsWith(parent.toPath())) { // Safe
throw new IOException("Path traversal attempt: " + dir.getCanonicalPath());
}
}
public void doesNotFlag() {
"hello".startsWith("goodbye");
}