fix(stepfunctions): reject reserved API headers in definitions (#6082)

Reject the live-AWS-verified reserved names and hyphenated prefixes before state-machine creation or update, including JSONata and nested workflows. Share the existing exact-name policy with the invoker, preserve nearby accepted header names and keep the current response parser behavior.

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-20 17:01:22 -04:00
1 parent a578bb0811
commit 2c6f2118e8
5 files changed
+156 -6

No files matched your search

@@ -40,6 +40,7 @@ import java.util.Base64;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -48,6 +49,10 @@ import java.util.stream.Collectors;
@ApplicationScoped
public class ApiGatewayTaskInvoker {
private static final SecureRandom RANDOM = new SecureRandom();
private static final Set<String> RESERVED_HEADERS = Set.of(
"authorization", "connection", "content-md5", "expect", "host", "max-forwards",
"proxy-authenticate", "server", "te", "transfer-encoding", "trailer", "upgrade", "via",
"www-authenticate");
private static final DateTimeFormatter AMZ_DATE =
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC);
private final ApiGatewayService apiGateway;
@@ -230,10 +235,7 @@ public class ApiGatewayTaskInvoker {
input.properties().forEach(entry -> {
String name = entry.getKey().toLowerCase(Locale.ROOT);
JsonNode values = entry.getValue();
if (!entry.getKey().matches("[!#$%&'*+.^_`|~0-9A-Za-z-]+") || name.startsWith("x-amz") || name.startsWith("x-forwarded")
|| List.of("authorization", "connection", "content-md5", "expect", "host", "max-forwards",
"proxy-authenticate", "server", "te", "transfer-encoding", "trailer", "upgrade", "via",
"www-authenticate").contains(name)
if (!entry.getKey().matches("[!#$%&'*+.^_`|~0-9A-Za-z-]+") || isReservedDefinitionHeader(name)
|| !values.isArray() || values.isEmpty() || result.containsKey(name)) {
throw unsupported("header name or value is not supported");
}
@@ -249,6 +251,11 @@ public class ApiGatewayTaskInvoker {
return result;
}
static boolean isReservedDefinitionHeader(String lowerName) {
return RESERVED_HEADERS.contains(lowerName) || lowerName.startsWith("x-amz-")
|| lowerName.startsWith("x-amzn-") || lowerName.startsWith("x-forwarded-");
}
private static void sign(TreeMap<String, List<String>> headers, URI uri, byte[] payload, String region,
String accessKey, String secret, String token) throws Exception {
String stamp = AMZ_DATE.format(Instant.now());
@@ -2378,6 +2378,9 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
validateFieldsAllowedForType(statePath, stateDef, stateType, errors);
validateTransitionTargets(statePath, stateDef, siblingStateNames, errors);
if ("Task".equals(stateType)) {
validateApiGatewayHeaders(statePath, stateDef, stateIsJsonata, errors);
}
// Measured on AWS: the downgrade is the whole answer for that state, and the fields its
// refused language forbids are not named on top of it. Only this check is skipped; every
@@ -2429,6 +2432,30 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
}
}
private static void validateApiGatewayHeaders(String statePath, JsonNode stateDef,
boolean jsonata, List<String> errors) {
if (StatesIntegration.parse(stateDef.path("Resource").asText(null))
.filter(integration -> integration.isAnySuffix("apigateway", "invoke")).isEmpty()) {
return;
}
String field = jsonata ? "Arguments" : "Parameters";
JsonNode headers = stateDef.path(field).path("Headers");
if (!headers.isObject()) {
return;
}
List<String> unsupported = new ArrayList<>();
headers.fieldNames().forEachRemaining(name -> {
String lower = name.toLowerCase(Locale.ROOT);
if (ApiGatewayTaskInvoker.isReservedDefinitionHeader(lower)) {
unsupported.add(lower);
}
});
if (!unsupported.isEmpty()) {
errors.add(EXPLICIT_LOCATION_MARKER + "The 'Headers' field contains unsupported values: "
+ unsupported + MARKER_PAYLOAD_SEPARATOR + statePath + "/" + field);
}
}
/**
* Reports every JSONata expression in the state that does not parse, or that reads the
* top-level context, or that reads {@code $states.errorOutput} outside the one place it