fix(swf): accept legacy JSON target headers (#5728)

* fix(swf): accept legacy JSON target headers

Signed-off-by: Andre Kurait <akurait@amazon.com>

* fix(swf): reject unsupported CBOR and clarify missing targets

Signed-off-by: Andre Kurait <akurait@amazon.com>

* refactor(protocol): declare targeted plain JSON in the service catalog

Signed-off-by: Andre Kurait <akurait@amazon.com>

---------

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-15 22:05:37 -04:00
1 parent eca2199de6
commit 209ecd799b
12 files changed
+265 -5

No files matched your search

@@ -393,7 +393,7 @@ public class AwsJsonCborController {
}
// Symmetric with the JSON 1.0/1.1 controllers: a target this controller cannot
// resolve is an unknown operation, not an empty 204. The 204 fallback now applies
// dispatch is an unknown operation, not an empty 204. The 204 fallback now applies
// only to a resolved service whose action this handler does not dispatch.
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
if (targetMatch == null) {
@@ -420,7 +420,7 @@ public class AwsJsonCborController {
case "kinesis" -> kinesisJsonHandler.handle(action, request, region);
case "states" -> sfnJsonHandler.handle(action, request, region);
case "monitoring" -> cloudWatchMetricsJsonHandler.handle(action, request, region);
default -> null;
default -> throw new AwsException("UnknownOperationException", "Unknown operation: " + target, 404);
};
if (delegated == null) {
return null;
@@ -93,6 +93,28 @@ public class AwsJsonController {
this.timestreamInfluxDbJsonHandler = timestreamInfluxDbJsonHandler;
}
/**
* Accept plain JSON only for catalog descriptors declaring that format.
* Keep the wire headers intact and delegate to the same JSON handler.
*/
@POST
@Consumes("application/json")
@Produces("application/json")
public Response handlePlainJsonRequest(
@HeaderParam("X-Amz-Target") String target,
@Context HttpHeaders httpHeaders,
String body) {
if (target == null) {
return JsonErrorResponseUtils.createMissingTargetErrorResponse();
}
if (catalog.matchPlainJsonTarget(target).isEmpty()) {
return JsonErrorResponseUtils.createUnknownOperationErrorResponse(target);
}
return Response.fromResponse(handleJsonRequest(target, httpHeaders, body))
.type("application/json")
.build();
}
@POST
@Consumes(CONTENT_TYPE_AWS_JSON_1_0)
@Produces(CONTENT_TYPE_AWS_JSON_1_0)
@@ -110,6 +110,9 @@ public class ProtocolClaimer {
if (CONTENT_TYPE_JSON_1_1.equals(mediaType)) {
return Optional.of(targetClaim(WireProtocol.AWS_JSON_1_1, target));
}
if ("application/json".equals(mediaType) && catalog.matchPlainJsonTarget(target).isPresent()) {
return Optional.of(targetClaim(WireProtocol.AWS_JSON_1_0, target));
}
if (isCbor(mediaType)) {
return Optional.of(targetClaim(WireProtocol.AWS_CBOR_TARGET, target));
}
@@ -82,6 +82,7 @@ import io.github.hectorvent.floci.services.ses.SesTemplateController;
import io.github.hectorvent.floci.services.ses.SesTenantController;
import io.github.hectorvent.floci.services.ssooidc.SsoOidcController;
import io.github.hectorvent.floci.services.ssoportal.SsoPortalController;
import io.github.hectorvent.floci.services.swf.model.SwfConstants;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -294,8 +295,9 @@ public class ResolvedServiceCatalog {
Set.of("AWSStepFunctions."), Set.of("states"), Set.of("SFN"), Set.of()),
descriptor("swf", "swf", config.services().swf().enabled(), true,
"swf", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("SimpleWorkflowService."), Set.of("swf"), Set.of(), Set.of()),
protocols(ServiceProtocol.JSON, ServiceProtocol.PLAIN_JSON),
Set.of(SwfConstants.TARGET_PREFIX, SwfConstants.LEGACY_TARGET_PREFIX),
Set.of("swf"), Set.of(), Set.of()),
descriptor("cloudformation", "cloudformation", config.services().cloudformation().enabled(), true,
null, null, 5000L, null, ServiceProtocol.QUERY,
protocols(ServiceProtocol.QUERY),
@@ -793,6 +795,10 @@ public class ResolvedServiceCatalog {
return catalog.matchTarget(target);
}
public Optional<ServiceCatalog.TargetMatch> matchPlainJsonTarget(String target) {
return catalog.matchPlainJsonTarget(target);
}
public Optional<ServiceDescriptor> byCredentialScope(String credentialScope) {
return catalog.byCredentialScope(credentialScope);
}
@@ -111,6 +111,12 @@ public class ServiceCatalog {
return matchTarget(target).map(TargetMatch::descriptor);
}
/** Targeted application/json requests are accepted only by descriptors declaring that format. */
public Optional<TargetMatch> matchPlainJsonTarget(String target) {
return matchTarget(target)
.filter(match -> match.descriptor().supportsProtocol(ServiceProtocol.PLAIN_JSON));
}
public List<ServiceDescriptor> all() {
return all;
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.core.common;
public enum ServiceProtocol {
QUERY,
JSON,
PLAIN_JSON,
CBOR,
REST_JSON,
REST_XML
@@ -13,6 +13,9 @@ import java.util.Set;
*/
public final class SwfConstants {
public static final String TARGET_PREFIX = "SimpleWorkflowService.";
public static final String LEGACY_TARGET_PREFIX = "com.amazonaws.swf.service.model.SimpleWorkflowService.";
public static final String FAULT_NAMESPACE = "com.amazonaws.swf.base.model#";
public static final String VALIDATION_NAMESPACE = "com.amazon.coral.validate#";
@@ -92,4 +95,5 @@ public final class SwfConstants {
private SwfConstants() {
}
}