-
Notifications
You must be signed in to change notification settings - Fork 0
security: fail closed when declared ignore policy cannot be read #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
fedbe6e
1fb5921
466c214
41f89a1
e1aab93
043f0a2
69d1c38
19a07bb
c7af731
8f522b9
b78eb41
4454de7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,8 @@ li + li { | |
| private val STYLE_HASH = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(CSS_CONTENT.toByteArray(Charsets.UTF_8))) | ||
| private val FILE_NAME_COMPARATOR = compareBy<File> { it.name } | ||
|
|
||
| class IgnoreFileReadException(message: String) : java.io.IOException(message) | ||
|
|
||
| class Html4tree : CliktCommand() { | ||
| val maxLevel:Int by option(help="Number of levels deep for which to generate an index.html file", hidden = false).int().default(-1) | ||
| val topDir: String by argument(help="Top directory to crawl") | ||
|
|
@@ -200,7 +202,12 @@ internal fun crawl_directories( | |
| val dirFilesNames = dirFiles?.let { files -> | ||
| Array(files.size) { index -> files[index].name } | ||
| } | ||
| val exclude = processIgnoreFile(lle.file, dirFilesNames) | ||
| val exclude = try { | ||
| processIgnoreFile(lle.file, dirFilesNames) | ||
| } catch (e: IgnoreFileReadException) { | ||
| lle = ll.pull() | ||
| continue | ||
| } | ||
|
|
||
| if(maxLevel == -1 || currentLevel <= maxLevel) | ||
| processDirectory(lle.file, exclude, dirFiles) | ||
|
|
@@ -303,6 +310,14 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S | |
|
|
||
| val files_to_exclude = mutableSetOf<String>() | ||
|
|
||
| val list = dirFilesNames ?: curr_dir.list() | ||
|
|
||
| if (list?.contains(ignore_filename) == true) { | ||
| if (!ignore_file.isFile || Files.isSymbolicLink(ignore_file.toPath()) || !ignore_file.canRead()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- src/main/kotlin/html4tree/main.kt:100-220 ---'
sed -n '100,220p' src/main/kotlin/html4tree/main.kt
printf '%s\n' '--- src/main/kotlin/html4tree/main.kt:300-385 ---'
sed -n '300,385p' src/main/kotlin/html4tree/main.kt
printf '%s\n' '--- relevant tests ---'
sed -n '730,785p' src/test/kotlin/html4tree/MainTest.kt
sed -n '890,940p' src/test/kotlin/html4tree/MainTest.ktRepository: ContextualWisdomLab/html4tree Length of output: 11914 🤖 get_repo_knowledge executed:
Length of output: 3701 🏁 Script executed: #!/bin/bash
set -eu
sed -n '100,220p' src/main/kotlin/html4tree/main.kt
sed -n '300,385p' src/main/kotlin/html4tree/main.kt
sed -n '730,785p' src/test/kotlin/html4tree/MainTest.kt
sed -n '890,940p' src/test/kotlin/html4tree/MainTest.ktRepository: ContextualWisdomLab/html4tree Length of output: 11791 Other (CWE-367): Time-of-check Time-of-use (TOCTOU) Race Condition Reachability: External · Exploitability: Moderate 정책 파일 검증과 읽기를 하나의 no-follow 작업으로 결합하십시오. 현재 파일 상태 검증과 no-follow 방식으로 파일을 열고, 열린 파일의 유형과 크기를 검증하십시오. 모든 읽기 실패를 🤖 Prompt for AI Agents |
||
| throw IgnoreFileReadException("Policy file $ignore_filename is present in directory snapshot but inaccessible or invalid") | ||
|
Comment on lines
+315
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- main.kt: crawl and ignore-file handling ---'
sed -n '130,225p;295,385p' src/main/kotlin/html4tree/main.kt
printf '%s\n' '--- MainTest.kt: ignore-file size tests ---'
sed -n '700,815p' src/test/kotlin/html4tree/MainTest.ktRepository: ContextualWisdomLab/html4tree Length of output: 11738 Information Disclosure (CWE-200): Exposure of Sensitive Information to an Unauthorized Actor Reachability: External · Exploitability: Moderate 1 MB를 초과한 정책 파일을 fail-closed로 처리하십시오. 현재 파일 크기 제한은 파싱만 건너뛰게 합니다. 따라서 정책의 제외 규칙이 적용되지 않고, 보호 대상 파일이 인덱스에 노출될 수 있습니다. 파일 크기 검사를 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| // 보안 향상: .html4ignore 파일이 일반 파일인지 확인하고, 심볼릭 링크인 경우 무시하여 DoS 및 경로 조작을 방지합니다. | ||
| // 보안 향상: 파일 크기(1MB 제한) 및 줄 수(1000줄), 정규식 길이(100자)를 제한하여 ReDoS 및 메모리 고갈(OOM) 방지 | ||
| // 보안 향상: 권한이 없는 파일 접근 시 발생하는 예외(DoS)를 방지하기 위해 canRead() 추가 확인 | ||
|
|
@@ -324,7 +339,6 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S | |
| } | ||
|
|
||
| // ⚡ Bolt Performance Optimization: 디렉토리 목록을 Set에 추가하기 위해 필터링만 할 때는 정렬이 불필요하므로 .sorted()를 제거하여 O(N log N) 오버헤드를 방지합니다. | ||
| val list = dirFilesNames ?: curr_dir.list() | ||
| list?.forEach { | ||
| val current = it | ||
| val pathCurrent = try { | ||
|
|
@@ -350,7 +364,7 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S | |
| files_to_exclude.addAll(Constants.defaultSensitiveFiles) | ||
|
|
||
| // 보안 향상: dot-like prefixes and case variants of known sensitive names are excluded. | ||
| (dirFilesNames ?: curr_dir.list())?.forEach { | ||
| list?.forEach { | ||
| val normalizedName = it.toLowerCase(java.util.Locale.ROOT) | ||
| if ( | ||
| it.isHiddenFile() || | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
IgnoreFileReadExceptioncatch 분기를 JUnit 4 테스트로 실행하십시오.현재 변경된 테스트는
process_ignore_file의 직접 예외만 확인합니다.crawl_directories에서processIgnoreFile이IgnoreFileReadException을 던질 때processDirectory와 하위 항목 enqueue가 실행되지 않는 테스트를 추가하십시오. 이 catch 분기는 현재 제공된 테스트에서 실행되지 않습니다.As per coding guidelines, "Any new Kotlin code or branch must have covering tests because JaCoCo enforces 100% coverage through
check."🧰 Tools
🪛 detekt (1.23.8)
[warning] 207-207: The caught exception is swallowed. The original exception could be lost.
(detekt.exceptions.SwallowedException)
🤖 Prompt for AI Agents
Source: Coding guidelines