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 @@ -88,3 +88,8 @@
**Vulnerability:** CSP ํ•ด์‹œ ๋ถˆ์ผ์น˜๋กœ ์ธํ•œ ์ธ๋ผ์ธ ์Šคํƒ€์ผ ์ฐจ๋‹จ
**Learning:** ๋ธŒ๋ผ์šฐ์ €๋Š” ์ธ๋ผ์ธ ์Šคํฌ๋ฆฝํŠธ์™€ ์Šคํƒ€์ผ์˜ ๋‚ด๋ถ€ ํ…์ŠคํŠธ(๊ณต๋ฐฑ๊ณผ ์ค„๋ฐ”๊ฟˆ ํฌํ•จ)๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ํ•ด์‹ฑํ•˜์—ฌ Content-Security-Policy(CSP) ํ•ด์‹œ์™€ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. Kotlin์˜ ๋ฉ€ํ‹ฐ๋ผ์ธ ๋ฌธ์ž์—ด(`"""`)์„ ์‚ฌ์šฉํ•˜์—ฌ ํ…œํ”Œ๋ฆฟ์— ์ฝ˜ํ…์ธ ๋ฅผ ์ฃผ์ž…ํ•  ๋•Œ ์•”๋ฌต์ ์ธ ์—ฌ๋ฐฑ์ด๋‚˜ ์ค„๋ฐ”๊ฟˆ์ด ์ถ”๊ฐ€๋˜๋ฉด ์ตœ์ข… HTML ๋ฌธ์ž์—ด์ด ๋ณ€๊ฒฝ๋˜์–ด CSP ํ•ด์‹œ๊ฐ€ ๋ฌดํšจํ™”๋ฉ๋‹ˆ๋‹ค.
**Prevention:** ์ฝ˜ํ…์ธ ๋ฅผ ํ•ด์‹ฑํ•˜๊ธฐ ์ „์— `.trimIndent()`๋ฅผ ์ ์šฉํ•˜์—ฌ ์›๋ณธ ๋ฌธ์ž์—ด์„ ์ •๊ทœํ™”ํ•˜๊ณ , HTML ํ…œํ”Œ๋ฆฟ์— ์ฃผ์ž…ํ•  ๋•Œ `<style>${exactContent}</style>`์™€ ๊ฐ™์ด ๊ณต๋ฐฑ ์—†์ด ์ฃผ์ž…ํ•˜์—ฌ ํ•ด์‹œ๊ฐ€ ์™„๋ฒฝํ•˜๊ฒŒ ์ผ์น˜ํ•˜๋„๋ก ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

## 2024-07-28 - [html4tree] ์œ ๋‹ˆ์ฝ”๋“œ ํ˜ธ๋ชจ๊ธ€๋ฆฌํ”„๋ฅผ ํ†ตํ•œ ์ˆจ๊น€ ํŒŒ์ผ ์šฐํšŒ ์ทจ์•ฝ์  ์ˆ˜์ •
**Vulnerability:** ํŒŒ์ผ ์ด๋ฆ„ ํ•„ํ„ฐ๋ง์„ ์šฐํšŒํ•˜๊ธฐ ์œ„ํ•ด ๋งˆ์นจํ‘œ(.) ๋Œ€์‹  ์œ ๋‹ˆ์ฝ”๋“œ ํ˜ธ๋ชจ๊ธ€๋ฆฌํ”„(์˜ˆ: U+3002, U+FF0E, U+FF61)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆจ๊น€ ํŒŒ์ผ์„ ์ƒ์„ฑ ๋ฐ ๋…ธ์ถœ์‹œํ‚ค๋Š” ์ทจ์•ฝ์ .
**Learning:** ์ˆจ๊น€ ํŒŒ์ผ์ด๋‚˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ํ•„ํ„ฐ๋งํ•  ๋•Œ ๋‹จ์ˆœํžˆ ASCII ๋งˆ์นจํ‘œ('.')๋งŒ ๊ฒ€์‚ฌํ•˜๋ฉด ์•…์˜์ ์ธ ์‚ฌ์šฉ์ž๊ฐ€ ์œ ๋‹ˆ์ฝ”๋“œ ํ˜ธ๋ชจ๊ธ€๋ฆฌํ”„๋ฅผ ์•…์šฉํ•˜์—ฌ ํ•„ํ„ฐ๋ง์„ ์šฐํšŒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
**Prevention:** ํŒŒ์ผ ์‹œ์Šคํ…œ ํ•„ํ„ฐ๋ง ๋กœ์ง์—์„œ ์œ ๋‹ˆ์ฝ”๋“œ ํ˜ธ๋ชจ๊ธ€๋ฆฌํ”„๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์‹๋ณ„ํ•˜๊ณ  ์ฐจ๋‹จํ•˜๋Š” ์ถ”๊ฐ€ ๊ฒ€์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
12 changes: 9 additions & 3 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal fun crawl_directories(
dirFiles?.forEach {
// โšก Bolt Performance Optimization: Short-circuit OS stat calls (isDirectory/isSymbolicLink)
// by checking cheap in-memory string exclusion rules first
if(!it.name.startsWith(".") && it.name !in exclude && isDirectory(it) && !isSymbolicLink(it)) {
if(!it.name.isHiddenFile() && it.name !in exclude && isDirectory(it) && !isSymbolicLink(it)) {
val childEntry = LinkedListEntry(it, currentLevel+1, readIdentity(it).key)
ll.push(childEntry)
}
Expand All @@ -186,6 +186,12 @@ internal fun crawl_directories(
}
}

fun String.isHiddenFile(): Boolean {
if (this.isEmpty()) return false
val firstChar = this[0]
return firstChar == '.' || firstChar == '\u3002' || firstChar == '\uFF0E' || firstChar == '\uFF61'
}

// โšก Bolt Performance Optimization: Single-pass loop with lazy StringBuilder
// Chained `.replace()` calls allocate multiple intermediate strings.
// A single pass over the string lazily allocating a StringBuilder is much faster.
Expand Down Expand Up @@ -303,7 +309,7 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S

// ๋ณด์•ˆ ํ–ฅ์ƒ: .env, .git ๋“ฑ ๋ฏผ๊ฐํ•œ ์ •๋ณด๊ฐ€ ํฌํ•จ๋  ์ˆ˜ ์žˆ๋Š” ์ˆจ๊น€ ํŒŒ์ผ(.์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ชจ๋“  ํ•ญ๋ชฉ)์„ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋…ธ์ถœํ•˜์ง€ ์•Š๋„๋ก ์ œ์™ธ (์ •๋ณด ๋…ธ์ถœ ๋ฐฉ์ง€)
(dirFilesNames ?: curr_dir.list())?.forEach {
if (it.startsWith(".")) {
if (it.isHiddenFile()) {
files_to_exclude.add(it)
}
}
Expand Down Expand Up @@ -357,7 +363,7 @@ fun process_dir(curr_dir: File, excludeSet: Set<String>? = null, dirFiles: Array
val fileName = it.getName()
// โšก Bolt Performance Optimization: Short-circuit string match before expensive OS filesystem calls
// ๐Ÿ›ก๏ธ Sentinel: Ignore hidden files/directories to prevent sensitive data exposure
if (!fileName.startsWith(".") && fileName !in exclude) {
if (!fileName.isHiddenFile() && fileName !in exclude) {
var isLinkedDirectory = false
var isSymbolicLink = false
try {
Expand Down
24 changes: 24 additions & 0 deletions src/test/kotlin/html4tree/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,28 @@ class MainTest {
assertFalse(processed, "fileKey mismatch should skip directory processing")
assertFalse(listed, "fileKey mismatch should skip child listing")
}

@Test
fun testIsHiddenFile() {
assertTrue(".env".isHiddenFile())
assertTrue("\u3002env".isHiddenFile())
assertTrue("\uFF0Egit".isHiddenFile())
assertTrue("\uFF61ssh".isHiddenFile())
assertFalse("test.txt".isHiddenFile())
assertFalse("".isHiddenFile())
}

@Test
fun testProcessIgnoreFileHomoglyphs() {
File(tempDir, "\u3002myhidden").createNewFile()
File(tempDir, "\uFF0Ehiddendir").mkdir()
File(tempDir, "\uFF61env").createNewFile()
File(tempDir, "test2.txt").createNewFile()

val excluded = process_ignore_file(tempDir)
assertTrue(excluded.contains("\u3002myhidden"))
assertTrue(excluded.contains("\uFF0Ehiddendir"))
assertTrue(excluded.contains("\uFF61env"))
assertFalse(excluded.contains("test2.txt"))
}
}
Loading