s3: return InvalidArgument for malformed x-amz-content-sha256

A header value that decodes to neither 32-byte hex nor base64 is a
malformed argument, not a hash mismatch.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Chris LuandDevin committed 2026-10-07 05:10:11 -07:00
1 parent 5d67acf5db
commit f9a70da28b
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ func getRequestDataReader(s3a *S3ApiServer, r *http.Request) (io.ReadCloser, s3e
expected, valid := expectedContentSha256(r)
if !valid {
return nil, s3err.ErrContentSHA256Mismatch
return nil, s3err.ErrInvalidArgument
}
if expected != nil && dataReader != nil {
if r.ContentLength == 0 {
@@ -299,6 +299,12 @@ func TestGetRequestDataReaderEmptyBodyHash(t *testing.T) {
t.Fatalf("empty body with wrong hash: code=%v", code)
}
malformed := httptest.NewRequest("PUT", "/b/o", strings.NewReader("x"))
malformed.Header.Set("X-Amz-Content-Sha256", "nothex")
if _, code := getRequestDataReader(s3a, malformed); code != s3err.ErrInvalidArgument {
t.Fatalf("malformed sha256 header: code=%v", code)
}
emptySum := sha256.Sum256(nil)
match := httptest.NewRequest("PUT", "/b/dir/", http.NoBody)
match.Header.Set("X-Amz-Content-Sha256", hex.EncodeToString(emptySum[:]))