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-03 - [Symlink Resolution Vulnerability Bypass]
**Vulnerability:** The top directory path evaluation used `canonicalFile`, which resolves symlinks. This bypassed the security check `Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)` and allowed paths containing symlinks to be processed unexpectedly.
**Learning:** `canonicalFile` strictly resolves all symlinks in the path. Using it before checking for symlinks defeats the purpose of the security check as the target is evaluated directly.
**Prevention:** Use `absoluteFile.normalize()` instead of `canonicalFile` when the goal is to evaluate the path logic (like `.` and `..`) without traversing symlinks. This maintains the true file type to properly enforce `LinkOption.NOFOLLOW_LINKS`.
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
// ๋ณด์•ˆ ์ˆ˜์ •: canonicalFile์€ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ฏธ๋ฆฌ ํ•ด์„ํ•˜์—ฌ NOFOLLOW_LINKS ๊ฒ€์‚ฌ๋ฅผ ์šฐํšŒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
// absoluteFile.normalize()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ ํ•ด์„ ์—†์ด ๊ฒฝ๋กœ๋งŒ ์ •๊ทœํ™”ํ•ฉ๋‹ˆ๋‹ค.
val top_dir = File(topDir).absoluteFile.normalize()
require(Files.isDirectory(top_dir.toPath(), LinkOption.NOFOLLOW_LINKS)) { "Top directory must be an existing non-symlink directory" }

val ll = LinkedList()
Expand Down
22 changes: 22 additions & 0 deletions src/test/kotlin/html4tree/GoNormalizeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package html4tree

import org.junit.Test
import java.io.File
import java.nio.file.Files
import kotlin.test.assertTrue

class GoNormalizeTest {
@Test
fun testGoNormalize() {
val tempDir = Files.createTempDirectory("html4tree-test-").toFile()
try {
// Test that normalize() logic works without errors by using a path ending with /..
val subdir = File(tempDir, "subdir")
subdir.mkdir()
go(subdir.absolutePath + "/..", -1)
assertTrue(File(tempDir, "index.html").exists())
} finally {
tempDir.deleteRecursively()
}
}
}