Skip to content
Closed
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-08-08 - [html4tree] μœ λ‹ˆμ½”λ“œ 호λͺ¨κΈ€λ¦¬ν”„(Homoglyph)λ₯Ό μ΄μš©ν•œ μˆ¨κΉ€ 파일 필터링 우회 λ°©μ§€
**Vulnerability:** μœ λ‹ˆμ½”λ“œμ˜ 점(dot) λ³€ν˜• 문자(예: U+3002, U+FF0E, U+FF61)λ₯Ό μ‚¬μš©ν•˜μ—¬ μˆ¨κΉ€ 파일 검사(startsWith("."))λ₯Ό μš°νšŒν•˜κ³ , λ―Όκ°ν•œ λ””λ ‰ν† λ¦¬λ‚˜ νŒŒμΌμ„ μΈλ±μŠ€μ— λ…ΈμΆœμ‹œν‚€λŠ” λ³΄μ•ˆ ν•„ν„° 우회(Bypass) 취약점.
**Learning:** μˆ¨κΉ€ νŒŒμΌμ„ κ±ΈλŸ¬λ‚΄κΈ° μœ„ν•΄ λ‹¨μˆœν•˜κ²Œ 점(.)으둜 μ‹œμž‘ν•˜λŠ”μ§€λ§Œ 검사할 경우, κ³΅κ²©μžκ°€ 점과 μ‹œκ°μ  및 의미적으둜 μœ μ‚¬ν•œ μœ λ‹ˆμ½”λ“œ 호λͺ¨κΈ€λ¦¬ν”„ 문자λ₯Ό μ‚¬μš©ν•˜μ—¬ 검사λ₯Ό μš°νšŒν•  수 μžˆμŠ΅λ‹ˆλ‹€.
**Prevention:** 파일 이름 기반의 필터링을 κ΅¬ν˜„ν•  λ•Œ, 일반적인 ASCII 점(.) 뿐만 μ•„λ‹ˆλΌ μ•…μš© κ°€λŠ₯ν•œ μœ λ‹ˆμ½”λ“œ 호λͺ¨κΈ€λ¦¬ν”„ 점(dot) λ³€ν˜• λ¬Έμžλ“€λ„ ν•¨κ»˜ κ²€μ‚¬ν•˜λŠ” κ°•λ ₯ν•œ 필터링 ν•¨μˆ˜(예: isHiddenFile)λ₯Ό μ‚¬μš©ν•˜μ—¬ 우회λ₯Ό λ°©μ§€ν•˜μ‹­μ‹œμ˜€.
12 changes: 9 additions & 3 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.types.int

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

private val CSS_CONTENT = """
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
Expand Down Expand Up @@ -176,7 +182,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 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
5 changes: 5 additions & 0 deletions src/test/kotlin/html4tree/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,9 @@ class MainTest {
assertFalse(processed, "fileKey mismatch should skip directory processing")
assertFalse(listed, "fileKey mismatch should skip child listing")
}

@Test
fun testIsHiddenFileEmptyString() {
assertFalse("".isHiddenFile())
}
}
Loading