mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(core): handle blank content types in request filters (#9710)
Signed-off-by: Jackson Price <jxnprice@amazon.com>
This commit is contained in:
1 parent
82c82ec553
commit
403405f787
9 files changed
+51
-20
No files matched your search
@@ -1393,7 +1393,7 @@ public class IamConditionContextResolver {
|
||||
if (cached instanceof Map<?, ?> map) {
|
||||
return (Map<String, String>) map;
|
||||
}
|
||||
MediaType mediaType = ctx.getMediaType();
|
||||
MediaType mediaType = ResteasyRequests.mediaType(ctx);
|
||||
byte[] body = bufferEntity(ctx);
|
||||
if (body == null || body.length == 0) {
|
||||
return Map.of();
|
||||
@@ -1559,6 +1559,11 @@ public class IamConditionContextResolver {
|
||||
return cached instanceof JsonNode node ? node : null;
|
||||
}
|
||||
|
||||
private static boolean isLegacyDynamoDbMediaType(ContainerRequestContext ctx) {
|
||||
MediaType mediaType = ResteasyRequests.mediaType(ctx);
|
||||
return mediaType != null && mediaType.isCompatible(MediaType.valueOf("application/x-amz-json-1.0"));
|
||||
}
|
||||
|
||||
private DynamoDbConditionKeys.Result dynamoDbKeys(
|
||||
String action, JsonNode body, TableDefinition table, ContainerRequestContext ctx) {
|
||||
String target = ctx.getHeaderString("X-Amz-Target");
|
||||
@@ -1568,8 +1573,7 @@ public class IamConditionContextResolver {
|
||||
.filter(match -> "dynamodb".equals(match.descriptor().externalKey()))
|
||||
.filter(match -> match.action().equals(action.substring("dynamodb:".length())))
|
||||
.isPresent()
|
||||
&& ctx.getMediaType() != null
|
||||
&& ctx.getMediaType().isCompatible(MediaType.valueOf("application/x-amz-json-1.0"));
|
||||
&& isLegacyDynamoDbMediaType(ctx);
|
||||
return legacy ? DynamoDbConditionKeys.extractLegacy(action, body, table)
|
||||
: DynamoDbConditionKeys.extract(action, body, table);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class RequestLogFilter implements ContainerRequestFilter, ContainerRespon
|
||||
url,
|
||||
headerList(ctx.getHeaders()),
|
||||
queryStringList(ctx.getUriInfo().getQueryParameters()),
|
||||
mimeType(ctx.getMediaType()),
|
||||
mimeType(ResteasyRequests.mediaType(ctx)),
|
||||
callerAccessKeyId(ctx));
|
||||
ctx.setProperty(CAPTURE_PROPERTY, capture);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -474,7 +474,7 @@ public class SigV4HeaderSignatureFilter implements ContainerRequestFilter {
|
||||
CborErrorResponses.mediaTypeFor(contentType)));
|
||||
return;
|
||||
}
|
||||
if (isFormEncoded(ctx.getMediaType())
|
||||
if (isFormEncoded(ResteasyRequests.mediaType(ctx))
|
||||
|| ctx.getProperty(AwsProtocolClaimFilter.CLAIM_PROPERTY) instanceof ProtocolClaim claim
|
||||
&& claim.protocol() == WireProtocol.AWS_QUERY) {
|
||||
ctx.abortWith(AwsQueryResponse.error(queryCode, message, null, status));
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SqsQueueUrlRouterFilter implements ContainerRequestFilter {
|
||||
}
|
||||
}
|
||||
|
||||
MediaType mt = ctx.getMediaType();
|
||||
MediaType mt = ResteasyRequests.mediaType(ctx);
|
||||
if (mt == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.fis;
|
||||
import io.floci.aws.core.common.AwsQueryResponse;
|
||||
import io.floci.aws.core.common.Ec2ErrorResponses;
|
||||
import io.floci.aws.core.common.ProtocolErrorResponses;
|
||||
import io.floci.aws.core.common.ResteasyRequests;
|
||||
import io.floci.aws.core.common.ServiceDescriptor;
|
||||
import io.floci.aws.core.common.ServiceProtocol;
|
||||
import io.floci.aws.core.common.WireProtocol;
|
||||
@@ -44,7 +45,8 @@ final class FisApiErrors {
|
||||
return ProtocolErrorResponses.cbor(ctx, error.code(), error.message(), error.status());
|
||||
}
|
||||
boolean restXml = descriptor != null && descriptor.supportsProtocol(ServiceProtocol.REST_XML);
|
||||
if (restXml || protocol == WireProtocol.AWS_QUERY || ProtocolErrorResponses.isFormEncoded(ctx.getMediaType())) {
|
||||
if (restXml || protocol == WireProtocol.AWS_QUERY
|
||||
|| ProtocolErrorResponses.isFormEncoded(ResteasyRequests.mediaType(ctx))) {
|
||||
return AwsQueryResponse.error(error.code(), error.message(),
|
||||
descriptor == null ? null : descriptor.xmlNamespace(), error.status());
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import io.floci.aws.services.s3.S3ObjectActions;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ResourceInfo;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -444,10 +443,6 @@ public class IamActionRegistry {
|
||||
if (path != null && !path.isEmpty() && !"/".equals(path)) {
|
||||
return false;
|
||||
}
|
||||
MediaType mediaType = ctx.getMediaType();
|
||||
return "POST".equalsIgnoreCase(ctx.getMethod())
|
||||
&& mediaType != null
|
||||
&& "application".equalsIgnoreCase(mediaType.getType())
|
||||
&& "x-www-form-urlencoded".equalsIgnoreCase(mediaType.getSubtype());
|
||||
return "POST".equalsIgnoreCase(ctx.getMethod()) && RequestBodyReader.isForm(ctx);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package io.floci.aws.services.iam;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
|
||||
import io.floci.aws.core.common.ProtocolErrorResponses;
|
||||
import io.floci.aws.core.common.QueryFormDecoder;
|
||||
import io.floci.aws.core.common.ResteasyRequests;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -46,20 +48,17 @@ public final class RequestBodyReader {
|
||||
}
|
||||
|
||||
static boolean isForm(ContainerRequestContext ctx) {
|
||||
MediaType mt = ctx.getMediaType();
|
||||
return mt != null
|
||||
&& "application".equalsIgnoreCase(mt.getType())
|
||||
&& "x-www-form-urlencoded".equalsIgnoreCase(mt.getSubtype());
|
||||
return ProtocolErrorResponses.isFormEncoded(ResteasyRequests.mediaType(ctx));
|
||||
}
|
||||
|
||||
public static String formField(ContainerRequestContext ctx, String key) {
|
||||
if ("GET".equalsIgnoreCase(ctx.getMethod()) && IamActionRegistry.isQueryRequest(ctx)) {
|
||||
return ctx.getUriInfo().getQueryParameters().getFirst(key);
|
||||
}
|
||||
if (!isForm(ctx)) {
|
||||
MediaType mt = ResteasyRequests.mediaType(ctx);
|
||||
if (!ProtocolErrorResponses.isFormEncoded(mt)) {
|
||||
return null;
|
||||
}
|
||||
MediaType mt = ctx.getMediaType();
|
||||
byte[] body = buffer(ctx);
|
||||
if (body.length == 0) {
|
||||
return null;
|
||||
@@ -78,7 +77,7 @@ public final class RequestBodyReader {
|
||||
}
|
||||
|
||||
static String documentField(ContainerRequestContext ctx, ObjectMapper objectMapper, String key) {
|
||||
MediaType mt = ctx.getMediaType();
|
||||
MediaType mt = ResteasyRequests.mediaType(ctx);
|
||||
if (mt == null || !"application".equalsIgnoreCase(mt.getType())
|
||||
|| mt.getSubtype() == null || (!isCbor(mt) && !mt.getSubtype().startsWith("x-amz-json"))) {
|
||||
return null;
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.floci.aws.testutil.AwsRequestSigner;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
@@ -169,6 +170,20 @@ class SigV4HeaderSignatureIntegrationTest {
|
||||
.header("X-Amzn-Errortype", equalTo("InvalidSignatureException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankContentTypeKeepsTheRestJsonSignatureError() {
|
||||
given()
|
||||
.config(RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
|
||||
.header("Content-Type", "")
|
||||
.filter(AwsRequestSigner.signedAs("test", "not-the-secret", "scheduler"))
|
||||
.when()
|
||||
.get("/schedule-groups")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.header("X-Amzn-Errortype", equalTo("InvalidSignatureException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void pathWithEscapesVerifiesDoubleEncoded() {
|
||||
|
||||
@@ -92,6 +92,22 @@ class FisApiFaultFilterTest {
|
||||
response.getEntity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankContentTypeKeepsTheKinesisJsonFault() {
|
||||
faults(new FisApiFault(FisApiFault.Kind.UNAVAILABLE, "kinesis", Set.of("PutRecord"), 100,
|
||||
Set.of(TARGET_ROLE), FAR_FUTURE));
|
||||
resolvesTo("kinesis", "PutRecord");
|
||||
ContainerRequestContext ctx = request("kinesis", WireProtocol.AWS_JSON_1_1, null);
|
||||
when(ctx.getHeaderString("Content-Type")).thenReturn(" ");
|
||||
|
||||
Response response = abortedWith(ctx);
|
||||
|
||||
assertEquals(503, response.getStatus());
|
||||
assertEquals(new AwsErrorResponse("ServiceUnavailable", "The service is temporarily unavailable. "
|
||||
+ "Try again later."), response.getEntity());
|
||||
verify(ctx, never()).getMediaType();
|
||||
}
|
||||
|
||||
@Test
|
||||
void aKinesisCborCallGetsTheErrorInCbor() {
|
||||
faults(new FisApiFault(FisApiFault.Kind.UNAVAILABLE, "kinesis", Set.of("GetRecords"), 100,
|
||||
|
||||
Reference in new issue
Block a user