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-06 - [html4tree] Directory Traversal Bypass via Canonical File
**Vulnerability:** Path traversal and directory boundary escape through top-level symbolic links.
**Learning:** Using `File.canonicalFile` resolves symbolic links to their absolute target paths before any subsequent checks are performed. This renders `Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)` useless because the path passed to it has already had all symlinks resolved by `canonicalFile`, meaning it will appear as a normal directory and bypass symlink checks.
**Prevention:** When you need an absolute path but must preserve symbolic links for validation purposes, use `.toPath().toAbsolutePath().normalize().toFile()` instead of `.canonicalFile`. This normalizes `.` and `..` without resolving symbolic links, allowing `LinkOption.NOFOLLOW_LINKS` checks to function correctly.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ๋ณ€๊ฒฝ ์‚ฌํ•ญ

## [Unreleased]
### ๋ณด์•ˆ (Security)
- `canonicalFile` ๋Œ€์‹  `normalize()`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ `html4tree`์˜ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ๊ธฐ๋ฐ˜ ๋””๋ ‰ํ† ๋ฆฌ ํƒ์ƒ‰ ์šฐํšŒ ์ทจ์•ฝ์ ์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. `canonicalFile`์€ ์‚ฌ์ „์— ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋Œ€์ƒ ๊ฒฝ๋กœ๋กœ ํ•ด์„ํ•˜์—ฌ ์ด์–ด์ง€๋Š” `LinkOption.NOFOLLOW_LINKS` ๊ฒ€์‚ฌ๋ฅผ ๋ฌด๋ ฅํ™”ํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
2 changes: 1 addition & 1 deletion src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun main(args: Array<String>) = Html4tree().main(args)

fun go(topDir: String, maxLevel: Int) {
require(topDir.isNotBlank())
val top_dir = File(topDir).canonicalFile
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
Loading