๐ก๏ธ Sentinel: [HIGH] ์ธ๋ผ์ธ ์คํ์ผ CSP ํด์ ๊ณ์ฐ ์ค๋ฅ ์์ #241
๐ก๏ธ Sentinel: [HIGH] ์ธ๋ผ์ธ ์คํ์ผ CSP ํด์ ๊ณ์ฐ ์ค๋ฅ ์์ #241seonghobae wants to merge 1 commit into
Conversation
- `cssContent`์ `.trimIndent()`๋ฅผ ์ ์ฉํ์ฌ ์ ํ/ํํ ๊ณต๋ฐฑ์ ์ ๊ฑฐํจ
- HTML ํ
ํ๋ฆฟ์ `cssContent`๋ฅผ ์ฃผ์
ํ ๋ `<style>` ํ๊ทธ ๋ด์ ๋ถํ์ํ ์ค๋ฐ๊ฟ์ด๋ ๊ณต๋ฐฑ์ด ํฌํจ๋์ง ์๋๋ก `<style>${cssContent}</style>` ํ์์ผ๋ก ์์ ํจ
- CSP ํด์ ๊ณ์ฐ ์ `cssContent.toByteArray()`๊ฐ ๋ธ๋ผ์ฐ์ ๊ฐ ์ธ์ํ๋ ์ค์ ์ธ๋ผ์ธ ์คํ์ผ ๋ฌธ์์ด๊ณผ ์ ํํ ์ผ์นํ๊ฒ ๋จ
- CSP ํด์ ๊ณ์ฐ ๋ฐ ๊ฒ์ฆ์ ์ํ ๋จ์ ํ
์คํธ(`CspTest.kt`) ์ถ๊ฐ
|
๐ Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a ๐ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Fixes CSP sha256 hash mismatches for inline <style> blocks by normalizing the hashed content and ensuring the injected HTML matches the hashed bytes exactly.
Changes:
- Normalize
cssContentwith.trimIndent()before hashing. - Inject
<style>content without additional newlines/indentation to keep browser hash input identical. - Add a unit test validating the style hash matches the injected style content.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/kotlin/html4tree/main.kt | Aligns CSP hash input with actual <style> inner text by trimming indentation and injecting without padding. |
| src/test/kotlin/html4tree/CspTest.kt | Adds a regression test to validate hash equality between computed content and injected style content. |
| .jules/sentinel.md | Documents the vulnerability, learning, and prevention guidance for CSP hash calculation. |
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val css = "<style>${cssContent}</style>" | ||
| val insideStyle = css.substringAfter("<style>").substringBefore("</style>") | ||
| val styleHash2 = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(insideStyle.toByteArray(Charsets.UTF_8))) | ||
|
|
||
| assertTrue(styleHash == styleHash2, "The CSP hash must exactly match the injected inline style content.") |
| val insideStyle = css.substringAfter("<style>").substringBefore("</style>") | ||
| val styleHash2 = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(insideStyle.toByteArray(Charsets.UTF_8))) | ||
|
|
||
| assertTrue(styleHash == styleHash2, "The CSP hash must exactly match the injected inline style content.") |
๐จ Severity: HIGH
๐ก Vulnerability: CSP(Content-Security-Policy) ์ค์ ์์ ์ธ๋ผ์ธ
<style>ํ๊ทธ์ ๋ํsha256ํด์ ๊ณ์ฐ ์, Kotlin ๋ค์ค ์ค ๋ฌธ์์ด(""")์ ๋ค์ฌ์ฐ๊ธฐ ๊ณต๋ฐฑ์ด ํฌํจ๋ ์ํ๋ก ํด์๋ฅผ ๊ณ์ฐํจ. ํ์ง๋ง HTML ํ ํ๋ฆฟ์ ์ฃผ์ ๋ ๋<style>\n${cssContent}</style>์ ๊ฐ์ด ์ค๋ฐ๊ฟ์ด ์ถ๊ฐ๋์ด ๋ธ๋ผ์ฐ์ ๊ฐ ์ธ์ํ๋ ์ค์ ๋ด์ฉ๊ณผ ํด์๊ฐ ๋ถ์ผ์นํ๊ฒ ๋จ. ์ด๋ก ์ธํด ๋ธ๋ผ์ฐ์ ๊ฐ ์ธ๋ผ์ธ ์คํ์ผ์ ์ฐจ๋จํ์ฌ ์คํ์ผ์ด ์ ์ฉ๋์ง ์๋ ๋ฌธ์ (๋ณด์ ์ ์ฑ ์ ์ฉ ์ค๋ฅ)๊ฐ ๋ฐ์ํ ์ ์์.๐ฏ Impact: ์๋ชป๋ CSP ํด์๋ก ์ธํด ๋ธ๋ผ์ฐ์ ์์ ์ธ๋ผ์ธ ์คํ์ผ์ด ์ฐจ๋จ๋์ด UI๊ฐ ๊นจ์ง๊ฑฐ๋, ์ด ๋ฌธ์ ๋ฅผ ์ฐํํ๊ธฐ ์ํด ๊ฐ๋ฐ์๊ฐ CSP ์ค์ (์:
unsafe-inline)์ ์ฝํ์ํฌ ์ํ์ด ์์.๐ง Fix:
cssContent์.trimIndent()๋ฅผ ์ ์ฉํ์ฌ ๋ค์ฌ์ฐ๊ธฐ ๊ณต๋ฐฑ์ ์ ๊ฑฐํ๊ณ , HTML ์ฃผ์ ์<style>${cssContent}</style>์ ๊ฐ์ด ๊ณต๋ฐฑ ์์ด ์ฃผ์ ํ์ฌ ํด์ ๊ณ์ฐ ๋์๊ณผ ๋ธ๋ผ์ฐ์ ๊ฐ ์ธ์ํ๋ ๋์์ด ์ ํํ ์ผ์นํ๋๋ก ์์ ํจ. ์ถ๊ฐ๋ก, ์ด๋ฅผ ๊ฒ์ฆํ๋CspTest.kt๋จ์ ํ ์คํธ๋ฅผ ์์ฑํจ.โ Verification:
CspTest.ktํ ์คํธ ๋ฐ./gradlew clean test jacocoTestReport jacocoTestCoverageVerification --continue์คํ ์ ๋ชจ๋ ํ ์คํธ ํต๊ณผ ๋ฐ 100% ์ฝ๋ ์ปค๋ฒ๋ฆฌ์ง ํ์ธ๋จ.PR created automatically by Jules for task 14987291479219800480 started by @seonghobae