httpsig 2.2.0: content-digest auto-coverage and verification enforcement - #69
Merged
Conversation
AAuth -11 Section 10.3 requires a request carrying a body to a PS or AS endpoint to cover content-digest (RFC 9530) and content-type on top of the four mandatory components. This package covered content-digest only when the caller listed it explicitly, and verified it only when the signer covered it -- so the rule was enforced nowhere, and the beta wallet hand-rolled the check. Signing side: after the covered components resolve, fetch() appends content-digest whenever the body's exact bytes are available to hash -- string, Uint8Array, ArrayBuffer, or Buffer, the four cases generateContentDigest handles. The component is NOT added to DEFAULT_COMPONENTS_BODY: a static list cannot know whether a given body is hashable, and putting it there would break every streaming caller. A new contentDigest option controls the behavior: 'auto' (default) appends when digestible, 'require' throws on a non-digestible body instead of silently dropping the component (what PS and AS callers pass), and 'omit' restores the pre-2.2 behavior. generateContentDigest now throws on body types it does not handle. Previously it fell through to String(body), so a ReadableStream produced a valid signature over the SHA-256 of the literal text "[object ReadableStream]" -- bytes that never go on the wire and that no verifier can reproduce. Without the throw, 'auto' could not tell "hashable" from "hashed the wrong thing". Verification side: a new VerifyOptions.requireContentDigest flag makes verification fail when the signature does not cover content-digest on a request with a body (the digest itself was already validated whenever covered). This is the flag a PS or AS sets to enforce Section 10.3. Resources are exempt from the profile rule and declare their needs via additional_signature_components in resource metadata. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TQ2FCHHAnuJWF5TJB3838S
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.
Implements the AAuth -11 Section 10.3 HTTP Message Signatures profile rule: a request carrying a body to a PS or AS endpoint MUST cover
content-digest(RFC 9530) andcontent-typeon top of the four mandatory components. Resources are exempt and declare their needs viaadditional_signature_componentsin resource metadata.Signing (
fetch())content-digestis appended whenever the body's exact bytes are available to hash —string,Uint8Array,ArrayBuffer,Buffer, the four casesgenerateContentDigesthandles.ReadableStream,FormData, andBlobare serialized by the fetch implementation, so they are not digestible here.DEFAULT_COMPONENTS_BODYis deliberately unchanged: a static list cannot know whether a given body is hashable, and addingcontent-digestthere would break every streaming caller.contentDigest?: 'auto' | 'require' | 'omit'(default'auto'):'auto'— append when digestible, sign without it otherwise'require'— throw on a non-digestible body instead of silently dropping the component; PS and AS callers pass this'omit'— never auto-append (pre-2.2 behavior)generateContentDigestthrows on unhandled typesIt previously fell through to
String(body), so aReadableStreamproduced a valid signature over the SHA-256 of the literal text"[object ReadableStream]"— bytes that never go on the wire and that no verifier can reproduce. Without the throw,'auto'cannot tell "hashable" from "hashed the wrong thing".Verification (
verify())New
VerifyOptions.requireContentDigest?: boolean. When true, a request with a body fails verification (invalid_input, withrequired_inputnaming the full Section 10.3 body set) unless the signature coverscontent-digest; the digest itself was already validated whenever covered. This is the flag a PS or AS sets to enforce the rule instead of hand-rolling the check — the beta wallet hand-rolled exactly this.Tests
16 new tests in
httpsig/tests/test-content-digest.ts: auto-append for each digestible type, no append for ReadableStream/FormData/Blob under'auto','require'throwing on non-digestible bodies,'omit'behavior (including explicit listing still working),generateContentDigestequivalence across the four types and throwing on unhandled ones, andrequireContentDigestpass/fail/no-body/tampered-body on verify.npm test --workspace=httpsig: 190 pass, 0 fail (174 pre-existing + 16 new).better-auth(32) andemail-verification(120) suites also pass;npm run buildandnpm run lintclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01TQ2FCHHAnuJWF5TJB3838S