fix(iam): read tagged resource ARNs with a blank content type (#9718)

ResourceArnBuilder handed ctx.getMediaType() to RequestBodyReader when
reading a JSON body, and the request context throws parsing a blank
Content-Type, so the read fell into its catch and a tag call's ARN in
the body went unread. It now reads the media type through
ResteasyRequests.mediaType, which takes a blank header as none, as the
request filters already do, and the body stays readable by the
handler.
This commit is contained in:
Jackson Price authored and GitHub committed 2026-11-28 23:32:26 -04:00
1 parent 9ee65d1e71
commit f592270705
2 files changed
+17 -1

No files matched your search

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.common.AwsRegions;
import io.floci.aws.core.common.RequestPathLabels;
import io.floci.aws.core.common.RequestResources;
import io.floci.aws.core.common.ResteasyRequests;
import io.floci.aws.core.common.StoredResourceArns;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
@@ -229,7 +230,7 @@ public class ResourceArnBuilder {
return null;
}
try {
JsonNode node = RequestBodyReader.readTree(body, ctx.getMediaType(), objectMapper);
JsonNode node = RequestBodyReader.readTree(body, ResteasyRequests.mediaType(ctx), objectMapper);
ctx.setProperty("floci.bufferedJsonBody", node);
return node;
} catch (Exception e) {
@@ -44,6 +44,7 @@ import io.vertx.ext.web.RoutingContext;
import jakarta.enterprise.inject.Instance;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
@@ -2792,6 +2793,20 @@ class ResourceArnBuilderTest {
assertNull(builder.taggedArn(ctx));
}
@Test
void taggedArnReadsTheJsonBodyWithABlankContentType() throws IOException {
String arn = "arn:aws:pipes:us-east-1:" + ACCOUNT + ":pipe/orders";
String json = "{\"resourceArn\":\"" + arn + "\"}";
setJsonBody(json);
when(uriInfo.getPath()).thenReturn("/tags");
when(ctx.getMethod()).thenReturn("POST");
when(ctx.getHeaderString(HttpHeaders.CONTENT_TYPE)).thenReturn(" ");
assertEquals(arn, builder.taggedArn(ctx));
assertEquals(json, new String(ctx.getEntityStream().readAllBytes(), StandardCharsets.UTF_8));
verify(ctx, never()).getMediaType();
}
/** A tag route names the resource by its ARN, which keeps its account and Region beside the caller's. */
@Test
void lambdaTagRoutesNameTheResourceTheirArnNames() {