mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): accept a percent-encoded bucket/key separator in copy sources (#2060)
* fix(s3): accept a percent-encoded bucket/key separator in copy sources
The AWS SDK for .NET percent-encodes the whole x-amz-copy-source value, so a
v4 client sends `bucket%2Ffolder%2Fkey.txt` with no literal slash anywhere.
Splitting the raw header on indexOf('/') found no separator there, so every
CopyObject and UploadPartCopy from that SDK failed with 400 InvalidArgument,
including copies of top-level keys.
Treat whichever comes first, a literal '/' or an encoded %2F, as the
bucket/key separator. Bucket names admit neither '/' nor '%', so the first
occurrence of either is unambiguously the separator and never part of the
bucket name. The split still happens before decoding, so an encoded slash
inside a key stays key content and a literal '?' is still preserved.
Both handlers now share one parseCopySource helper rather than duplicating
the split.
Adds regression coverage for the fully-encoded .NET wire format, a lowercase
%2f, a leading encoded separator, the mixed encoded-separator/literal-slash
form, UploadPartCopy, and malformed encoding reached through an encoded
separator.
Closes #2038
* test(s3): verify the bytes copied through an encoded separator
The encoded-separator UploadPartCopy part was uploaded but left out of
CompleteMultipartUpload, so the test only proved the request returned 200,
not that the encoded source resolved to the same object.
Complete the part and assert the trailing slice, so a parse that resolved the
wrong key would fail on content rather than pass on status.
This commit is contained in:
3 files changed
+174
-20
No files matched your search
@@ -479,6 +479,64 @@ class S3IntegrationTest {
|
||||
given().delete("/" + bucket);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(119)
|
||||
void copyObjectWithPercentEncodedBucketSeparatorSucceeds() {
|
||||
// The AWS SDK for .NET percent-encodes the whole copy source, so a v4 client sends
|
||||
// "bucket%2Ffolder%2Fkey.txt" with no literal slash anywhere in the header.
|
||||
String bucket = "copy-encoded-separator-bucket";
|
||||
String srcKey = "folder/file.txt";
|
||||
|
||||
given().put("/" + bucket).then().statusCode(200);
|
||||
given()
|
||||
.contentType("text/plain")
|
||||
.body("encoded separator")
|
||||
.when()
|
||||
.put("/" + bucket + "/" + srcKey)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Fully encoded, no leading separator: the .NET wire format.
|
||||
given()
|
||||
.header("x-amz-copy-source", bucket + "%2Ffolder%2Ffile.txt")
|
||||
.when()
|
||||
.put("/" + bucket + "/copied/dotnet.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
// Lowercase %2f, and a leading encoded separator, name the same object.
|
||||
given()
|
||||
.header("x-amz-copy-source", "%2F" + bucket + "%2ffolder%2ffile.txt")
|
||||
.when()
|
||||
.put("/" + bucket + "/copied/lowercase.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
// Mixed: encoded bucket separator, literal slash inside the key.
|
||||
given()
|
||||
.header("x-amz-copy-source", bucket + "%2Ffolder/file.txt")
|
||||
.when()
|
||||
.put("/" + bucket + "/copied/mixed.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
for (String copied : new String[] {"dotnet", "lowercase", "mixed"}) {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "/copied/" + copied + ".txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("encoded separator"));
|
||||
given().delete("/" + bucket + "/copied/" + copied + ".txt");
|
||||
}
|
||||
|
||||
given().delete("/" + bucket + "/" + srcKey);
|
||||
given().delete("/" + bucket);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(120)
|
||||
void copyObjectWithQuestionMarkInSourceKeySucceeds() {
|
||||
@@ -550,6 +608,15 @@ class S3IntegrationTest {
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidArgument"));
|
||||
|
||||
// Decoding still rejects a malformed key reached through an encoded separator.
|
||||
given()
|
||||
.header("x-amz-copy-source", "test-bucket%2F%ZZinvalid")
|
||||
.when()
|
||||
.put("/test-bucket/dest-key")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidArgument"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -562,6 +629,23 @@ class S3IntegrationTest {
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidArgument"));
|
||||
|
||||
// A source with no separator at all names no bucket, encoded form included.
|
||||
given()
|
||||
.header("x-amz-copy-source", "key-only-no-bucket")
|
||||
.when()
|
||||
.put("/test-bucket/dest-key")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidArgument"));
|
||||
|
||||
given()
|
||||
.header("x-amz-copy-source", "%2Fkey-only-no-bucket")
|
||||
.when()
|
||||
.put("/test-bucket/dest-key")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidArgument"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+17
-2
@@ -247,11 +247,24 @@ class S3MultipartIntegrationTest {
|
||||
.body(containsString("<CopyPartResult"))
|
||||
.body(containsString("<ETag>"));
|
||||
|
||||
// Percent-encoded bucket/key separator: the AWS SDK for .NET encodes the whole
|
||||
// copy source, so the header carries no literal slash.
|
||||
given()
|
||||
.header("x-amz-copy-source", BUCKET + "%2Fsource-for-copy.bin")
|
||||
.header("x-amz-copy-source-range", "bytes=2-5")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/copy-dest.bin?uploadId=" + copyUploadId + "&partNumber=3")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CopyPartResult"))
|
||||
.body(containsString("<ETag>"));
|
||||
|
||||
// Complete the upload
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>etag1</ETag></Part>
|
||||
<Part><PartNumber>2</PartNumber><ETag>etag2</ETag></Part>
|
||||
<Part><PartNumber>3</PartNumber><ETag>etag3</ETag></Part>
|
||||
</CompleteMultipartUpload>""";
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
@@ -261,13 +274,15 @@ class S3MultipartIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Verify contents: full source + ranged slice
|
||||
// Verify contents: full source, ranged slice, then the same slice copied
|
||||
// through the percent-encoded separator. The last four bytes prove the
|
||||
// encoded source resolved to the same object, not just that it returned 200.
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/copy-dest.bin")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("ABCDEFGHIJCDEF"));
|
||||
.body(equalTo("ABCDEFGHIJCDEFCDEF"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user