-
Notifications
You must be signed in to change notification settings - Fork 0
๐ก๏ธ Sentinel: [HIGH] Fix TOCTOU vulnerability in useLines #605
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
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 |
|---|---|---|
|
|
@@ -306,21 +306,25 @@ fun process_ignore_file(curr_dir: File, dirFilesNames: Array<String>? = null): S | |
| // ๋ณด์ ํฅ์: .html4ignore ํ์ผ์ด ์ผ๋ฐ ํ์ผ์ธ์ง ํ์ธํ๊ณ , ์ฌ๋ณผ๋ฆญ ๋งํฌ์ธ ๊ฒฝ์ฐ ๋ฌด์ํ์ฌ DoS ๋ฐ ๊ฒฝ๋ก ์กฐ์์ ๋ฐฉ์งํฉ๋๋ค. | ||
| // ๋ณด์ ํฅ์: ํ์ผ ํฌ๊ธฐ(1MB ์ ํ) ๋ฐ ์ค ์(1000์ค), ์ ๊ท์ ๊ธธ์ด(100์)๋ฅผ ์ ํํ์ฌ ReDoS ๋ฐ ๋ฉ๋ชจ๋ฆฌ ๊ณ ๊ฐ(OOM) ๋ฐฉ์ง | ||
| // ๋ณด์ ํฅ์: ๊ถํ์ด ์๋ ํ์ผ ์ ๊ทผ ์ ๋ฐ์ํ๋ ์์ธ(DoS)๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด canRead() ์ถ๊ฐ ํ์ธ | ||
| if(ignore_file.isFile && !Files.isSymbolicLink(ignore_file.toPath()) && ignore_file.canRead() && ignore_file.length() <= 1048576){ | ||
| if(ignore_file.isFile && 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 { | ||
| java.nio.file.Files.newInputStream(ignore_file.toPath(), java.nio.file.StandardOpenOption.READ, java.nio.file.LinkOption.NOFOLLOW_LINKS).bufferedReader().useLines { lines -> | ||
|
Comment on lines
+309
to
+313
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 | ๐๏ธ Heavy lift ๐งฉ Analysis chain๐ Script executed: #!/bin/bash
set -eu
sed -n '285,350p' src/main/kotlin/html4tree/main.kt
printf '\n-- relevant tests --\n'
sed -n '250,300p' src/test/kotlin/html4tree/MainTest.ktRepository: ContextualWisdomLab/html4tree Length of output: 4887 Denial of Service (CWE-400): Uncontrolled Resource Consumption Reachability: External ยท Exploitability: Moderate ์ด๋ฆฐ ์คํธ๋ฆผ์๋ 1MB ์ํ์ ์ ์ฉํ์ธ์.
๐ค Prompt for AI AgentsSource: MCP tools |
||
| 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) { | ||
| // ํ์ผ์ด ์ฝ๋ ๋์ค ์ญ์ ๋๊ฑฐ๋ ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ก ๊ต์ฒด๋ ๊ฒฝ์ฐ ๋ฌด์ํฉ๋๋ค. | ||
|
Comment on lines
+312
to
+327
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. ๐ Maintainability & Code Quality | ๐ Major | โก Quick win ์ ์ฝ๊ธฐ ์คํจ ๋ถ๊ธฐ๋ฅผ ํ ์คํธ๋ก ์ปค๋ฒํ์ธ์. ํ์ฌ ํ
์คํธ ์ปจํ
์คํธ๋ ์ผ๋ฐ As per coding guidelines: ์ Kotlin ์ฝ๋์ ๋ถ๊ธฐ์๋ ์ปค๋ฒ๋ฆฌ์ง ํ ์คํธ๊ฐ ํ์ํฉ๋๋ค. ๐ค Prompt for AI AgentsSource: Coding guidelines |
||
| } | ||
|
|
||
| // โก Bolt Performance Optimization: ๋๋ ํ ๋ฆฌ ๋ชฉ๋ก์ Set์ ์ถ๊ฐํ๊ธฐ ์ํด ํํฐ๋ง๋ง ํ ๋๋ ์ ๋ ฌ์ด ๋ถํ์ํ๋ฏ๋ก .sorted()๋ฅผ ์ ๊ฑฐํ์ฌ O(N log N) ์ค๋ฒํค๋๋ฅผ ๋ฐฉ์งํฉ๋๋ค. | ||
|
|
||
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
๐ Supported by static analysis
๐ Script executed:
Repository: ContextualWisdomLab/html4tree
Length of output: 29381
์ฌ์ ๊ฒ์ฌ์์๋ ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ฐ๋ฅด์ง ์๋๋ก ๋ณ๊ฒฝํ์ธ์.
ignore_file.isFile,canRead(),length()๋ ์ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ฐ๋ฅผ ์ ์์ต๋๋ค.Files.readAttributes(..., LinkOption.NOFOLLOW_LINKS)๋ก regular-file ์ฌ๋ถ์ ํฌ๊ธฐ๋ฅผ ํ์ธํ๊ณ , ์ต์ขFiles.newInputStream์NOFOLLOW_LINKS์ต์ ์ ์ ์งํ์ธ์.๐ค Prompt for AI Agents
Sources: Coding guidelines, MCP tools