mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(s3): honor x-amz-tagging query parameter on presigned PutObject and CreateMultipartUpload (#3615)
* fix(s3): honor x-amz-tagging query parameter on presigned PutObject and CreateMultipartUpload SDK presigners hoist x-amz-tagging into the query string and sign only host, so the uploader sends no tagging header at all. Floci read the tags only from the header and silently dropped them: the PUT returned 200 and GetObjectTagging came back with an empty TagSet, while real S3 applies both forms. Fall back to the x-amz-tagging query parameter when the header is absent, for PutObject and for CreateMultipartUpload. The signed header still wins when both are present. JAX-RS decodes the query value once, which yields the same URL-encoded k=v&k=v string the header carries, so the existing parser is reused unchanged. Closes #3608 * test(s3): verify the presigned x-amz-tagging query fallback under SigV4 enforcement The tests added with the fix run with signature validation off and append x-amz-tagging to an already generated URL, so they show the fallback works but not that a genuinely SigV4-signed presigned request reaches it. Add an enforce-auth companion class that builds URLs the way SDK presigners do, with every query parameter in the canonical query string and only the listed headers covered by the signature, and checks that: - a presigned PUT with x-amz-tagging in the signed query applies the tags - a presigned CreateMultipartUpload with x-amz-tagging in the signed query applies the tags to the completed object - a signed x-amz-tagging header wins over the query parameter - a tag parameter appended after signing is rejected with SignatureDoesNotMatch
This commit is contained in:
1 parent
38056a00f6
commit
52bafb7e5c
3 files changed
+415
-4
No files matched your search
@@ -812,7 +812,7 @@ public class S3Controller {
|
||||
return handleCopyObject(copySource, bucket, key, contentType, httpHeaders, authorization);
|
||||
}
|
||||
|
||||
Map<String, String> inlineTags = parseInlineTaggingHeader(tagging);
|
||||
Map<String, String> inlineTags = parseInlineTaggingHeader(resolveInlineTaggingSource(tagging, uriInfo));
|
||||
|
||||
String lockMode = httpHeaders.getHeaderString("x-amz-object-lock-mode");
|
||||
String retainUntilStr = httpHeaders.getHeaderString("x-amz-object-lock-retain-until-date");
|
||||
@@ -1388,7 +1388,8 @@ public class S3Controller {
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"),
|
||||
getChecksumAlgorithm(httpHeaders),
|
||||
httpHeaders.getHeaderString("x-amz-checksum-type"),
|
||||
parseInlineTaggingHeader(httpHeaders.getHeaderString("x-amz-tagging")));
|
||||
parseInlineTaggingHeader(
|
||||
resolveInlineTaggingSource(httpHeaders.getHeaderString("x-amz-tagging"), uriInfo)));
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("InitiateMultipartUploadResult", AwsNamespaces.S3)
|
||||
@@ -3606,8 +3607,24 @@ public class S3Controller {
|
||||
private static final int MAX_INLINE_TAGGING_HEADER_BYTES = 8 * 1024;
|
||||
|
||||
/**
|
||||
* Parses an {@code x-amz-tagging} request-header value (URL-encoded
|
||||
* {@code k=v&k=v}) into a tag map. Returns an empty map for null or blank input.
|
||||
* Resolves the inline {@code x-amz-tagging} value for PutObject and CreateMultipartUpload.
|
||||
* The signed request header wins; otherwise the value comes from the {@code x-amz-tagging}
|
||||
* query parameter, where SDK presigners hoist the header while signing only {@code host}.
|
||||
* JAX-RS decodes the query value once, which yields the same URL-encoded {@code k=v&k=v}
|
||||
* string the header form carries, so both sources feed
|
||||
* {@link #parseInlineTaggingHeader(String)} unchanged. Real S3 honors both forms.
|
||||
*/
|
||||
private static String resolveInlineTaggingSource(String taggingHeader, UriInfo uriInfo) {
|
||||
if (taggingHeader != null) {
|
||||
return taggingHeader;
|
||||
}
|
||||
return uriInfo.getQueryParameters().getFirst("x-amz-tagging");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an {@code x-amz-tagging} value (URL-encoded {@code k=v&k=v}), taken from the
|
||||
* request header or the presigned-URL query parameter, into a tag map. Returns an empty
|
||||
* map for null or blank input.
|
||||
*
|
||||
* <p>Note: the error codes thrown here ({@code InvalidArgument} for malformed input,
|
||||
* {@code BadRequest} for exceeding the 10-tag limit) match real-AWS S3 behavior
|
||||
|
||||
Reference in new issue
Block a user