Skip to content

πŸ›‘οΈ Sentinel: [security improvement] CSP Trusted Types μ •μ±… 및 DOMPurify μ†Œλ… μΆ”κ°€#42

Open
seonghobae wants to merge 1 commit into
mainfrom
sentinel/csp-trusted-types-1006353573105115304
Open

πŸ›‘οΈ Sentinel: [security improvement] CSP Trusted Types μ •μ±… 및 DOMPurify μ†Œλ… μΆ”κ°€#42
seonghobae wants to merge 1 commit into
mainfrom
sentinel/csp-trusted-types-1006353573105115304

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

🚨 Severity: HIGH
πŸ’‘ Vulnerability: μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ— Trusted Types 정책이 κ°•μ œλ˜μ§€ μ•Šμ•„, μΆ”ν›„ DOM sink(예: innerHTML)에 μ‹ λ’°ν•  수 μ—†λŠ” 데이터가 할당될 경우 DOM 기반 XSS 곡격에 λ…ΈμΆœλ  μœ„ν—˜μ΄ μ‘΄μž¬ν–ˆμŠ΅λ‹ˆλ‹€.
🎯 Impact: κ³΅κ²©μžκ°€ μ•…μ„± 슀크립트λ₯Ό μ£Όμž…ν•˜μ—¬ μ‚¬μš©μž λΈŒλΌμš°μ €μ—μ„œ μž„μ˜μ˜ μ½”λ“œλ₯Ό μ‹€ν–‰ν•˜κ±°λ‚˜ μ„Έμ…˜μ„ νƒˆμ·¨ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
πŸ”§ Fix: index.html의 CSP 섀정에 require-trusted-types-for 'script' μ§€μ‹œμ–΄λ₯Ό μΆ”κ°€ν•˜κ³ , ν™•λ¦½λœ λ³΄μ•ˆ 라이브러리인 DOMPurifyλ₯Ό μ‚¬μš©ν•΄ μž…λ ₯을 μ•ˆμ „ν•˜κ²Œ μ†Œλ…ν•˜λŠ” κΈ°λ³Έ(default) Trusted Types 정책을 security.js에 λ“±λ‘ν–ˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό 톡해 DOM sink에 λ¬Έμžμ—΄μ΄ 할당될 λ•Œ μžλ™μœΌλ‘œ μ•ˆμ „ν•œ TrustedHTML둜 λ³€ν™˜λ˜λ„λ‘ ν•˜μ—¬ XSSλ₯Ό λ°©μ–΄ν•˜κ³  ν¬λ‘œλ―Έμ›€ 기반 λΈŒλΌμš°μ €μ—μ„œμ˜ μΆ©λŒμ„ μ˜ˆλ°©ν–ˆμŠ΅λ‹ˆλ‹€.
βœ… Verification: κΈ°μ‘΄ i18n ν…ŒμŠ€νŠΈ μŠ€ν¬λ¦½νŠΈμ™€ λ™μΌν•œ ν™˜κ²½μ—μ„œ 둜컬 Playwright 슀크립트λ₯Ό 톡해 μ•±μ˜ 정상 λ‘œλ”©κ³Ό ν…ŒμŠ€νŠΈ 톡과λ₯Ό ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€. λΈŒλΌμš°μ € μ½˜μ†”μ—μ„œ Trusted Types μ •μ±… μœ„λ°˜ 였λ₯˜λ‚˜ DOMPurify둜 μΈν•œ 좩돌이 λ°œμƒν•˜μ§€ μ•ŠμŒμ„ κ²€μ¦ν–ˆμŠ΅λ‹ˆλ‹€.


PR created automatically by Jules for task 1006353573105115304 started by @seonghobae

Copilot AI review requested due to automatic review settings July 1, 2026 16:33
@google-labs-jules

Copy link
Copy Markdown

πŸ‘‹ 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the static site against DOM-based XSS by enforcing Trusted Types via CSP and registering a default Trusted Types policy backed by DOMPurify, with supporting documentation updates.

Changes:

  • Add require-trusted-types-for 'script' to the CSP meta tag in index.html.
  • Introduce security.js to register a default Trusted Types policy that sanitizes HTML via DOMPurify.
  • Vendor DOMPurify (assets/dompurify.min.js) and document the Sentinel security learning in .jules/sentinel.md.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
index.html Enforces Trusted Types in CSP and loads DOMPurify + the default policy script.
security.js Registers a default Trusted Types policy that sanitizes HTML with DOMPurify.
assets/dompurify.min.js Adds vendored DOMPurify runtime used by the Trusted Types policy.
.jules/sentinel.md Documents the Trusted Types hardening rationale and prevention guidance.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread security.js
Comment on lines +3 to +7
if (window.trustedTypes && trustedTypes.createPolicy) {
trustedTypes.createPolicy('default', {
createHTML: (string) => DOMPurify.sanitize(string, {RETURN_TRUSTED_TYPE: true})
});
}
Comment thread index.html
Comment on lines +26 to 28
<script src="assets/dompurify.min.js"></script>
<script src="security.js"></script>
<script src="i18n.js" defer></script>
Comment thread .jules/sentinel.md
**Prevention:** μ™ΈλΆ€ 링크λ₯Ό μƒˆ νƒ­μœΌλ‘œ μ—΄κΈ° μœ„ν•΄ `target="_blank"`λ₯Ό μ‚¬μš©ν•  λ•Œλ§Œ `rel="noopener noreferrer"`λ₯Ό ν•¨κ»˜ μΆ”κ°€ν•˜μ—¬ λΆ€λͺ¨ 창에 λŒ€ν•œ 접근을 차단해야 ν•©λ‹ˆλ‹€.
## 2026-07-01 - Add Trusted Types Policy via DOMPurify
**Vulnerability:** Application lacked Trusted Types enforcement, which left it potentially vulnerable to DOM-based XSS if DOM sinks (like `innerHTML`) were manipulated.
**Learning:** Enforcing `require-trusted-types-for 'script'` in CSP will crash Chromium-based browsers if they assign strings to DOM sinks without a registered policy.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

OpenCode reviewed the current-head evidence but found unresolved reviewer or review-agent threads before approval.

Findings

1. HIGH .github/workflows/opencode-review.yml:1 - Unresolved reviewer thread blocks automated approval

  • Problem: OpenCode reached an APPROVE control result, but the approval step found unresolved, non-outdated human or review-agent thread evidence on the current pull request.
  • Root cause: Reviewer and review-agent feedback can arrive after bounded model evidence is prepared, so the approval step must re-query GitHub immediately before publishing an approval.
  • Fix: Address or resolve the listed reviewer thread(s), then re-run OpenCode on the current head.
  • Regression test: Keep the approval gate querying reviewThreads(first: 100) after model output and before create_pull_review APPROVE, including bot review agents other than OpenCode itself.

Review thread evidence

Latest unresolved reviewer thread evidence

security.js line 7

  • Latest reviewer comment: @copilot-pull-request-reviewer at 2026-07-01T16:36:27Z
  • Comment URL: #42 (comment)
  • Comment excerpt: 'trustedTypes.createPolicy('default', …)' can throw (e.g., if a default policy already exists), which would break page load. Also, the guard checks 'window.trustedTypes' but then uses the unqualified 'trustedTypes' identifier, and the policy assumes DOMPurify is always present. Consider using 'window.trustedTypes' consistently, checking 'window.DOMPurify', and wrapping policy creation in a try/catch so the page still loads if policy creation fails.

index.html line 28

  • Latest reviewer comment: @copilot-pull-request-reviewer at 2026-07-01T16:36:27Z
  • Comment URL: #42 (comment)
  • Comment excerpt: The newly added scripts are render-blocking because they omit 'defer', while 'i18n.js' is already deferred. Since these scripts don't appear to be needed during initial HTML parsing, deferring them will avoid blocking and keep script execution order (DOMPurify β†’ security policy β†’ i18n) intact.

.jules/sentinel.md line 19

  • Latest reviewer comment: @copilot-pull-request-reviewer at 2026-07-01T16:36:27Z

  • Comment URL: #42 (comment)

  • Comment excerpt: In Chromium, Trusted Types enforcement typically throws a Trusted Types violation (e.g., a TypeError) rather than "crashing" the browser. Rewording avoids ambiguity and keeps the doc technically precise.

  • Result: REQUEST_CHANGES

  • Reason: unresolved reviewer or review-agent thread(s) were present before approval.

  • Head SHA: d2338c5e7cae34c3d4c99f42ebe9b0751e94d94a

  • Workflow run: 28532676057

  • Workflow attempt: 1

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file (4 files)"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file (4 files)"]
  R1 --> V1["required checks"]
Loading

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: d2338c5e7cae34c3d4c99f42ebe9b0751e94d94a
  • Workflow run: 28532676057
  • Workflow attempt: 1
  • Gate result: REQUEST_CHANGES (approval step)

Pull request overview

OpenCode reviewed the current-head evidence but found unresolved reviewer or review-agent threads before approval.

Findings

1. HIGH .github/workflows/opencode-review.yml:1 - Unresolved reviewer thread blocks automated approval

  • Problem: OpenCode reached an APPROVE control result, but the approval step found unresolved, non-outdated human or review-agent thread evidence on the current pull request.
  • Root cause: Reviewer and review-agent feedback can arrive after bounded model evidence is prepared, so the approval step must re-query GitHub immediately before publishing an approval.
  • Fix: Address or resolve the listed reviewer thread(s), then re-run OpenCode on the current head.
  • Regression test: Keep the approval gate querying reviewThreads(first: 100) after model output and before create_pull_review APPROVE, including bot review agents other than OpenCode itself.

Review thread evidence

Latest unresolved reviewer thread evidence

security.js line 7

index.html line 28

.jules/sentinel.md line 19

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file (4 files)"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file (4 files)"]
  R1 --> V1["required checks"]
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants