s3api: ignore custom x- query parameters on bucket requests (#13046)

This commit is contained in:
Chris Lu authored and GitHub committed 2026-11-27 02:42:37 -08:00
1 parent eb655f46ba
commit 781288cf11
2 files changed
+11 -8

No files matched your search

+7 -7
View File
@@ -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
}
@@ -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)