Skip to content

fix(coderd): omit frame-ancestors CSP for embed routes#24529

Merged
jdomeracki-coder merged 1 commit into
mainfrom
fix/embed-csp-frame-ancestors
Apr 20, 2026
Merged

fix(coderd): omit frame-ancestors CSP for embed routes#24529
jdomeracki-coder merged 1 commit into
mainfrom
fix/embed-csp-frame-ancestors

Conversation

@jdomeracki-coder
Copy link
Copy Markdown
Contributor

Problem

PR #24474 added frame-ancestors 'self' as the default CSP directive and set
frame-ancestors * for embed routes (/agents/{agentId}/embed). However,
per the CSP spec, the * wildcard in frame-ancestors only matches network
schemes (http, https, ws, wss). VSCode webviews use the vscode-webview://
scheme, which is not a network scheme, so frame-ancestors * blocks embedding.

This is a known limitation documented in:

Fix

Omit the frame-ancestors directive entirely from the embed route CSP instead
of setting it to *. When frame-ancestors is absent from CSP, the browser
does not enforce frame ancestor restrictions via CSP (frame-ancestors does
not fall back to default-src), allowing embedding from any origin/scheme
including vscode-webview://.

  • Non-embed routes still have frame-ancestors 'self' for clickjacking protection.
  • Operator CODER_ADDITIONAL_CSP_POLICY overrides are still respected.
  • All other CSP protections (script-src, connect-src, etc.) remain intact.

Changes

File Change
coderd/httpmw/csp.go Support omitting frame-ancestors when an empty slice is passed via staticAdditions
coderd/coderd.go Pass empty slice instead of ["*"] for embed routes
coderd/httpmw/csp_test.go Add OmitWhenEmpty test; update OverrideViaStaticAdditions to use a concrete origin
Implementation notes (Coder Agents generated)

Decision log

  1. Why not frame-ancestors * vscode-webview://*? — The frame-ancestors source-list doesn't support arbitrary scheme wildcards. Only network schemes, hostnames, and 'self' are valid sources.
  2. Why empty slice as sentinel? — Minimal API surface change. An empty slice in staticAdditions for CSPFrameAncestors signals "omit entirely". The key exists (so the default 'self' isn't applied), but the empty value triggers deletion before header construction.
  3. Security impact — Embed routes are intentionally designed for iframe embedding (with postMessage auth bootstrap). Omitting frame-ancestors is equivalent to the pre-fix(coderd): add frame-ancestors CSP directive to prevent clickjacking #24474 behavior for these specific routes only.

🤖 Generated by Coder Agents

The CSP wildcard '*' in frame-ancestors only matches network schemes
(http, https, ws, wss) per the CSP spec. VSCode webviews use the
vscode-webview:// scheme, which is not a network scheme, so
frame-ancestors * blocks embedding in VSCode.

The fix omits frame-ancestors entirely from the embed route CSP.
When frame-ancestors is absent from CSP, no frame ancestor restriction
is enforced, allowing embedding from any scheme including
vscode-webview://. All other CSP protections remain intact, and
non-embed routes still have frame-ancestors 'self'.
@jdomeracki-coder jdomeracki-coder marked this pull request as ready for review April 20, 2026 13:03
@jdomeracki-coder
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jdomeracki-coder jdomeracki-coder merged commit 411ed21 into main Apr 20, 2026
33 checks passed
@jdomeracki-coder jdomeracki-coder deleted the fix/embed-csp-frame-ancestors branch April 20, 2026 13:38
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants