Skip to content

[sec-check] fix: sandbox CSP on SVG responses in /api/docs-image - #6812

Merged
kubestellar-hive[bot] merged 1 commit into
mainfrom
sec/svg-sandbox-6810
Sep 11, 2026
Merged

kubestellar-hive[bot] merged 1 commit into
mainfrom
sec/svg-sandbox-6810

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

Security Fix

Hardens src/app/api/docs-image/[...path]/route.ts against a stored-XSS gadget: any SVG committed under docs/content/** was served with Content-Type: image/svg+xml and no per-response CSP, which — combined with the global script-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 under docs.kubestellar.io becomes a persistent same-origin XSS surface.

Changes

  • src/app/api/docs-image/[...path]/route.ts: attach Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox on responses where the resolved extension is .svg. The sandbox directive 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 on icon.svg and a negative test asserting no per-response CSP on diagram.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

  • The two new tests cover both the SVG-CSP and no-CSP-on-PNG paths.
  • Path-traversal and MIME-mapping tests are untouched.

Refs #6810


Filed by sec-check agent (ACMM L6 — full mode)

— hive: agent=sec-check backend=copilot model=claude-opus-4.7

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>
@kubestellar-hive

Copy link
Copy Markdown
Contributor Author

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 approved-direction label — and remove the hold label here.

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Sep 8, 2026
@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kproche for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellar-docs ready!

Name Link
🔨 Latest commit 887f824
🔍 Latest deploy log https://app.netlify.com/projects/kubestellar-docs/deploys/6aa04d362b62740008b82a76
😎 Deploy Preview https://deploy-preview-6812--kubestellar-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubestellar-prow kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 8, 2026
@kubestellar-prow

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@kubestellar-prow kubestellar-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 8, 2026
@clubanderson clubanderson removed the hold label Sep 11, 2026
@clubanderson

Copy link
Copy Markdown
Member

Direction acknowledged by hub admin (approved-direction added on #6810); releasing the #5117 hold. This hive runs at ACMM L6 and may act on its own findings.

@kubestellar-hive
kubestellar-hive Bot merged commit 66ca484 into main Sep 11, 2026
14 of 17 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the sec/svg-sandbox-6810 branch September 11, 2026 16:44
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

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

Labels

copilot dco-signoff: yes Indicates the PR's author has signed the DCO. frontend needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. pages size/M Denotes a PR that changes 30-99 lines, ignoring generated files. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants