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-15 - [CRITICAL] μˆ¨κΉ€ 파일 μœ λ‹ˆμ½”λ“œ 우회 취약점 λ°©μ§€
**Vulnerability:** 파일 이름 검증 μ‹œ μœ λ‹ˆμ½”λ“œ μœ μ‚¬ 문자λ₯Ό ν†΅ν•œ μˆ¨κΉ€ 파일 우회 (Information Exposure)
**Learning:** `startsWith(".")` λ°©μ‹λ§ŒμœΌλ‘œλŠ” μœ λ‹ˆμ½”λ“œμ˜ λ‹€λ₯Έ ν˜•νƒœ 점 문자(예: `\u3002`, `\uFF0E`, `\uFF61`)둜 μ‘°μž‘λœ μ•…μ˜μ μΈ 파일이 필터링을 μš°νšŒν•˜μ—¬ λ…ΈμΆœλ  수 μžˆμŒμ„ λ°°μ› μŠ΅λ‹ˆλ‹€.
**Prevention:** 파일 필터링 λ‘œμ§μ—μ„œ μœ λ‹ˆμ½”λ“œ λ“±κ°€ 문자λ₯Ό ν•¨κ»˜ μ²˜λ¦¬ν•˜λŠ” μΌκ΄€λœ μœ ν‹Έλ¦¬ν‹° ν•¨μˆ˜(`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 @@ -108,6 +108,12 @@ internal fun read_file_identity(file: File): FileIdentity {
}
}

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

fun go(topDir: String, maxLevel: Int) {
require(topDir.isNotBlank())
require(!topDir.contains("..")) { "Path traversal sequences are not allowed." }
Expand Down Expand Up @@ -165,7 +171,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 @@ -292,7 +298,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 @@ -346,7 +352,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
10 changes: 10 additions & 0 deletions src/test/kotlin/html4tree/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,14 @@ 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("\uFF0Eenv".isHiddenFile())
assertTrue("\uFF61env".isHiddenFile())
assertFalse("env".isHiddenFile())
assertFalse("".isHiddenFile())
}
}
Loading