Files
floci/src/main/java/io/github/hectorvent
David bfe2b71587 fix(s3): verify the SigV4 header signature when enforce-auth is enabled (#3573)
With FLOCI_SERVICES_S3_ENFORCE_AUTH=true, a request signed in the
Authorization header, which is how every AWS SDK and the CLI sign ordinary
calls, was authenticated by access key existence alone: isKnownAccessKey
checked that the key id was registered and the Signature value was never
recomputed. The presigned placements already had real verifiers (#1842 for
the query string, #3081 for browser POST); this was the remaining one, so a
fabricated signature naming a known key was accepted for any request.

Add S3HeaderSignatureFilter beside PreSignedUrlFilter. It runs only with the
flag on, for requests routed to S3Controller, and rebuilds the canonical
request from the request as it arrived: raw path, canonical query string,
the SignedHeaders with host resolved through S3VirtualHostFilter, and the
signed x-amz-content-sha256. The signature is derived from the resolved
secret and compared in constant time; when the declared hash is a real
digest the body is hashed too and handed back unchanged. Rejections mirror
S3's codes and order: AuthorizationHeaderMalformed for a structurally bad
header or scope, AccessDenied for a missing date, InvalidRequest for a
missing content hash, InvalidAccessKeyId for an unknown key or a temporary
key without its session token, RequestTimeTooSkewed beyond fifteen minutes,
SignatureDoesNotMatch for an unsigned host or a signature that does not
verify, and XAmzContentSHA256Mismatch for a body that differs from its
declared hash. PreSignedUrlFilter's crypto helpers go package-private so
the new filter shares them.

The entity stream is read directly rather than gated on hasEntity(), which
RESTEasy Reactive implements as "has a Content-Type"; the AWS CLI sends
bucket configuration bodies and put-object --body without one, and the
first cut rejected those as hash mismatches.

The enforce-auth tests all sent a fabricated Signature=test, which is the
bug running green. A new testutil S3RequestSigner signs each request at
send time the way an SDK does; the 103 fabricated headers become filter
attachments with no assertion changed, and three new tests pin the forged,
wrong-secret, unbound-host, tampered-body, stale-date, missing-hash,
missing-date and malformed-header cases. Verified live with the flag on
against the unmodified AWS CLI 2.36 (including an 8 MB multipart round
trip) and the AWS Java SDK v2 compat suite, 143/143 across every S3 class.

Closes #2332
2026-09-13 18:39:34 -04:00
..