Skip to content

fix(auth): verify streaming SigV4 chunk signatures inline - #271

Merged
ovaistariq merged 3 commits into
mainfrom
fix-streaming-chunk-verify
Oct 22, 2026
Merged

ovaistariq merged 3 commits into
mainfrom
fix-streaming-chunk-verify

Conversation

@ovaistariq

@ovaistariq ovaistariq commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

In signing mode, STREAMING-AWS4-HMAC-SHA256-PAYLOAD bodies were decoded for framing only and re-signed upstream as UNSIGNED-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.Validate returns the validated request (signing key, date, scope, seed signature); ValidateRequest is unchanged for existing callers. A ChunkVerifier walks the SigV4 chain (AWS4-HMAC-SHA256-PAYLOAD, previous signature, sha256(""), chunk digest) with hmac.Equal.
  • The chunked reader hashes data as it streams and withholds each chunk's last byte until that chunk's signature and the next frame header verify (the terminal frame is verified over sha256("")). A mismatch is a sticky ErrChunkSignatureMismatch. Against the exact decoded Content-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.
  • The signing forwarder validates before decoding in every entry point and answers 403 SignatureDoesNotMatch. The tiered local-tier PUT obtains the verifier from the forwarder and takes its existing read-error path (no PutMetaIfVersion, staged body reclaimed).
  • Only the signed streaming marker is verified; -TRAILER, ECDSA and unsigned-trailer markers keep framing-only decoding, noted at the dispatch.

Also fixes a separate bug on main: SignRequest signed X-Amz-Decoded-Content-Length (copied by the x-amz-* rule) and prepareForwardedRequest then deleted it, so the upstream SignedHeaders listed a header that was absent on arrival, which the Tigris verifier rejects as SignatureDoesNotMatch. headersForForwardedSigning now drops that header and the aws-chunked token before signing; a test validates the forwarded request with a real validator.

Tests use the AWS SDK v2 signer for the header and v4.NewStreamSigner as 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-PAYLOAD uploads were decoded for framing only and re-signed upstream as UNSIGNED-PAYLOAD, so a replayed header could carry a different body within the SigV4 window.

Auth adds ChunkVerifier and RequestValidator.Validate (returns signing material for the chunk chain; ValidateRequest unchanged). 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 to X-Amz-Decoded-Content-Length so 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 to SignatureDoesNotMatch.

Also fixes upstream re-signing: headersForForwardedSigning drops X-Amz-Decoded-Content-Length and the aws-chunked Content-Encoding token before signing (not after), avoiding Tigris SignatureDoesNotMatch when 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.

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
@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no new actionable issues remain.

Summary

The PR checks signed streaming bodies as they pass through TAG.

  • Signed streaming uploads stay tied to their request signature as they stream.
  • Forwarded uploads are signed against the headers they actually carry.

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

Comment thread proxy/chunked_reader.go Resolved
Comment thread proxy/forwarder_signing.go Resolved
Comment thread proxy/chunk_verify_test.go Resolved
…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
@ovaistariq
ovaistariq merged commit 6addc09 into main Oct 22, 2026
9 checks passed
@ovaistariq
ovaistariq deleted the fix-streaming-chunk-verify branch October 22, 2026 03:36
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.22.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants