Make admin UI CSP-compatible (nonce inline scripts, drop inline onclick)#477
Merged
dereuromark merged 1 commit intomasterfrom Apr 22, 2026
Merged
Make admin UI CSP-compatible (nonce inline scripts, drop inline onclick)#477dereuromark merged 1 commit intomasterfrom
dereuromark merged 1 commit intomasterfrom
Conversation
- Add nonce attribute to inline <script> blocks (layout, stats chart) - Replace postLink+confirm with postButton+data-confirm-message across all admin templates to eliminate inline onclick handlers that CSP blocks without unsafe-inline / unsafe-hashes - JS delegate in the layout already intercepts form[data-confirm-message] submit events and replicates the confirmation UX This lets the admin UI work under a strict script-src CSP (e.g. "script-src 'self' 'nonce-X' 'unsafe-eval'") without needing 'unsafe-inline' or 'unsafe-hashes'.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #477 +/- ##
============================================
- Coverage 77.22% 77.22% -0.01%
Complexity 949 949
============================================
Files 45 45
Lines 3196 3209 +13
============================================
+ Hits 2468 2478 +10
- Misses 728 731 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nonceattribute to the two inline<script>blocks (layout initialization, stats chart) so apps with a strictscript-src 'self' 'nonce-...' ...CSP can run them.Form->postLink(..., 'confirm' => X)withForm->postButton(..., 'form' => ['data-confirm-message' => X])across all admin templates.postLinkemitsonclick="..."on the<a>, which CSP blocks without'unsafe-inline'/'unsafe-hashes'.noncedoes not cover inline event handlers per the CSP spec.postButtonemits a<form>+<button type="submit">— zero inline event handlers. The existing JS delegate intemplates/layout/queue.phpalready interceptsform[data-confirm-message]submit events and callsconfirm(), preserving the destructive-action confirmation UX 1:1.Before / after
Host app nonce setup
Apps that want to benefit from the new nonce support need to set a
cspNoncerequest attribute in a middleware, for example:If no
cspNonceattribute is present, the<script>tag falls back to rendering without thenonceattribute — apps on permissive CSP continue to work unchanged.Visual side-note
Admin/Queue/index.phpandAdmin/QueueProcesses/index.phphave abtn-groupthat wrapped two adjacent postLinks. Because eachpostButtonnow wraps its button in<form class="d-inline">, Bootstrap's.btn-groupno longer collapses borders across them. They render as two independent adjacent buttons rather than a connected pair. Functionally identical; visual grouping lost. Mentioning for awareness.Verified
/admin/queueand/admin/queue/queued-jobsin Chrome, confirmed 0 inlineonclickattributes, 24form[data-confirm-message]elements, and confirmation dialog fires as expected on button click with proper localized message.cspNonceattribute is present on request.