Skip to content

Emit csp-nonce meta tag so Turbo-injected styles/scripts work under a strict CSP - #5

Open
infused wants to merge 1 commit into
cmer:mainfrom
infused:csp-nonce-meta-tag
Open

Emit csp-nonce meta tag so Turbo-injected styles/scripts work under a strict CSP#5
infused wants to merge 1 commit into
cmer:mainfrom
infused:csp-nonce-meta-tag

Conversation

@infused

@infused infused commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #4.

Under a strict, nonce-based CSP the dashboard's Turbo-injected progress-bar <style> (and async-import <script> shim) are blocked, because the layout never provides the csp-nonce meta that the bundled Turbo already reads (getMetaContent("csp-nonce") → assigns .nonce on the elements it injects).

Change

  • Add <%= csp_meta_tag %> after csrf_meta_tags in the engine layout head. Rails' csp_meta_tag renders the meta only when a CSP is present (if content_security_policy?), so it's a complete no-op for apps without CSP — no behavior change for existing users.

Test

  • test/integration/csp_nonce_test.rb loads the dashboard under a nonce-based CSP and asserts the layout emits <meta name="csp-nonce"> carrying the same nonce as the response's style-src directive, plus a no-op case asserting no meta is emitted when the host has no CSP.
  • Verified failing before the layout change and passing after; full bin/test is green on both the full-host and API-only legs.

Changelog

  • Added a Fixed entry under [Unreleased].

The bundled Turbo injects its progress-bar <style> (and an async-import
<script> shim) at runtime and reads the nonce from a <meta name="csp-nonce">
tag. The layout never rendered that tag, so under a strict, nonce-based CSP
(no 'unsafe-inline') those injected elements were nonce-less and blocked.

Render Rails' csp_meta_tag in the layout head. It emits the meta only when a
CSP is configured, so it is a no-op for hosts without one.
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.

Dashboard blocked under a strict (nonce-based) Content Security Policy — layout omits the csp-nonce meta tag

1 participant