You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
handle nonce re-writing for hx-head extension - #4220
hx-head does not handle nonces in scripts well as they need to be processed with the original page nonce to work. So we should probably use the existing inlineScriptNonce config in hx-head to set the correct nonce on the inserted script tags. Also we can make hx-csp use htmx:before:response event for its nonce rewriting so it can work well with hx-head which can process the head data after it. This does mean the hx-csp extension needs to be loaded first.
Corresponding issue:
Testing
Please explain how you tested this change manually, and, if applicable, what new tests you added. If
you're making a change to just the website, you can omit this section.
Checklist
I have read the contribution guidelines
I have targeted this PR against the correct branch (master for website changes, dev for
source changes)
This is either a bugfix, a documentation update, or a new feature that has been explicitly
approved via an issue
I ran the test suite locally (npm run test) and verified that it succeeded
Won't setting the nonce in addNode in hx-head mean that outerHTML comparisons will have already detected an element as different, when only their nonce is different?
When hx-csp is also in use, a TrustedTypes policy being in effect (require-trusted-types-for 'script') means that hx-head is doing things it's not allowed to.
Since I'm using <meta http-equiv="Content-Security-Policy", when I include a new one for hx-csp, then hx-head replacing it causes all sorts of errors.
A limitation of supporting htmx.config.inlineScriptNonce is that of course it doesn't handle stylesheets. In htmx v4, to avoid needing htmx.config.inlineStyleNonce it uses adoptedStyleSheets, which is something hx-head doesn't support.
For my last point about TrustedTypes support in hx-head, there seems to currently be no way for hx-head to use the policy registered by hx-csp. Should it just define it's own policy (I assume named something different so that 'allow-duplicates' is not required), or should there be a mechanism within htmx to allow sharing its policy?
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
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.
Description
hx-head does not handle nonces in scripts well as they need to be processed with the original page nonce to work. So we should probably use the existing inlineScriptNonce config in hx-head to set the correct nonce on the inserted script tags. Also we can make hx-csp use htmx:before:response event for its nonce rewriting so it can work well with hx-head which can process the head data after it. This does mean the hx-csp extension needs to be loaded first.
Corresponding issue:
Testing
Please explain how you tested this change manually, and, if applicable, what new tests you added. If
you're making a change to just the website, you can omit this section.
Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded