mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 18:18:02 -05:00
fix(s3): store x-amz-meta-* passed in a presigned URL query string (#4753)
* fix(s3): store x-amz-meta-* passed in a presigned URL query string Presigners such as the AWS SDK for JavaScript v3 hoist user metadata into the query string instead of sending it as headers. Read x-amz-meta-* from the query as well, with headers taking precedence. Fixes #4752 * fix(s3): prefer signed query metadata over unsigned headers The presigned URL signature covers x-amz-meta-* query parameters, so an unsigned header with the same key must not replace them. Also cover presigned CreateMultipartUpload and CopyObject with query metadata. * fix(s3): reject unsigned x-amz-meta-* headers on presigned requests S3 requires every x-amz-* header sent with a presigned URL to be listed in X-Amz-SignedHeaders and answers HeadersNotSigned otherwise. Apply the existing unsigned checksum header check to user metadata headers too.
This commit is contained in:
1 parent
75b56d49e2
commit
419e840260
4 files changed
+168
-18
No files matched your search
@@ -156,7 +156,7 @@ class PreSignedUrlFilterTest {
|
||||
"x-amz-checksum-sha1",
|
||||
"x-amz-checksum-sha256",
|
||||
"x-amz-sdk-checksum-algorithm"),
|
||||
PreSignedUrlFilter.unsignedChecksumHeaders(
|
||||
PreSignedUrlFilter.unsignedHeadersRequiringSignature(
|
||||
Set.of(
|
||||
"Host",
|
||||
"X-Amz-Checksum-Algorithm",
|
||||
@@ -173,18 +173,27 @@ class PreSignedUrlFilterTest {
|
||||
void acceptsChecksumHeadersIncludedInSignedHeaders() {
|
||||
assertEquals(
|
||||
List.of(),
|
||||
PreSignedUrlFilter.unsignedChecksumHeaders(
|
||||
PreSignedUrlFilter.unsignedHeadersRequiringSignature(
|
||||
Set.of("host", "x-amz-checksum-algorithm", "x-amz-checksum-crc32",
|
||||
"x-amz-checksum-sha256", "x-amz-sdk-checksum-algorithm"),
|
||||
"host;x-amz-checksum-algorithm;x-amz-checksum-crc32;"
|
||||
+ "x-amz-checksum-sha256;x-amz-sdk-checksum-algorithm"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reportsUnsignedUserMetadataHeaders() {
|
||||
assertEquals(
|
||||
List.of("x-amz-meta-source"),
|
||||
PreSignedUrlFilter.unsignedHeadersRequiringSignature(
|
||||
Set.of("host", "X-Amz-Meta-Source", "x-amz-meta-signed"),
|
||||
"host;x-amz-meta-signed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ignoresHeadersOutsideChecksumFamily() {
|
||||
assertEquals(
|
||||
List.of(),
|
||||
PreSignedUrlFilter.unsignedChecksumHeaders(
|
||||
PreSignedUrlFilter.unsignedHeadersRequiringSignature(
|
||||
Set.of("content-type", "user-agent", "x-amz-content-sha256",
|
||||
"x-amz-user-agent", "x-amz-checksum-type"),
|
||||
"host"));
|
||||
|
||||
+129
@@ -212,6 +212,135 @@ class S3PresignedChecksumIntegrationTest {
|
||||
.header("x-amz-checksum-sha256", equalTo(expectedSha256));
|
||||
}
|
||||
|
||||
@Test
|
||||
void presignedPutWithUserMetadataInQueryStoresTheMetadata() throws Exception {
|
||||
createBucket();
|
||||
String path = "/" + BUCKET + "/query-metadata.txt";
|
||||
String url = presign("PUT", path,
|
||||
Map.of("x-amz-meta-source", "presigned-put", "x-amz-meta-Uploaded-By", "tester"), Map.of());
|
||||
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.body("x".getBytes(StandardCharsets.UTF_8))
|
||||
.when()
|
||||
.put(url)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.when()
|
||||
.head(path)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-meta-source", equalTo("presigned-put"))
|
||||
.header("x-amz-meta-uploaded-by", equalTo("tester"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void presignedPutWithUnsignedMetadataHeaderIsRejectedAsHeadersNotSigned() throws Exception {
|
||||
createBucket();
|
||||
String path = "/" + BUCKET + "/unsigned-metadata-header.txt";
|
||||
String url = presign("PUT", path, Map.of("x-amz-meta-source", "signed"), Map.of());
|
||||
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.header("x-amz-meta-source", "altered")
|
||||
.body("x".getBytes(StandardCharsets.UTF_8))
|
||||
.when()
|
||||
.put(url)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("<Code>AccessDenied</Code>"))
|
||||
.body(containsString("<HeadersNotSigned>x-amz-meta-source</HeadersNotSigned>"));
|
||||
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.when()
|
||||
.head(path)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void presignedCreateMultipartUploadWithUserMetadataInQueryStoresTheMetadata() throws Exception {
|
||||
createBucket();
|
||||
String path = "/" + BUCKET + "/multipart-query-metadata.txt";
|
||||
String initiateUrl = presign("POST", path,
|
||||
Map.of("uploads", "", "x-amz-meta-source", "presigned-multipart"), Map.of());
|
||||
|
||||
String uploadId = given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.post(initiateUrl)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
String etag = given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.body("part".getBytes(StandardCharsets.UTF_8))
|
||||
.when()
|
||||
.put(path + "?partNumber=1&uploadId=" + uploadId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().header("ETag");
|
||||
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.body("<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>" + etag
|
||||
+ "</ETag></Part></CompleteMultipartUpload>")
|
||||
.when()
|
||||
.post(path + "?uploadId=" + uploadId)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.when()
|
||||
.head(path)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-meta-source", equalTo("presigned-multipart"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void presignedCopyObjectWithReplacedUserMetadataInQueryStoresTheMetadata() throws Exception {
|
||||
createBucket();
|
||||
String sourcePath = "/" + BUCKET + "/metadata-copy-source.txt";
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.header("x-amz-meta-source", "original")
|
||||
.body("copy me".getBytes(StandardCharsets.UTF_8))
|
||||
.when()
|
||||
.put(sourcePath)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String destPath = "/" + BUCKET + "/metadata-copy-dest.txt";
|
||||
String copyUrl = presign("PUT", destPath,
|
||||
Map.of("x-amz-meta-source", "copied"),
|
||||
Map.of("x-amz-copy-source", sourcePath, "x-amz-metadata-directive", "REPLACE"));
|
||||
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.header("x-amz-copy-source", sourcePath)
|
||||
.header("x-amz-metadata-directive", "REPLACE")
|
||||
.when()
|
||||
.put(copyUrl)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.when()
|
||||
.head(destPath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-meta-source", equalTo("copied"));
|
||||
}
|
||||
|
||||
private static void createBucket() {
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
|
||||
Reference in new issue
Block a user