Skip to content

add nonce reuse protection to hx-nonce#3785

Open
MichaelWest22 wants to merge 3 commits intobigskysoftware:four-devfrom
MichaelWest22:nonce-reuse-protect
Open

add nonce reuse protection to hx-nonce#3785
MichaelWest22 wants to merge 3 commits intobigskysoftware:four-devfrom
MichaelWest22:nonce-reuse-protect

Conversation

@MichaelWest22
Copy link
Copy Markdown
Collaborator

@MichaelWest22 MichaelWest22 commented May 5, 2026

Description

The extension rewrites the response nonce to the page nonce so swapped-in elements pass subsequent nonce checks. Before doing that rewrite, we can scrub any element that already carries the page nonce value from the raw response text.

The server cannot know the page nonce - it only knows its own per-response nonce. So if the page nonce appears in a response, it was put there by an attacker, not the server. Scrubbing it first means the rewrite pass cannot accidentally promote attacker-controlled elements to trusted status.

The risk: unlike <script nonce>, hx-nonce attributes are not blanked by browsers after parse, so they are a possible additional nonce exposure surface. The scrub step is a defense-in-depth measure to ensure a stolen nonce cannot be pre-stamped into injected content to pass nonce checks.

Corresponding issue:

Testing

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

@MichaelWest22 MichaelWest22 added the htmx 4 Issues specific to htmx version 4 label May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

htmx 4 Issues specific to htmx version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant