Browse Source
Fix: S3 CORS headers missing for non-existent buckets (#8078 )
Fix S3 CORS for non-existent buckets
Enable fallback to global CORS configuration when a bucket is not found (s3err.ErrNoSuchBucket). This ensures consistent CORS behavior and prevents information disclosure.
pull/8079/head
Chris Lu
2 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
6 additions and
3 deletions
weed/s3api/cors/middleware.go
weed/s3api/cors/middleware_test.go
@ -50,6 +50,9 @@ func (m *Middleware) getCORSConfig(bucket string) (*CORSConfiguration, bool) {
// No bucket config, proceed to fallback.
case s3err . ErrNoSuchCORSConfiguration :
// No bucket config, proceed to fallback.
case s3err . ErrNoSuchBucket :
// Bucket doesn't exist, proceed to fallback.
// This ensures we don't leak existence information and returning 403 vs 200.
default :
// Any other error means we should not proceed.
return nil , false
@ -358,10 +358,10 @@ func TestMiddlewareFallbackWithError(t *testing.T) {
description : "Internal errors should not expose CORS headers" ,
} ,
{
name : "ErrNoSuchBucket should not trigger fallback" ,
name : "ErrNoSuchBucket should trigger fallback" ,
errCode : s3err . ErrNoSuchBucket ,
expectedOriginHeader : "" ,
description : "Bucket not found errors should not expose CORS headers" ,
expectedOriginHeader : "https://example.com " ,
description : "Bucket not found errors should expose CORS headers to prevent information disclosure " ,
} ,
{
name : "ErrNoSuchCORSConfiguration should trigger fallback" ,