Repository navigation
fix(auth): verify streaming SigV4 chunk signatures inline - #271
Merged
Merged
Conversation
In signing mode TAG decoded STREAMING-AWS4-HMAC-SHA256-PAYLOAD bodies without checking a single chunk signature and re-signed upstream as UNSIGNED-PAYLOAD, so neither TAG nor Tigris ever authenticated the body of a streaming PUT: a captured header-signed request could be replayed with an arbitrary body for 15 minutes. The tiered local tier decoded the same way. The fix verifies the chunk chain inline, as the body streams, with no staging and no per-chunk buffering: - auth: RequestValidator.Validate returns a ValidatedRequest that keeps the signing key, signing time, credential scope and request signature; ChunkVerifier (new) continues the SigV4 chain from that seed, comparing with hmac.Equal. ValidateRequest is unchanged for existing callers. - proxy/chunked_reader: the decoder takes an optional verifier. Data is hashed as it is delivered; a chunk's LAST byte is withheld until its trailing CRLF is read, its signature verifies, and the next frame header is read (the terminal frame being verified too). A mismatch or a missing chunk-signature is a sticky ErrChunkSignatureMismatch from Read, so a failed chunk is never completely delivered and a clean EOF exists only after a fully verified chain, terminal frame included. Against an exact decoded Content-Length no consumer can hold a complete unauthenticated body. Only the plain HMAC marker is verified; the -TRAILER, ECDSA and unsigned-trailer markers keep framing-only decoding (documented at the dispatch). - proxy/forwarder_signing: validate BEFORE decoding and thread the ValidatedRequest into the decoder in Forward, ForwardTeeingBody, ForwardWithCapture and DoRequestWithCreds (which re-validates for the signed marker since its caller only kept the keys). A verification error surfaces as a body read error: the exact-length upstream request aborts short and Tigris rejects it; the client is answered SignatureDoesNotMatch via mapAuthError. - proxy/tiered + localstore: the local-tier PUT obtains the verifier from the forwarder (both production forwarders implement chunkVerifierProvider) and decodes with it; a chunk failure takes the existing reader-error path (no metadata commit, staged body reclaimed) and answers SignatureDoesNotMatch instead of IncompleteBody. Also fixes a separate signed-header bug: SignRequest signed every x-amz-* header, including X-Amz-Decoded-Content-Length, which prepareForwardedRequest then deleted AFTER signing; Tigris rejects a signed header that is absent on arrival. headersForForwardedSigning now drops that header and the aws-chunked Content-Encoding token from the header set before signing. Tests use the AWS SDK v2 request and stream signers as an independent oracle: a correct stream passes every entry point with the exact decoded bytes upstream and a forwarded signature that validates there; tampered chunk bodies (middle and last), tampered chunk and terminal signatures, a replayed header with a body signed under another key or with unsigned chunks all fail without upstream ever receiving a complete body and without a local-tier commit; the unsigned-trailer marker is untouched. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
[High impact] The PR appears safe to merge; no new actionable issues remain. SummaryThe PR checks signed streaming bodies as they pass through TAG.
The three earlier, unnumbered findings are addressed: oversized frames are bounded, empty streams are checked, and tests wait for upstream results. No new actionable issues were found. Reviews (3) · Last reviewed commit: "Merge origin/main into fix-streaming-chu..." · Reviewed by Greptile |
…pty streams Two gaps in the inline chunk-chain verification, and one test that could pass without checking its central promise. Oversized frames bypassed verification. The decoder withheld the last byte of the CLAIMED chunk, not of the declared body: a replayed header declaring X-Amz-Decoded-Content-Length: N with one frame claiming N+2 bytes handed all N replacement bytes to a consumer satisfied by exactly N — upstream under the exact Content-Length — before the frame's signature was ever checked, while TAG waited for bytes that never came. The verifying reader now takes the declared decoded length: a frame claiming more than the declaration has left is refused before a single byte of it is delivered, and a terminal frame that arrives with declared bytes unsent is refused too (an honestly signed chain over some other body is no authentication of the declared one). With the bound, the declared body's final byte is always the last byte of a frame whose successor can only be the terminal frame, so it is delivered only after the terminal signature verified. Both refusals are sticky ErrChunkSignatureMismatch, so every path answers SignatureDoesNotMatch. No declared length (-1) keeps the per-chunk rules only. The local tier passes its declared size; framing-only decoding is unchanged. Empty streams skipped verification. A zero decoded length is forwarded as http.NoBody, so nothing ever read the decoder and the terminal frame's signature went unchecked (upstream accepted, the local tier rejected). The signing forwarder's four entry points now decode through decodeBody, which drains a zero-length verified stream — reading and verifying exactly the terminal frame — before the body is replaced; a failure is refused before any upstream request. streamChunkVerifier is the single decision of whether a stream is verified, shared with decodeChunkedIfNeeded. The fake upstream now announces every handler run; the reject tests await upstream's record of the aborted request instead of inspecting a possibly empty record set, so "upstream never received a complete body" is checked on every case. New cases: the oversized frame and the short stream (reader level: nothing delivered / last byte withheld; forwarder level: every entry point), and the empty stream with a correct and a tampered terminal signature on every entry point and the tiered local PUT. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
Reconciles #266 (URL-only presigned GETs in transparent local auth) with this branch's validate-first chunk verification. auth/validator.go keeps Validate() returning *ValidatedRequest with ValidateRequest as the thin wrapper, but adopts #266's rule that the content-hash header is only required inside the validator for header-signed or non-GET presigned requests, and keeps #266's validatePresigned lifetime rules (X-Amz-Expires mandatory, exactly once, integer in [1, 604800], expiry and future-skew enforced, ErrInvalidExpires) while still returning the presigned signing time for the chunk verifier. proxy/forwarder_signing.go keeps #266's validateRequest wrapper (signing mode still rejects requests without X-Amz-Content-Sha256) as the first step of this branch's validate() helper, so every entry point validates first and then decodes the body with the verifying chunked reader. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
|
🎉 This PR is included in version 1.22.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
In signing mode,
STREAMING-AWS4-HMAC-SHA256-PAYLOADbodies were decoded for framing only and re-signed upstream asUNSIGNED-PAYLOAD, so neither TAG nor Tigris ever authenticated the body. A captured header-signed streaming PUT could be replayed within the 15-minute window with an arbitrary body.Chunk signatures are now verified inline as the body streams:
RequestValidator.Validatereturns the validated request (signing key, date, scope, seed signature);ValidateRequestis unchanged for existing callers. AChunkVerifierwalks the SigV4 chain (AWS4-HMAC-SHA256-PAYLOAD, previous signature,sha256(""), chunk digest) withhmac.Equal.sha256("")). A mismatch is a stickyErrChunkSignatureMismatch. Against the exact decodedContent-Length, no consumer can hold a complete unauthenticated body: upstream sees a short body and rejects it, the tee never completes, and the local tier never commits metadata.403 SignatureDoesNotMatch. The tiered local-tier PUT obtains the verifier from the forwarder and takes its existing read-error path (noPutMetaIfVersion, staged body reclaimed).-TRAILER, ECDSA and unsigned-trailer markers keep framing-only decoding, noted at the dispatch.Also fixes a separate bug on main:
SignRequestsignedX-Amz-Decoded-Content-Length(copied by thex-amz-*rule) andprepareForwardedRequestthen deleted it, so the upstreamSignedHeaderslisted a header that was absent on arrival, which the Tigris verifier rejects asSignatureDoesNotMatch.headersForForwardedSigningnow drops that header and theaws-chunkedtoken before signing; a test validates the forwarded request with a real validator.Tests use the AWS SDK v2 signer for the header and
v4.NewStreamSigneras an independent chain oracle: valid streams forward byte-exact through all four entry points; tampered middle/last chunk, tampered chunk or terminal signature, and replayed headers with another body are all rejected before any consumer holds a complete body.Replaces #243, whose temp-file store-and-forward staging is not adopted.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
Note
High Risk
Changes authentication for streaming upload bodies and signing-forward paths; mistakes could reject valid traffic or leave replay vectors open.
Overview
Closes a security gap where
STREAMING-AWS4-HMAC-SHA256-PAYLOADuploads were decoded for framing only and re-signed upstream asUNSIGNED-PAYLOAD, so a replayed header could carry a different body within the SigV4 window.Auth adds
ChunkVerifierandRequestValidator.Validate(returns signing material for the chunk chain;ValidateRequestunchanged). Proxy verifies each chunk inline while decoding: hashes as data streams, withholds each chunk’s last byte until signatures and framing check out, and binds frames toX-Amz-Decoded-Content-Lengthso consumers cannot finish an unauthenticated body. Signing forwarder validates before decode on all paths; tiered local PUT gets the verifier from the forwarder and maps failures toSignatureDoesNotMatch.Also fixes upstream re-signing:
headersForForwardedSigningdropsX-Amz-Decoded-Content-Lengthand theaws-chunkedContent-Encodingtoken before signing (not after), avoiding TigrisSignatureDoesNotMatchwhen a signed header was removed post-sign. Only the HMAC-SHA256 streaming marker is verified; unsigned/trailer/ECDSA markers stay decode-only.Reviewed by Cursor Bugbot for commit b302c24. Bugbot is set up for automated code reviews on this repo. Configure here.