104 lines
9.0 KiB
Markdown
104 lines
9.0 KiB
Markdown
---
|
||
title: OWASP Path Traversal — dot-dot-slash attack and encoding bypasses
|
||
source_type: official-doc
|
||
url: https://owasp.org/www-community/attacks/Path_Traversal
|
||
archive_url:
|
||
status: raw
|
||
confidence: high
|
||
related_branches: [feature-file-resource-handling-contract]
|
||
related_projects: [ca-skeleton-operational-contract]
|
||
tags: [ca-security, path-traversal, owasp, directory-traversal, allowlist, encoding-bypass, official-doc]
|
||
created: 2026-05-27
|
||
last_reviewed: 2026-05-27
|
||
---
|
||
|
||
# OWASP Path Traversal
|
||
|
||
> Layer: `raw/official-docs/` — OWASP community 발행 path traversal attack 분류 페이지. ca-tmpl file resource handling contract 의 path traversal 방어 결정 (filename allowlist + URL decode 후 검증 + canonicalization) 의 1차 근거.
|
||
|
||
## Parent / 활용 branch (필수)
|
||
|
||
| Branch | 이 자료가 정당화하는 결정 |
|
||
|---|---|
|
||
| [[raw/branch-notes/feature-file-resource-handling-contract]] | path traversal 방어 결정 — `../` sequence + URL encoded variant (`%2e%2e%2f`) + null byte (`%00`) + absolute path 모두 거부, "accept known good" allowlist 접근 (sanitize 금지) 근거 |
|
||
|
||
## 컨텍스트 / 왜 저장했는지
|
||
|
||
ca-tmpl 의 file download / static resource serving 결정에서 "왜 filename sanitize 가 아닌 allowlist 가 권고되는가", "왜 URL decode 후 검증해야 하는가 (%2e%2e%2f bypass)", "왜 null byte 종료 공격을 고려해야 하는가" 결정의 1차 근거. 본 페이지는 attack 분류 (definition) 페이지로 cheatsheet 와는 다름.
|
||
|
||
## 출처 / Source
|
||
|
||
- 원본 URL: https://owasp.org/www-community/attacks/Path_Traversal
|
||
- 아카이브 URL: (미수집)
|
||
- 저자 / 조직: OWASP Foundation (community wiki — attack 분류)
|
||
- 발행일: rolling docs
|
||
- 마지막 확인일: 2026-05-27 (WebFetch verbatim 확인)
|
||
|
||
## 핵심 인용 / Key quotes (verbatim, captured 2026-05-27)
|
||
|
||
> [§Overview] "A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root folder."
|
||
|
||
> [§Overview] "By manipulating variables that reference files with 'dot-dot-slash (../)'sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files."
|
||
|
||
> [§How to protect yourself] "Validate the user's input by only accepting known good – do not sanitize the data."
|
||
|
||
> [§Request variations] "%2e%2e%2f represents ../ [and] %2e%2e%5c represents ..\\"
|
||
|
||
> [§Description - OS specific] "In many operating systems, null bytes %00 can be injected to terminate the filename."
|
||
|
||
> [§Example 4] "The repeated ../ characters after /home/users/phpguru/templates/ has caused include() to traverse to the root directory."
|
||
|
||
> [§Absolute Path Traversal] "When the web server returns information about errors in a web application, it is much easier for the attacker to guess the correct locations."
|
||
|
||
## Claims Extracted / 추출된 주장
|
||
|
||
| Claim ID | Claim (이 자료가 직접 말하는 것) | Evidence quote | Strength | Applies to | Does not prove |
|
||
|---|---|---|---|---|---|
|
||
| OWASP-PT-C1 | path traversal (= directory traversal) 은 **web root 밖** 의 파일/디렉토리에 접근하려는 공격 | [§Overview] "A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root folder." | `official-reference` (OWASP community wiki — 표준 아님) | path traversal 공격 분류 결정 | web root 안의 unauthorized file 접근 (예: 다른 user 의 file) 도 별도 — IDOR/BOLA 영역 |
|
||
| OWASP-PT-C2 | 공격 벡터: `../` (dot-dot-slash) sequence 와 그 variation, 또는 **absolute file path** 로 임의 파일 접근 가능 | [§Overview] "By manipulating variables that reference files with 'dot-dot-slash (../)'sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files." | `official-reference` | filename 입력 검증 시 `../` + absolute path 모두 차단 결정 | `..` 만 차단해도 안전하다는 뜻은 아님 — variation (%2e%2e%2f 등) 별도 |
|
||
| OWASP-PT-C3 | 방어 원칙: 사용자 입력은 **"known good only" allowlist 로 검증** — sanitize **하지 말 것** | [§How to protect yourself] "Validate the user's input by only accepting known good – do not sanitize the data." | `official-reference` | filename allowlist (예: `^[a-zA-Z0-9_-]+\.(jpg|png|pdf)$`) 접근 결정 — blacklist sanitize (`../` 제거) 금지 | sanitize 가 절대 불가능하다는 뜻은 아님 — defense in depth 로 sanitize + allowlist 둘 다 가능 |
|
||
| OWASP-PT-C4 | URL encoded variation: `%2e%2e%2f` = `../`, `%2e%2e%5c` = `..\` — encoding 으로 bypass 가능 | [§Request variations] "%2e%2e%2f represents ../ [and] %2e%2e%5c represents ..\\" | `official-reference` | URL decode 후 검증 결정 (decode 전 검증은 bypass 가능) | double encoding (`%252e%252e%252f`) 같은 nested encoding 은 본 인용 범위 밖 — 별도 고려 필요 |
|
||
| OWASP-PT-C5 | 많은 OS 에서 **null byte `%00`** 을 inject 하여 filename 을 종료시켜 검증 우회 가능 | [§Description - OS specific] "In many operating systems, null bytes %00 can be injected to terminate the filename." | `official-reference` | filename 검증 시 null byte 거부 결정 | 모든 modern runtime (Java NIO 등) 이 null byte 에 취약하다는 뜻은 아님 — legacy C-based file API 위주 |
|
||
| OWASP-PT-C6 | `../` 반복으로 root directory 까지 traverse 가능 (예: `/home/users/phpguru/templates/../../../../etc/passwd`) | [§Example 4] "The repeated ../ characters after /home/users/phpguru/templates/ has caused include() to traverse to the root directory." | `official-reference` | path traversal 의 destructive 잠재력 인지 — `/etc/passwd`, application config 등 노출 | application 이 file system root 권한을 갖지 않으면 영향 제한 — 본 인용은 권한 가정 |
|
||
| OWASP-PT-C7 | web server 가 error 정보에서 file path 를 노출하면 공격자가 정확한 location 을 추측하기 훨씬 쉬워짐 | [§Absolute Path Traversal] "When the web server returns information about errors in a web application, it is much easier for the attacker to guess the correct locations." | `official-reference` | error response 에 file path 노출 금지 결정 (generic error message 정책) | error path 노출이 단독 취약점이라는 뜻은 아님 — information disclosure 보조 요인 |
|
||
|
||
## Usage Boundaries / 적용 경계
|
||
|
||
- **이 자료가 직접 증명하는 것** (2026-05-27 WebFetch verbatim 확인):
|
||
- `OWASP-PT-C1`: path traversal 정의 (web root 밖 접근)
|
||
- `OWASP-PT-C2`: 공격 벡터 (`../` + absolute path)
|
||
- `OWASP-PT-C3`: 방어 원칙 (allowlist, not sanitize)
|
||
- `OWASP-PT-C4`: URL encoded variation
|
||
- `OWASP-PT-C5`: null byte injection
|
||
- `OWASP-PT-C6`: root directory traversal 예시
|
||
- `OWASP-PT-C7`: error response 의 path 노출 위험
|
||
- **이 자료가 증명하지 않는 것**:
|
||
- 구체적 framework (Spring, Express, Django) 별 안전한 file API 권고 — 본 페이지는 attack 분류만
|
||
- canonicalization 함수 (Java `Path.normalize()`, `realpath()` 등) 의 안전성 보장 — 별도 cheatsheet / 벤더 doc 위임
|
||
- double encoding / Unicode normalization 같은 advanced bypass — 본 인용 범위 밖
|
||
- WAF rule 로 path traversal 차단의 효과 — 본 페이지는 application layer 방어만
|
||
- OWASP community wiki 는 **공격 분류 + 권고** 이며 강제 표준 아님.
|
||
- **내 프로젝트에 적용하려면 추가 확인이 필요한 것**:
|
||
- ca-tmpl 의 file serving 경로에서 Spring Resource API (`Resource.getFile()`, `Path.resolve()`) 의 canonicalization 동작 확인
|
||
- filename allowlist regex 의 구체적 정의 (확장자 + 문자 집합)
|
||
- URL decode 처리 순서 — Spring `@PathVariable` 자동 decode 후 검증 vs raw path 검증
|
||
- error response 에서 file path 가 노출되는 경로 (stack trace, 404 message 등) 점검
|
||
|
||
## 메모 / Notes
|
||
|
||
- **다른 OWASP 자료와의 관계**: 본 페이지는 공격 분류, [[raw/official-docs/owasp-file-upload-cheat-sheet]] 는 upload 방어, OWASP Input Validation Cheat Sheet 는 일반 input 검증. 세 자료가 path traversal 의 서로 다른 측면을 커버.
|
||
- **CWE 매핑**: CWE-22 (Improper Limitation of a Pathname to a Restricted Directory). 본 페이지에는 CWE 번호 명시 없지만 일반적으로 매핑됨.
|
||
- **"allowlist not sanitize" 의 의미** (`C3`): sanitize 는 blacklist 기반 ("../" 제거) 이라 bypass variation 에 취약. allowlist 는 "known good 패턴" 만 허용 → 새로운 bypass 에도 안전. ca-tmpl 의 file resource 에서는 allowlist 우선 권고.
|
||
|
||
## Related / 관련
|
||
|
||
- 같은 주제 다른 official-doc:
|
||
- [[raw/official-docs/owasp-file-upload-cheat-sheet]] (upload 방어 — 본 자료와 짝)
|
||
- OWASP Input Validation Cheat Sheet — 별도 raw 작성 후보
|
||
- CWE-22 (MITRE) — 별도 raw 작성 후보
|
||
- 인용하는 branch:
|
||
- [[raw/branch-notes/feature-file-resource-handling-contract]]
|
||
- 인용하는 project:
|
||
- [[raw/project-notes/ca-skeleton-operational-contract]]
|
||
- 인용한 wiki 요약: (미작성)
|