From 781288cf11fd4cae4808d358af261c08d149e89a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 27 Nov 2026 02:42:37 -0800 Subject: [PATCH] s3api: ignore custom x- query parameters on bucket requests (#13046) --- weed/s3api/s3api_bucket_handlers_misc.go | 14 +++++++------- .../s3api/s3api_bucket_subresource_routing_test.go | 5 ++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/weed/s3api/s3api_bucket_handlers_misc.go b/weed/s3api/s3api_bucket_handlers_misc.go index 0c6f8230a6..0e45507832 100644 --- a/weed/s3api/s3api_bucket_handlers_misc.go +++ b/weed/s3api/s3api_bucket_handlers_misc.go @@ -244,13 +244,12 @@ func (s3a *S3ApiServer) GetBucketWebsiteHandler(w http.ResponseWriter, r *http.R } // listObjectsQueryParams are the query keys a ListObjects/ListObjectsV2 request may -// carry. x-id is stamped by the AWS SDKs and carries no meaning for the server; the -// rest of the non-listing keys are what a presigned URL signs into the query string. +// carry. The non-listing keys are what a presigned URL signs into the query string. var listObjectsQueryParams = map[string]bool{ "prefix": true, "delimiter": true, "marker": true, "max-keys": true, "encoding-type": true, "list-type": true, "continuation-token": true, "start-after": true, "fetch-owner": true, "expected-bucket-owner": true, - "allow-unordered": true, "x-id": true, + "allow-unordered": true, // SigV2 presigned URLs. "AWSAccessKeyId": true, "Signature": true, "Expires": true, } @@ -264,13 +263,14 @@ func unroutedBucketSubresource(r *http.Request) (string, bool) { } // unroutedSubresource names a query key that no route claimed, outside the -// request's own parameters, SigV2 presign keys, and SigV4 presign keys -// (all "X-Amz-" prefixed). +// request's own parameters, SigV2 presign keys, and "x-" keys in any case: +// SigV4 presign keys and the custom parameters S3 ignores (x-id from the AWS +// SDKs, x-purpose from Elasticsearch). func unroutedSubresource(r *http.Request, allowed map[string]bool) (string, bool) { for key := range r.URL.Query() { switch { - case allowed[key], strings.HasPrefix(key, "X-Amz-"): - case key == "x-id", key == "AWSAccessKeyId", key == "Signature", key == "Expires": + case allowed[key], len(key) >= 2 && strings.EqualFold(key[:2], "x-"): + case key == "AWSAccessKeyId", key == "Signature", key == "Expires": default: return key, true } diff --git a/weed/s3api/s3api_bucket_subresource_routing_test.go b/weed/s3api/s3api_bucket_subresource_routing_test.go index b82f863e17..b55fe0f29f 100644 --- a/weed/s3api/s3api_bucket_subresource_routing_test.go +++ b/weed/s3api/s3api_bucket_subresource_routing_test.go @@ -18,6 +18,9 @@ func TestUnroutedBucketSubresource(t *testing.T) { "list-type=2&continuation-token=x", "delimiter=/&encoding-type=url", "x-id=ListObjectsV2", + "prefix=tests-a/&x-purpose=SnapshotMetadata", + "list-type=2&x-custom-tag=1", + "prefix=a&X-Purpose=SnapshotMetadata", // The listing handlers read allow-unordered and validate it against // delimiter, so the guard has to let it through to them. "allow-unordered=true", @@ -31,7 +34,7 @@ func TestUnroutedBucketSubresource(t *testing.T) { assert.False(t, found, "%q is a listing request, got %q", query, name) } - for _, query := range []string{"torrent=", "replication=", "prefix=a&torrent="} { + for _, query := range []string{"torrent=", "replication=", "prefix=a&torrent=", "purpose=x"} { req, _ := http.NewRequest("GET", "http://localhost/bucket?"+query, nil) _, found := unroutedBucketSubresource(req) assert.True(t, found, "%q should be reported as a subresource", query)