-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [보μ κ°μ ] #586
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
Changes from all commits
e9c847f
1b99f7c
f5684d9
0d9bac6
be7655a
52e6b0e
3a1ebe7
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 |
|---|---|---|
|
|
@@ -309,18 +309,22 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S | |
| if(ignore_file.isFile && !Files.isSymbolicLink(ignore_file.toPath()) && ignore_file.canRead() && ignore_file.length() <= 1048576){ | ||
| val ignored_matchers = mutableListOf<java.nio.file.PathMatcher>() | ||
|
|
||
| ignore_file.useLines { lines -> | ||
| for ((lineIndex, it) in lines.withIndex()) { | ||
| // μ€ μ μ νμ΄ ν¨ν΄ μλ ν¨κ» μν(μ€λΉ μ΅λ 1κ° ν¨ν΄)νλ―λ‘ λ³λ ν¨ν΄ μΉ΄μ΄ν°λ λΆνμ | ||
| if (lineIndex >= 1000) break | ||
| val pattern = it.trim() | ||
| if (pattern.isNotEmpty() && pattern.length <= 100) { | ||
| try { | ||
| ignored_matchers.add(java.nio.file.FileSystems.getDefault().getPathMatcher("glob:$pattern")) | ||
| } catch (_: IllegalArgumentException) { | ||
| try { | ||
| ignore_file.useLines { lines -> | ||
| for ((lineIndex, it) in lines.withIndex()) { | ||
| // μ€ μ μ νμ΄ ν¨ν΄ μλ ν¨κ» μν(μ€λΉ μ΅λ 1κ° ν¨ν΄)νλ―λ‘ λ³λ ν¨ν΄ μΉ΄μ΄ν°λ λΆνμ | ||
| if (lineIndex >= 1000) break | ||
| val pattern = it.trim() | ||
| if (pattern.isNotEmpty() && pattern.length <= 100) { | ||
| try { | ||
| ignored_matchers.add(java.nio.file.FileSystems.getDefault().getPathMatcher("glob:$pattern")) | ||
| } catch (_: IllegalArgumentException) { | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } catch (_: Exception) { | ||
|
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. |
||
| // 보μ: TOCTOU νμΌ μ κ·Ό κ±°λΆ/μμ μμΈ μ ν¬λμ(DoS) λ°©μ§ λ° μμ νκ² λ¬΄μ (Fail Securely) | ||
| } | ||
|
|
||
| // β‘ Bolt Performance Optimization: λλ ν 리 λͺ©λ‘μ Setμ μΆκ°νκΈ° μν΄ νν°λ§λ§ ν λλ μ λ ¬μ΄ λΆνμνλ―λ‘ .sorted()λ₯Ό μ κ±°νμ¬ O(N log N) μ€λ²ν€λλ₯Ό λ°©μ§ν©λλ€. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package html4tree | ||
|
|
||
| import org.junit.Test | ||
| import java.io.File | ||
| import kotlin.test.assertTrue | ||
| import kotlin.concurrent.thread | ||
| import java.nio.file.Files | ||
|
|
||
| class ToctouTest { | ||
| @Test | ||
| fun testProcessIgnoreFileToctouExceptionRace() { | ||
| val tempDir = Files.createTempDirectory("toctoutest").toFile() | ||
| val ignoreFile = File(tempDir, ".html4ignore") | ||
|
|
||
| var excluded: Set<String>? = null | ||
| for (i in 0..2000) { | ||
|
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. |
||
| ignoreFile.writeText("test.txt") | ||
| val t = thread { ignoreFile.delete() } | ||
| excluded = process_ignore_file(tempDir, null) | ||
|
Comment on lines
+18
to
+19
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. π― Functional Correctness | π‘ Minor | β‘ Quick win
μμ μ€λ λμλ
As per coding guidelines, βAny new Kotlin code or branch must have covering tests because JaCoCo enforces 100% coverage through π Affects 1 file
π€ Prompt for AI AgentsSource: Coding guidelines |
||
| t.join() | ||
| } | ||
| assertTrue(excluded?.contains("index.html") ?: false) | ||
| } | ||
|
|
||
| @Test | ||
| fun testProcessIgnoreFileToctouException() { | ||
| val tempDir = Files.createTempDirectory("toctoutest2").toFile() | ||
| val ignoreFile = File(tempDir, ".html4ignore") | ||
| ignoreFile.writeText("test.txt") | ||
|
|
||
| // Force an IOException during useLines | ||
| val method = java.io.File::class.java.getDeclaredMethod("setReadable", Boolean::class.java) | ||
| method.isAccessible = true | ||
| method.invoke(ignoreFile, false) | ||
| val excluded = process_ignore_file(tempDir, null) | ||
| assertTrue(excluded.contains("index.html")) | ||
|
Comment on lines
+35
to
+36
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. |
||
| } | ||
| } | ||
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.
π Security & Privacy | π Major | ποΈ Heavy lift
Denial of Service (CWE-59)
Reachability: External Β· Exploitability: Moderate
.html4ignoreλ₯Ό no-follow λ°©μμΌλ‘ μ½μΌμμμ€.isFile,isSymbolicLink,canRead,length()κ²μ¬λuseLinesνΈμΆκ³Ό μμμ μ΄μ§ μμ΅λλ€. κ²μ¬ ν νμΌμ FIFO λλ λ€λ₯Έ μ¬λ³Όλ¦ λ§ν¬λ‘ κ΅μ²΄νλ©΄useLinesκ° μ λμμ λ°λΌ μ΄μ΄ ν¬λ‘€λ§μ λΈλ‘νΉνκ±°λ 1MB μ νμ μ°νν μ μμ΅λλ€. νμΌ μ΄κΈ° μNOFOLLOW_LINKSλ₯Ό μ μ©νκ³ , μ΄λ¦° νμΌ κΈ°μ€μΌλ‘ μΌλ° νμΌ μ¬λΆμ μ€μ μ½κΈ° λ°μ΄νΈλ₯Ό μ ννμμμ€. μ΄ κ²½μ 쑰건μ λν νκ· ν μ€νΈλ μΆκ°νμμμ€.π€ Prompt for AI Agents
Source: Coding guidelines