Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
**Vulnerability:** Defense in Depth (CSP Missing)
**Learning:** Even when inputs are properly escaped, statically generated HTML that displays file/directory structures should implement a Content Security Policy (CSP) to provide an extra layer of defense against potential XSS bypasses.
**Prevention:** Include a strict CSP meta tag (e.g., `default-src 'none'; style-src 'unsafe-inline';`) in auto-generated HTML headers when external scripts or resources are not required.

## 2024-07-03 - [Path Traversal via Symbolic Link Canonicalization]
**Vulnerability:** `File(path).canonicalFile`์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฝ๋กœ๋ฅผ ์ •๊ทœํ™”ํ•œ ํ›„ ํ•ด๋‹น ํŒŒ์ผ ๊ฐ์ฒด์— ๋Œ€ํ•ด ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ์—ฌ๋ถ€๋ฅผ ๊ฒ€์‚ฌํ•˜๋ฉด, ์ด๋ฏธ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๊ฐ€ ์›๋ณธ ๊ฒฝ๋กœ๋กœ ํ•ด์„๋œ ์ƒํƒœ์ด๋ฏ€๋กœ `Files.isDirectory(..., LinkOption.NOFOLLOW_LINKS)` ๊ฐ™์€ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ๊ฒ€์‚ฌ๊ฐ€ ์‹คํŒจ(์šฐํšŒ)ํ•ฉ๋‹ˆ๋‹ค.
**Learning:** `canonicalFile`์€ ๋ชจ๋“  ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ํ•ด์ œํ•˜๊ณ  ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ, ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ์ž์ฒด์˜ ํŠน์„ฑ์„ ํ™•์ธํ•ด์•ผ ํ•  ๋•Œ๋Š” ์‚ฌ์šฉํ•ด์„œ๋Š” ์•ˆ ๋ฉ๋‹ˆ๋‹ค. ์ด๋กœ ์ธํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ œ์–ด ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ๋””๋ ‰ํ† ๋ฆฌ๋กœ Path Traversal์ด ๊ฐ€๋Šฅํ•ด์ง‘๋‹ˆ๋‹ค.
**Prevention:** ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๊ฒ€์‚ฌํ•˜๊ฑฐ๋‚˜ ํŒŒ์ผ ์‹œ์Šคํ…œ ๊ฒฝ๊ณ„๋ฅผ ์œ ์ง€ํ•ด์•ผ ํ•  ๋•Œ๋Š” `canonicalFile` ๋Œ€์‹  `absoluteFile`์„ ์‚ฌ์šฉํ•˜์—ฌ ์ž…๋ ฅ๋œ ๊ฒฝ๋กœ์˜ ์›๋ž˜ ํ˜•ํƒœ(์‹ฌ๋ณผ๋ฆญ ๋งํฌ ํฌํ•จ)๋ฅผ ๋ณด์กดํ•œ ์ฑ„๋กœ ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
4 changes: 3 additions & 1 deletion src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ fun main(args: Array<String>) = Html4tree().main(args)

fun go(topDir: String, maxLevel: Int) {
require(topDir.isNotBlank())
val top_dir = File(topDir).canonicalFile
// ๐Ÿ›ก๏ธ Sentinel: Path Traversal ๋ฐ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ์ด์šฉํ•œ ๊ฒ€์‚ฌ ์šฐํšŒ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด
// canonicalFile ๋Œ€์‹  absoluteFile์„ ์‚ฌ์šฉํ•˜์—ฌ ์›๋ณธ ๊ฒฝ๋กœ ํ˜•ํƒœ๋ฅผ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.
val top_dir = File(topDir).absoluteFile
require(Files.isDirectory(top_dir.toPath(), LinkOption.NOFOLLOW_LINKS)) { "Top directory must be an existing non-symlink directory" }

val ll = LinkedList()
Expand Down