fix(s3): reject response-* overrides on unsigned requests (#1098)

* fix(s3): reject response-* overrides on unsigned requests

AWS S3 requires a signed request (Authorization header or presigned URL)
when any of the six response-* query parameters are present. Unsigned
requests with these parameters were silently honoured, diverging from
real S3 behaviour in a way that would only surface in production.

Confirmed against real S3: HTTP 400, Code=InvalidRequest,
"Request specific response headers cannot be used for anonymous GET requests."

Adds hasAny() to ResponseHeaderOverrides and an isSigned() check
(Authorization header or X-Amz-Algorithm query param) applied to both
GetObject and HeadObject before the overrides are applied.

Closes #918

* fix(s3): sign response-* override tests to match AWS requirement

PreSignedUrlIntegrationTest orders 11, 12, 14, and 16 made anonymous
requests with response-* query params and expected 200. These tests now
correctly reflect the AWS requirement that response-* overrides must be
on a signed request — anonymous requests must be rejected (closes #918).
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-05-30 16:04:51 -05:00
1 parent c7a4ef37f1
commit 9b7f8e40f0
3 files changed
+226 -1

No files matched your search

@@ -19,6 +19,9 @@ class PreSignedUrlIntegrationTest {
private static final String BUCKET = "presign-test-bucket";
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/s3/aws4_request";
@Inject
PreSignedUrlGenerator presignGenerator;
@@ -138,8 +141,10 @@ class PreSignedUrlIntegrationTest {
@Order(11)
void getObjectAppliesResponseContentDispositionOverride() {
// Stored disposition is "inline"; override should win.
// Must be a signed request per AWS spec (response-* params require Authorization or presigned URL).
given()
.urlEncodingEnabled(false)
.header("Authorization", AUTH_HEADER)
.when()
.get("/" + BUCKET + "/disposition-file.txt?response-content-disposition=attachment%3B%20filename%3D%22file.txt%22")
.then()
@@ -152,6 +157,7 @@ class PreSignedUrlIntegrationTest {
void getObjectAppliesAllResponseOverrides() {
given()
.urlEncodingEnabled(false)
.header("Authorization", AUTH_HEADER)
.when()
.get("/" + BUCKET + "/disposition-file.txt"
+ "?response-content-type=application%2Fpdf"
@@ -187,6 +193,7 @@ class PreSignedUrlIntegrationTest {
void headObjectAppliesResponseContentDispositionOverride() {
given()
.urlEncodingEnabled(false)
.header("Authorization", AUTH_HEADER)
.when()
.head("/" + BUCKET + "/disposition-file.txt?response-content-disposition=attachment%3B%20filename%3D%22head.txt%22")
.then()
@@ -212,6 +219,7 @@ class PreSignedUrlIntegrationTest {
void rangeRequestAppliesResponseContentDispositionOverride() {
given()
.urlEncodingEnabled(false)
.header("Authorization", AUTH_HEADER)
.header("Range", "bytes=0-3")
.when()
.get("/" + BUCKET + "/disposition-file.txt?response-content-disposition=attachment%3B%20filename%3D%22range.txt%22")
@@ -0,0 +1,198 @@
package io.github.hectorvent.floci.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
/**
* Verifies response-* header override behaviour on GetObject / HeadObject.
*
* Empirically confirmed against real AWS S3:
* HTTP 400, Code=InvalidRequest,
* Message="Request specific response headers cannot be used for anonymous GET requests."
*
* Unsigned requests that supply any response-* query parameter must be rejected.
* Signed requests (Authorization header present) must be accepted and the override
* applied to the response.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class S3ResponseHeaderOverrideIntegrationTest {
private static final String BUCKET = "response-override-test-bucket";
private static final String KEY = "test-object.txt";
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/s3/aws4_request";
@Test
@Order(1)
void setup_createBucketAndObject() {
given().put("/" + BUCKET).then().statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.contentType("text/plain")
.body("hello")
.put("/" + BUCKET + "/" + KEY)
.then().statusCode(200);
}
// ── Anonymous requests must be rejected (400 InvalidRequest) ─────────────
@Test
@Order(2)
void anonymousGetWithResponseCacheControl_returns400() {
given()
.queryParam("response-cache-control", "no-cache")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400)
.body(containsString("InvalidRequest"))
.body(containsString("anonymous GET requests"));
}
@Test
@Order(3)
void anonymousGetWithResponseContentType_returns400() {
given()
.queryParam("response-content-type", "text/html")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400)
.body(containsString("InvalidRequest"));
}
@Test
@Order(4)
void anonymousGetWithResponseContentDisposition_returns400() {
given()
.queryParam("response-content-disposition", "attachment; filename=x.txt")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400)
.body(containsString("InvalidRequest"));
}
@Test
@Order(5)
void anonymousGetWithResponseContentEncoding_returns400() {
given()
.queryParam("response-content-encoding", "gzip")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400)
.body(containsString("InvalidRequest"));
}
@Test
@Order(6)
void anonymousGetWithResponseContentLanguage_returns400() {
given()
.queryParam("response-content-language", "en-US")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400)
.body(containsString("InvalidRequest"));
}
@Test
@Order(7)
void anonymousGetWithResponseExpires_returns400() {
given()
.queryParam("response-expires", "Thu, 01 Jan 2099 00:00:00 GMT")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400)
.body(containsString("InvalidRequest"));
}
@Test
@Order(8)
void anonymousHeadWithResponseCacheControl_returns400() {
given()
.queryParam("response-cache-control", "no-cache")
.when()
.head("/" + BUCKET + "/" + KEY)
.then()
.statusCode(400);
}
// ── Signed requests must be accepted and the override applied ────────────
@Test
@Order(9)
void signedGetWithResponseCacheControl_appliesOverride() {
given()
.header("Authorization", AUTH_HEADER)
.queryParam("response-cache-control", "max-age=3600")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(200)
.header("Cache-Control", equalTo("max-age=3600"));
}
@Test
@Order(10)
void signedGetWithResponseContentType_appliesOverride() {
given()
.header("Authorization", AUTH_HEADER)
.queryParam("response-content-type", "application/octet-stream")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(200)
.header("Content-Type", containsString("application/octet-stream"));
}
@Test
@Order(11)
void signedGetWithResponseContentDisposition_appliesOverride() {
given()
.header("Authorization", AUTH_HEADER)
.queryParam("response-content-disposition", "attachment; filename=download.txt")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(200)
.header("Content-Disposition", equalTo("attachment; filename=download.txt"));
}
// ── Anonymous request without response-* params must still work ──────────
@Test
@Order(12)
void anonymousGetWithoutOverrides_returns200() {
given()
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(200);
}
// ── Empty response-* values are ignored (not treated as present) ─────────
@Test
@Order(13)
void anonymousGetWithEmptyResponseCacheControl_returns200() {
// Real S3 ignores ?response-cache-control= (empty value) — should not reject.
given()
.queryParam("response-cache-control", "")
.when()
.get("/" + BUCKET + "/" + KEY)
.then()
.statusCode(200);
}
}