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.

## 2026-07-02 - [Fix Path Traversal/Symlink Bypass in File Checking]
**Vulnerability:** ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ๋””๋ ‰ํ† ๋ฆฌ์ธ์ง€ ๊ฒ€์ฆํ•˜๋Š” ๊ณผ์ •์—์„œ `File.canonicalFile`์„ ์‚ฌ์šฉํ•˜๋ฉด, JVM/OS๊ฐ€ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋Œ€์ƒ ๊ฒฝ๋กœ(์‹ค์ œ ๋””๋ ‰ํ† ๋ฆฌ)๋กœ ๋ฏธ๋ฆฌ ํ•ด์„(resolve)ํ•ด ๋ฒ„๋ฆฝ๋‹ˆ๋‹ค. ๊ทธ ๊ฒฐ๊ณผ `Files.isDirectory(..., LinkOption.NOFOLLOW_LINKS)`๊ฐ€ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ์ž์ฒด๊ฐ€ ์•„๋‹Œ ์‹ค์ œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ฒ€์‚ฌํ•˜๊ฒŒ ๋˜์–ด ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ๊ฒ€์ฆ์„ ์šฐํšŒํ•˜๋Š” ๋ณด์•ˆ ์ทจ์•ฝ์ ์ด ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.
**Learning:** `canonicalFile`์€ ๋ชจ๋“  ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ํ•ด์„ํ•˜๊ณ  ์ •๊ทœํ™”๋œ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ์ž์ฒด์˜ ์†์„ฑ์„ ๊ฒ€์‚ฌํ•ด์•ผ ํ•  ๋•Œ(์˜ˆ: ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š๊ฑฐ๋‚˜, ๊ฒฝ๋กœ ํƒ์ƒ‰์„ ๋ฐฉ์ง€ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ) `canonicalFile`์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฒ€์ฆ ๋กœ์ง์ด ๋ฌดํšจํ™”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
**Prevention:** ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ๊ฒ€์ฆ ์‹œ์—๋Š” ๊ฒฝ๋กœ์˜ ์ƒ๋Œ€์„ฑ๋งŒ ํ•ด๊ฒฐํ•˜๊ณ  ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ํ•ด์„ํ•˜์ง€ ์•Š๋Š” `Path.toAbsolutePath().normalize()`์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ํ›„ `LinkOption.NOFOLLOW_LINKS`์™€ ๊ฐ™์€ ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์•ˆ์ „ํ•˜๊ฒŒ ํŒŒ์ผ ์‹œ์Šคํ…œ ์†์„ฑ์„ ๊ฒ€์‚ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
3 changes: 2 additions & 1 deletion src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ fun main(args: Array<String>) = Html4tree().main(args)

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

val ll = LinkedList()
Expand Down