feat(content-script): verify against pristine fetched HTML, not the DOM#3
Merged
Conversation
Fixes false-invalid verification on pages whose client-side scripts
mutate content inside signed regions after page load. The most
visible case in the wild is Hugo Blox's docs theme, which injects a
<button class="copy-button">Copy</button> into every <pre> block on
DOMContentLoaded — the signer at build time never sees the button,
the verifier reading element.innerHTML does, and the canonical text
diverges. Documented as "Known Issue: Runtime DOM Mutation" in the
spec README.
autoVerifyPage now:
1. Fetches location.href with cache:'force-cache' (HTTP cache hit
on the typical post-navigation path; on a fresh load, a small
duplicate request that origins with sane cache headers serve
from cache too).
2. Runs extractSignedSections() on the response body to enumerate
every <signed-section> in document order from the pristine HTML.
3. Position-pairs each pristine slice with the live DOM
<signed-section> by index. The DOM element is still used for
UI placement (badge anchor, decoration); only the bytes fed to
verifySignedSection() come from the pristine fetch.
Falls back gracefully to per-section DOM verification when:
- the pristine fetch fails (network, HTTP error, CORS quirk)
- the pristine section count doesn't match the DOM count (page
rendered differently between navigation and our fetch, SPA route
change, intercepting service worker, runtime sections appended)
The fallback re-introduces the runtime-mutation false-invalid risk
on those pages, but only on those pages, and a console.warn marks
the case so users can report it.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Fixes false-invalid verification on pages whose client-side scripts mutate content inside signed regions after page load.
The most visible case is Hugo Blox's docs theme (used by the project website itself), which injects
<button class=\"copy-button\">Copy</button>into every<pre>block onDOMContentLoaded. The signer at build time never sees the button; the verifier readingelement.innerHTMLdoes; canonical text diverges; signature reports as invalid despite being mathematically correct. Documented as Known Issue: Runtime DOM Mutation in the spec README.What changed
autoVerifyPage()now:location.hrefwithcache: 'force-cache'(browser HTTP cache hit on the typical post-navigation path)<signed-section>substring from the pristine response viaextractSignedSections()(new helper landing in feat(verify): add extractSignedSections helper for pristine-HTML verify htmltrust-browser-client#1)verifySignedSection()The DOM element is still used for UI placement (badge anchor, decoration). Only the bytes fed to canonical-hash computation come from the pristine fetch.
Fallback
Falls back gracefully to per-section DOM verification when:
The fallback re-introduces the runtime-mutation false-invalid risk on those pages, but only on those pages, and a
console.warnmarks the case for debugging.Depends on
extractSignedSectionsto the lib(Already merged that PR locally via the
file:dep, so this PR's CI will exercise the new export.)Test plan
npx tsc --noEmitclean🤖 Generated with Claude Code