mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): reject unsigned checksum headers on presigned requests (#4153)
Match S3 behavior by requiring supported x-amz-checksum-* headers to be included in X-Amz-SignedHeaders. Return AccessDenied with HeadersNotSigned when a presigned request includes an unsigned checksum header.
This commit is contained in:
1 parent
7eafd2f706
commit
343e1574fa
4 files changed
+270
No files matched your search
@@ -7,6 +7,8 @@ import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
@@ -142,4 +144,49 @@ class PreSignedUrlFilterTest {
|
||||
"X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20260101T000000Z",
|
||||
PreSignedUrlFilter.buildCanonicalQueryString(params));
|
||||
}
|
||||
|
||||
@Test
|
||||
void identifiesUnsignedChecksumHeadersCaseInsensitively() {
|
||||
assertEquals(
|
||||
List.of(
|
||||
"x-amz-checksum-algorithm",
|
||||
"x-amz-checksum-crc32",
|
||||
"x-amz-checksum-crc32c",
|
||||
"x-amz-checksum-crc64nvme",
|
||||
"x-amz-checksum-sha1",
|
||||
"x-amz-checksum-sha256",
|
||||
"x-amz-sdk-checksum-algorithm"),
|
||||
PreSignedUrlFilter.unsignedChecksumHeaders(
|
||||
Set.of(
|
||||
"Host",
|
||||
"X-Amz-Checksum-Algorithm",
|
||||
"X-Amz-Checksum-CRC32",
|
||||
"X-Amz-Checksum-CRC32C",
|
||||
"X-Amz-Checksum-CRC64NVME",
|
||||
"X-Amz-Checksum-SHA1",
|
||||
"X-Amz-Checksum-SHA256",
|
||||
"X-Amz-SDK-Checksum-Algorithm"),
|
||||
"host"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsChecksumHeadersIncludedInSignedHeaders() {
|
||||
assertEquals(
|
||||
List.of(),
|
||||
PreSignedUrlFilter.unsignedChecksumHeaders(
|
||||
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 ignoresHeadersOutsideChecksumFamily() {
|
||||
assertEquals(
|
||||
List.of(),
|
||||
PreSignedUrlFilter.unsignedChecksumHeaders(
|
||||
Set.of("content-type", "user-agent", "x-amz-content-sha256",
|
||||
"x-amz-user-agent", "x-amz-checksum-type"),
|
||||
"host"));
|
||||
}
|
||||
}
|
||||
+43
@@ -668,6 +668,49 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.body(containsString("SignatureDoesNotMatch"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
void presignedPutWithUnsignedChecksumHeaderIsRejected() {
|
||||
String bucket = "auth-presigned-checksum-bucket";
|
||||
String key = "part.bin";
|
||||
String path = "/" + bucket + "/" + key;
|
||||
given().filter(LOCAL_SIGNER).when().put("/" + bucket).then().statusCode(200);
|
||||
|
||||
try {
|
||||
String signature = presignedSignature("PUT", path, "test", "test", "3600");
|
||||
Map<String, String> checksumHeaders = Map.of(
|
||||
"x-amz-checksum-algorithm", "CRC32",
|
||||
"x-amz-checksum-crc32", "y/Q5Jg==",
|
||||
"x-amz-checksum-crc32c", "4waSgw==",
|
||||
"x-amz-checksum-crc64nvme", "rosUhgp5mIg=",
|
||||
"x-amz-checksum-sha1", "98O8HYCOBHMq32eZZczDTKeuNEE=",
|
||||
"x-amz-checksum-sha256", "FeKw08M4keuw8e9gnsQZQgwg4yDOlMZfvIwzEkSOsiU=",
|
||||
"x-amz-sdk-checksum-algorithm", "CRC32");
|
||||
for (Map.Entry<String, String> checksum : checksumHeaders.entrySet()) {
|
||||
presignedRequest(signature)
|
||||
.header(checksum.getKey(), checksum.getValue())
|
||||
.body("123456789")
|
||||
.when()
|
||||
.put(path)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body("Error.Code", equalTo("AccessDenied"))
|
||||
.body("Error.Message", equalTo(
|
||||
"There were headers present in the request which were not signed"))
|
||||
.body("Error.HeadersNotSigned", equalTo(checksum.getKey()));
|
||||
}
|
||||
|
||||
given()
|
||||
.filter(LOCAL_SIGNER)
|
||||
.when()
|
||||
.get(path)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
} finally {
|
||||
given().filter(LOCAL_SIGNER).when().delete("/" + bucket);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
void presignedRequestWithExpiresExceedingMaxIsRejected() {
|
||||
|
||||
Reference in new issue
Block a user