SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
s3api: ignore response header overrides on anonymous requests
Chris Lua4c8d31cb8b7
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.goindex c3da495139..f5e6b546cd 100644--- a/weed/s3api/s3api_object_handlers.go+++ b/weed/s3api/s3api_object_handlers.go@@ -2430,8 +2430,10 @@ func (s3a *S3ApiServer) setResponseHeaders(w http.ResponseWriter, r *http.Reques// Apply S3 passthrough headers from query parameters// AWS S3 supports overriding response headers via query parameters like:// ?response-cache-control=no-cache&response-content-type=application/json- // This allows presigned URLs to control how browsers handle the downloaded content- if r != nil {+ // This allows presigned URLs to control how browsers handle the downloaded content.+ // AWS requires the request to be signed; anonymous requests must not influence+ // how the stored object is served.+ if r != nil && getRequestAuthType(r) != authTypeAnonymous {for queryParam, headerValue := range r.URL.Query() {if normalizedHeader, ok := s3_constants.PassThroughHeaders[strings.ToLower(queryParam)]; ok && len(headerValue) > 0 && headerValue[0] != "" {w.Header().Set(normalizedHeader, headerValue[0])diff --git a/weed/s3api/s3api_object_handlers_conditional_read_test.go b/weed/s3api/s3api_object_handlers_conditional_read_test.goindex 1c4dd2dcd1..71e9acd94a 100644--- a/weed/s3api/s3api_object_handlers_conditional_read_test.go+++ b/weed/s3api/s3api_object_handlers_conditional_read_test.go@@ -238,3 +238,30 @@ func TestRemoteObjectETagFallback(t *testing.T) {t.Errorf("local object ETag = %q", got)}}++func TestSetResponseHeadersIgnoresOverridesForAnonymous(t *testing.T) {+ s3a := &S3ApiServer{}+ entry := &filer_pb.Entry{+ Name: "object",+ Attributes: &filer_pb.FuseAttributes{FileSize: 8, Mtime: 100},+ }+ for name, url := range map[string]string{+ "anonymous": "/bucket/object?response-content-type=text%2Fhtml&response-content-disposition=inline",+ "signed": "/bucket/object?response-content-type=text%2Fhtml&response-content-disposition=inline",+ "presigned": "/bucket/object?X-Amz-Credential=k&response-content-type=text%2Fhtml",+ } {+ r := httptest.NewRequest(http.MethodGet, url, nil)+ if name == "signed" {+ r.Header.Set("Authorization", "AWS4-HMAC-SHA256 Credential=k")+ }+ w := httptest.NewRecorder()+ s3a.setResponseHeaders(w, r, entry, 8)+ if name == "anonymous" {+ if got := w.Header().Get("Content-Disposition"); got != "" {+ t.Errorf("anonymous request must not override response headers, got Content-Disposition %q", got)+ }+ } else if got := w.Header().Get("Content-Type"); got != "text/html" {+ t.Errorf("%s request should apply response overrides, got Content-Type %q", name, got)+ }+ }+}