Skip to content

fix: admin styling to a nonce'd <style> block (CSP is nonce-only) - #4

Merged
DanMat merged 1 commit into
mainfrom
fix/admin-csp-nonced-styles
Aug 30, 2026
Merged

DanMat merged 1 commit into
mainfrom
fix/admin-csp-nonced-styles

Conversation

@DanMat

@DanMat DanMat commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

The admin CSP is nonce-only for style-src (SecurityHeaders, no 'unsafe-inline'), so the inline style="" attributes on the Commerce admin page were dropped by the browser — status-pill colours never applied and the multi-column form/filter layout collapsed on the live admin. (The core CspNonceTest guards core templates for exactly this, but plugin HTML isn't scanned, so it slipped through Phase 1/2.)

Fix

  • Emit one nonce-carrying <style> block per render (the page handler already receives the CSP nonce as its 2nd arg; mirrors core DemoBanner/PreviewBanner), and replace every inline style= with a class.
  • Pill tone classes are generated from STATUS_TONE, so each status and its var(--nb-*-bg/-text) colours stay defined once and remain dark-safe.

Tests

New guard: a <style nonce=…> block is emitted and no inline style= attribute survives (/\sstyle\s*=/), plus the pill tone resolves from theme tokens inside the block. 27 tests green; PHPStan + php-cs-fixer clean.

Paired with the same fix in plugin-inventory. Redeploy will make the pills actually colour on the demo.

🤖 Generated with Claude Code

…e-only)

The admin CSP is nonce-only for style-src (no 'unsafe-inline'), so the inline
style="" attributes on the Commerce admin page were being DROPPED by the browser
— the status-pill colours never applied and the multi-column form/filter layout
collapsed on the live admin.

Emit one nonce-carrying <style> block per render (the page handler already
receives the CSP nonce as its 2nd arg) and replace every inline style= with a
class. The pill tone classes are generated from STATUS_TONE, so a status and its
theme-token colours stay defined in one place and remain dark-safe.

Tests: a new guard asserts a <style nonce=…> block is emitted and NO inline
style= attribute survives, plus the pill tone resolves from theme tokens inside
the block. 27 tests green; PHPStan + php-cs-fixer clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@DanMat
DanMat merged commit 2857d15 into main Aug 30, 2026
2 checks passed
@DanMat
DanMat deleted the fix/admin-csp-nonced-styles branch August 30, 2026 20:59
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.

1 participant