I catch "Stored Absolute Path Traversal" for 2 operations in my Java code:
byte[] buffer = Files.readAllBytes(dir);
Files.readAllLines(dir)
Argument dir is created as follows:
Path dir = Paths.get(Paths.get(base, parts).normalize().toString().replace(" ", "_"));
So, I tried to sanitize path creation, by normalization and replace of empty characters, but this does not work.
Also I tried to apply File(path).getCanonicalPath():
String canonicalPath;
String path = Paths.get(base, parts)
.normalize()
.toString().replace(" ", "_");
try {
canonicalPath = new File(path).getCanonicalPath();
} catch (Exception e) {
throw new RuntimeExceptione);
}
But with the same effect.