#21667: fix(canvas): add CSP and security headers to HTML responses
size: XS
## Summary
- Add `Content-Security-Policy`, `X-Frame-Options`, and `X-Content-Type-Options` headers to all HTML responses served by the canvas host in `src/canvas-host/server.ts`.
- CSP allows `'unsafe-inline'` for scripts and styles because the injected action bridge (`injectCanvasLiveReload`) and the default index page use inline `<script>` and `<style>` blocks.
- Headers are applied to both the normal HTML file serving path and the 404 "missing file" HTML fallback.
## Test plan
- [x] Verified the injected live-reload/action-bridge script uses inline `<script>` tags, confirming `'unsafe-inline'` is needed in `script-src`
- [x] Verified the default index HTML uses inline `<style>` tags, confirming `'unsafe-inline'` is needed in `style-src`
- [x] Formatter and linter pass with no warnings
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added `Content-Security-Policy`, `X-Frame-Options`, and `X-Content-Type-Options` headers to all HTML responses served by the canvas host. The CSP policy correctly allows `'unsafe-inline'` for scripts and styles, which is necessary because the live-reload injection (`injectCanvasLiveReload`) adds inline `<script>` tags and the default index page includes inline `<style>` blocks. Headers are properly applied to both the normal HTML file serving path and the 404 fallback response.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with no identified risks
- The security headers are correctly implemented with appropriate CSP directives that match the actual usage patterns (inline scripts/styles). The changes are minimal, focused, and properly cover all HTML response paths. Import reordering is cosmetic and follows standard conventions.
- No files require special attention
<sub>Last reviewed commit: 4f837f1</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#2544: fix(security): XSS vulnerability in Canvas Host + Windows CI stability
by Kiwitwitter · 2026-01-27
78.4%
#23465: Gateway: strengthen Control UI security headers
by bmendonca3 · 2026-02-22
76.4%
#11740: fix(gateway): remove IP-based canvas auth fallback
by coygeek · 2026-02-08
72.3%
#6906: Add baseline HTTP security headers to gateway responses
by QuantumEdu · 2026-02-02
72.3%
#22361: fix(macos/canvas): prevent A2UI reload loop and add A2UI MIME mapping
by AIflow-Labs · 2026-02-21
72.0%
#5649: fix(security): harden file permissions and header merging
by sfo2001 · 2026-01-31
71.5%
#21159: fix(security): harden data exposure controls
by novalis133 · 2026-02-19
70.8%
#16990: fix(media): strip auth headers on cross-origin redirect in download...
by AI-Reviewer-QS · 2026-02-15
70.3%
#14197: fix(security): harden browser API auth, token comparisons, and hook...
by leecarollyn-gif · 2026-02-11
69.2%
#22309: fix(export-session): render system prompt section and payload corre...
by AIflow-Labs · 2026-02-21
69.1%