fix(core): return UnknownOperationException when X-Amz-Target is missing (#3925)

This commit is contained in:
danielvanza authored and GitHub committed 2026-09-19 23:10:19 -04:00
1 parent 68425d942a
commit ca98384b4a
5 files changed
+169 -8

No files matched your search

@@ -266,7 +266,7 @@ public class AwsJson11Controller {
String body) {
if (target == null) {
return null;
return JsonErrorResponseUtils.createMissingTargetErrorResponse();
}
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
@@ -385,16 +385,15 @@ public class AwsJsonCborController {
byte[] body) {
if (target == null) {
return null;
return cborUnknownOperationError("Missing X-Amz-Target header.", httpHeaders);
}
// Upstream CBOR behavior is to return null for targets this controller
// does not dispatch (JAX-RS then serves 204). The JSON 1.0/1.1
// controllers return UnknownOperationException instead; CBOR stays on
// null here to preserve pre-refactor semantics.
// 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
// only to a resolved service whose action this handler does not dispatch.
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
if (targetMatch == null) {
return null;
return cborUnknownOperationError("Unknown operation: " + target, httpHeaders);
}
String serviceKey = targetMatch.descriptor().externalKey();
@@ -491,6 +490,12 @@ public class AwsJsonCborController {
};
}
private Response cborUnknownOperationError(String message, HttpHeaders httpHeaders) {
return cborErrorResponse(
new AwsException("UnknownOperationException", message, 404),
"smithy-protocol", responseContentType(httpHeaders));
}
private Response cborErrorResponse(AwsException e, String protocolHeader, String mediaType) {
try {
byte[] errBytes = CBOR_MAPPER.writeValueAsBytes(
@@ -101,7 +101,7 @@ public class AwsJsonController {
String body) {
if (target == null) {
return null;
return JsonErrorResponseUtils.createMissingTargetErrorResponse();
}
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
@@ -57,6 +57,18 @@ public class JsonErrorResponseUtils {
"Unknown operation: " + target, null);
}
/**
* A JSON request with no X-Amz-Target names no operation, so there is nothing to route on.
* It fails as an unknown operation but with a message about the missing header rather than
* concatenating a literal {@code null} into {@link #createUnknownOperationErrorResponse}.
*/
public static Response createMissingTargetErrorResponse() {
return createErrorResponse(404,
"UnknownOperationException",
"UnknownOperationException",
"Missing X-Amz-Target header.", null);
}
/**
* A request body that is not valid JSON is a client (deserialization) error, not a server
* fault. AWS's JSON protocols reject it with 400 SerializationException; without this the