Files
seaweedfs/weed/s3api/s3api_subresource_ambiguity.go
T
Chris LuandDevin cec96c02ea s3: reject requests carrying more than one routed subresource (#11942)
* s3: reject requests carrying more than one routed subresource

Routing picks the first matching subresource route while authorization
resolves a single action from the query, and the two can disagree. A
bucket-level PUT ?tagging&policy is authorized as s3:PutBucketTagging but
served by PutBucketPolicyHandler, letting a tagger rewrite the bucket
policy; the same shape lets a list grant read the policy via
?list-type=2&policy or ?versions&policy, and lets an object ACL writer
retag via PUT ?acl&tagging. Declining ambiguous requests keeps the
authorized action and the served handler identical.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* s3: reuse hasAmbiguousSubresource in the routed-subresource guard

The standalone key list dropped versioning, so ?versioning&policy still
reached route matching and auth with two operations. The bucket-level
check already keys off operationSubresources plus bucketQueryActions;
running the same predicate keeps the lists from drifting apart.

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-21 22:45:53 -07:00

21 lines
599 B
Go

package s3api
import (
"net/http"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
)
// rejectAmbiguousSubresource applies the same one-operation-per-request rule
// validateRequestPath enforces inside bucket routes to the routes outside them,
// so the check runs once for every request the router serves.
func rejectAmbiguousSubresource(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if hasAmbiguousSubresource(r.URL.Query()) {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
return
}
next.ServeHTTP(w, r)
})
}