JAVA-013 / 初級
ファイルダウンロードのパストラバーサル
なぜ問題になるのか?
../../etc/passwd により任意ファイルを読み取れます。
修正方法
java
Path base = Path.of("/data/files").toRealPath();
Path file = base.resolve(name).toRealPath();
if (!file.startsWith(base) || !Files.isRegularFile(file)) {
throw new SecurityException();
}