Skip to content

httpsig 2.2.0: content-digest auto-coverage and verification enforcement - #69

Merged
dickhardt merged 1 commit into
mainfrom
httpsig-content-digest
Aug 13, 2026
Merged

httpsig 2.2.0: content-digest auto-coverage and verification enforcement#69
dickhardt merged 1 commit into
mainfrom
httpsig-content-digest

Conversation

@dickhardt

Copy link
Copy Markdown
Member

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) and content-type on top of the four mandatory components. Resources are exempt and declare their needs via additional_signature_components in resource metadata.

Signing (fetch())

  • After the covered components resolve, content-digest is appended whenever the body's exact bytes are available to hash — string, Uint8Array, ArrayBuffer, Buffer, the four cases generateContentDigest handles. ReadableStream, FormData, and Blob are serialized by the fetch implementation, so they are not digestible here.
  • DEFAULT_COMPONENTS_BODY is deliberately unchanged: a static list cannot know whether a given body is hashable, and adding content-digest there would break every streaming caller.
  • New option 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)

generateContentDigest throws on unhandled types

It previously 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' 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, with required_input naming the full Section 10.3 body set) unless the signature covers content-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), generateContentDigest equivalence across the four types and throwing on unhandled ones, and requireContentDigest pass/fail/no-body/tampered-body on verify.

npm test --workspace=httpsig: 190 pass, 0 fail (174 pre-existing + 16 new). better-auth (32) and email-verification (120) suites also pass; npm run build and npm run lint clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TQ2FCHHAnuJWF5TJB3838S

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
@dickhardt
dickhardt merged commit 8d5517f into main Aug 13, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant