๐ก๏ธ Sentinel: [MEDIUM] CSP Hash ์ ์ฉ ๋ฐฉ์ ๋ณด์ ๊ฐํ - #274
๐ก๏ธ Sentinel: [MEDIUM] CSP Hash ์ ์ฉ ๋ฐฉ์ ๋ณด์ ๊ฐํ#274seonghobae wants to merge 1 commit into
Conversation
|
๐ 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
This PR hardens html4treeโs generated index.html Content Security Policy (CSP) by ensuring the style-src SHA-256 hash is computed from the exact inline <style> content that is emitted into the HTML, preventing browser style blocking and avoiding hash/markup mismatches.
Changes:
- Normalize the CSS multiline string with
trimIndent()and compute the CSPsha256-...hash from that normalized value. - Emit the
<style>tag as a single string (<style>${content}</style>) to avoid template-introduced whitespace differences. - Document the CSP hash mismatch lesson/prevention guidance in the Jules Sentinel log.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/kotlin/html4tree/main.kt | Aligns CSP hash input with emitted <style> text by normalizing and injecting the exact same string. |
| .jules/sentinel.md | Records the security learning/prevention note related to CSP hash mismatches from multiline string injection. |
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val exactStyleContent = cssContent.trimIndent() | ||
| val styleHash = "sha256-" + Base64.getEncoder().encodeToString(MessageDigest.getInstance("SHA-256").digest(exactStyleContent.toByteArray(Charsets.UTF_8))) | ||
|
|
||
| val css = """ | ||
| <style> | ||
| ${cssContent} </style> | ||
| """ | ||
| val css = "<style>${exactStyleContent}</style>" |
| **Learning:** Kotlin์์ ๋ค์ค ์ค ๋ฌธ์์ด(multiline string)๋ก ๊ตฌ์ฑ๋ ์ฝํ ์ธ (์: CSS)๋ฅผ HTML ํ ํ๋ฆฟ์ `<style>` ํ๊ทธ์ ๊ฒฐํฉํ ๋, ์ ์์ ์ฝ์ ๋ ๊ณต๋ฐฑ๊ณผ ์ค๋ฐ๊ฟ์ CSP ํด์ ์ฐ์ฐ ์ ์ ์ธ๋์ง๋ง ์ค์ ๋ธ๋ผ์ฐ์ ๊ฐ ํ์ฑํ๋ ํ ์คํธ์๋ ํฌํจ๋์ด ํด์ ๋ถ์ผ์น๋ฅผ ์ผ๊ธฐํฉ๋๋ค. | ||
| **Prevention:** ํ ํ๋ฆฟ์ ์ฝ์ ํ ์ฝํ ์ธ ์๋ ํญ์ `.trimIndent()`๋ฅผ ์ ์ฉํ์ฌ ์ ํ/ํํ ๊ณต๋ฐฑ ๋ฐ ์ค๋ฐ๊ฟ์ ์๋ฒฝํ ์ ๊ฑฐํ๊ณ , ์ฃผ์ ์ `<style>${content}</style>`์ ๊ฐ์ด ์ถ๊ฐ ๊ณต๋ฐฑ ์์ด ๊ฒฐํฉํ์ฌ ํด์์ ์๋ณธ ์ฝํ ์ธ ์ ๋ธ๋ผ์ฐ์ ๊ฐ ๋ณด๋ ํ ์คํธ๋ฅผ ์ ํํ๊ฒ ๋๊ธฐํํด์ผ ํฉ๋๋ค. |
|
Closing as superseded by canonical #363. Both repair the inline-style CSP hash mismatch, but #363 additionally verifies the exact emitted UTF-8 style bytes from a real generated page, hoists the immutable source and hash, adds APA 7 doctoring and changelog, and has fresh current-head CI/JaCoCo/Security/Semgrep evidence. No result from this duplicate head is reused. |
Understood. Acknowledging that this work is now obsolete and superseded by canonical #363, and stopping work on this task. |
๐จ Severity: MEDIUM
๐ก Vulnerability: ์ ์ ๋ฆฌ์์ค์ฉ CSP ์์ฑ ์ ํด์ ๋ถ์ผ์น
๐ฏ Impact: ๋ธ๋ผ์ฐ์ ๊ฐ ์คํ์ผ์ ์ฐจ๋จํ์ฌ ํ๋ฉด์ด ๊นจ์ง๊ฑฐ๋ CSP ์ฐํ๊ฐ ๊ฐ๋ฅํด์ง
๐ง Fix:
<style>ํ๊ทธ ๋ด๋ถ ๋ด์ฉ์ ์ ํํ๊ฒ ๋ง์ถ๊ธฐ ์ํด trimIndent()๋ฅผ ์ฌ์ฉํ๊ณ ๊ณต๋ฐฑ ์์ด ์ฃผ์ ํจโ Verification: ./gradlew test ํต๊ณผ ๋ฐ ์์ฑ๋ HTML ๋ด์ ์คํ์ผ๊ณผ ํด์๊ฐ ์ ํํ ์ผ์นํจ
PR created automatically by Jules for task 12596847652619187529 started by @seonghobae