Java: Add test for sanitization using toAbsolutePath().

This commit is contained in:
Anders Schack-Mulligen
2018-10-19 14:49:50 +02:00
parent bf6b7c4734
commit 4953e4923a

View File

@@ -41,4 +41,14 @@ public class ZipTest {
validate(dir, file);
FileOutputStream os = new FileOutputStream(file); // OK
}
public void m5(ZipEntry entry, File dir) {
String name = entry.getName();
File file = new File(dir, name);
Path absfile = file.toPath().toAbsolutePath().normalize();
Path absdir = dir.toPath().toAbsolutePath().normalize();
if (!absfile.startsWith(absdir))
throw new Exception();
FileOutputStream os = new FileOutputStream(file); // OK
}
}