S3: quote ETag in CopyObject and UploadPartCopy XML responses (#11624)

* s3api: extract quoteETag from setEtag

Consolidate ETag quoting so the XML response builders can share it.

* s3api: quote ETag in CopyObjectResult XML

AWS returns the ETag quoted in the copy result body, matching the ETag header. Fixes seaweedfs/seaweedfs#11622

* s3api: quote ETag in CopyPartResult XML

UploadPartCopy returned the raw ETag in the XML body while the response header and other APIs return it quoted. Fixes seaweedfs/seaweedfs#11622

* s3api: test ETag quoting in copy responses

* s3api: assert quoted ETag on the wire in copy response tests

* s3api: use strconv.Quote in quoteETag

Addresses CodeQL 'potentially unsafe quoting' on string concatenation.
This commit is contained in:
Chris Lu authored and GitHub committed 2026-10-06 18:05:15 +08:00
1 parent cac6cd4b16
commit ec261c5fbc
4 files changed
+55 -15

No files matched your search

+8 -5
View File
@@ -1397,14 +1397,17 @@ func (s3a *S3ApiServer) resolveFileMode(r *http.Request) uint32 {
func setEtag(w http.ResponseWriter, etag string) {
if etag != "" {
if strings.HasPrefix(etag, "\"") {
w.Header()["ETag"] = []string{etag}
} else {
w.Header()["ETag"] = []string{"\"" + etag + "\""}
}
w.Header()["ETag"] = []string{quoteETag(etag)}
}
}
func quoteETag(etag string) string {
if etag == "" || strings.HasPrefix(etag, "\"") {
return etag
}
return strconv.Quote(etag)
}
// setSSEResponseHeaders sets appropriate SSE response headers based on encryption type
func (s3a *S3ApiServer) setSSEResponseHeaders(w http.ResponseWriter, r *http.Request, sseMetadata SSEResponseMetadata) {
switch sseMetadata.SSEType {