JAVA-013 / Beginner
Path traversal in file downloads
Why is this a problem?
An arbitrary file can be read using ../../etc/passwd.
How to fix it
java
Path base = Path.of("/data/files").toRealPath();
Path file = base.resolve(name).toRealPath();
if (!file.startsWith(base) || !Files.isRegularFile(file)) {
throw new SecurityException();
}