[sec-check] fix: sandbox CSP on SVG responses in /api/docs-image - #6812
Conversation
SVGs served with Content-Type: image/svg+xml can execute JavaScript when opened top-level. The docs origin's global CSP permits script-src 'self' 'unsafe-inline', so a committed SVG under docs/content/** containing <script> or on*-handlers would run same-origin on docs.kubestellar.io if the SVG lands via a merged PR — a persistent XSS gadget bounded only by PR review. Attach a per-response 'Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox' to SVG replies. The 'sandbox' directive strips the SVG document of its origin privileges (no script execution, no cookies/storage, no same-origin fetch), while 'default-src 'none'' also stops the SVG document from loading remote subresources. Non-SVG images are unaffected. Also extends src/__tests__/docs-image-route.test.ts with an SVG-CSP regression test and a non-SVG negative test. Refs #6810 Signed-off-by: kubestellar-hive[bot] <223556219+Copilot@users.noreply.github.com>
|
Important Held for human sign-off on the direction, not on the code. This PR's only tracked rationale is #6810, which the hive filed itself — issue #6810 was filed by kubestellar-hive[bot] and no human has acknowledged it. An agent-filed issue does not, on its own, establish that anyone agreed to the direction (hivecommons/hive#5117). The change may well be right; nothing here is a review of it. To release the hold, acknowledge the direction on that issue — comment on it, assign yourself, or add the |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellar-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hi @kubestellar-hive[bot]. Thanks for your PR. I'm waiting for a kubestellar member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
Security Fix
Hardens
src/app/api/docs-image/[...path]/route.tsagainst a stored-XSS gadget: any SVG committed underdocs/content/**was served withContent-Type: image/svg+xmland no per-response CSP, which — combined with the globalscript-src 'self' 'unsafe-inline'— lets an SVG execute JavaScript as the docs origin when opened top-level. Once a PR with a hostile SVG lands, the SVG URL underdocs.kubestellar.iobecomes a persistent same-origin XSS surface.Changes
src/app/api/docs-image/[...path]/route.ts: attachContent-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandboxon responses where the resolved extension is.svg. Thesandboxdirective strips origin privileges from the SVG document (no script exec, no cookies/storage, no same-origin fetch).default-src 'none'also prevents the SVG from loading external subresources. Non-SVG images are unchanged.src/__tests__/docs-image-route.test.ts: adds a positive test asserting the sandbox CSP onicon.svgand a negative test asserting no per-response CSP ondiagram.png.Why sandbox and not "remove svg from MIME_TYPES"
Removing SVG from the whitelist would break existing diagrams already committed under
docs/content/console/diagrams/*.svg. Sandbox CSP neutralises the attack while keeping legitimate diagram rendering functional.Verification
Refs #6810
Filed by sec-check agent (ACMM L6 — full mode)
— hive: agent=sec-check backend=copilot model=claude-opus-4.7