← Java / Spring 목차

JAVA-013 / 기초

경로 탐색 (파일 다운로드)

A01:2021 Broken Access Control · CWE-22 Path Traversal

왜 문제가 될까요?

../../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();
}

더 읽기