fix(ssm): parse and bound command delivery timeouts (#5908)

* fix(ssm): limit public command delivery time

* docs(ssm): describe command delivery timeouts

* fix(ssm): deserialize delivery timeouts before checking bounds

Handle numeric delivery timeouts consistently without bypassing limits.

* fix(ssm): report member-specific deserialization errors

Name the expected scalar type and explain malformed structures.

* refactor(ssm): keep delivery timeout errors consistent
This commit is contained in:
David Phillips authored and GitHub committed 2026-10-18 11:03:48 -04:00
1 parent 1a80884f40
commit 356c79e78e
9 files changed
+536 -14

No files matched your search

@@ -48,6 +48,7 @@ public class SsmCommandService implements Resettable {
private static final Logger LOG = Logger.getLogger(SsmCommandService.class);
private static final int MIN_TIMEOUT_SECONDS = 30;
private static final int MAX_TIMEOUT_SECONDS = 2_592_000;
private static final int MAX_INSTANCE_IDS = 50;
private static final int DEFAULT_SHELL_EXECUTION_TIMEOUT_SECONDS = 3600;
private static final int MAX_SHELL_EXECUTION_TIMEOUT_SECONDS = 172800;
@@ -165,7 +166,7 @@ public class SsmCommandService implements Resettable {
Map<String, List<String>> parameters = publicShell
? parseShellParameters(request.path("Parameters")) : parseParameters(request.path("Parameters"));
String comment = request.path("Comment").asText("");
int timeoutSeconds = request.path("TimeoutSeconds").asInt(3600);
int timeoutSeconds = SsmJsonDeserialization.optionalInteger(request.path("TimeoutSeconds"), 3600);
validateTimeoutSeconds(timeoutSeconds);
int executionTimeoutSeconds = publicShell ? shellExecutionTimeout(parameters) : timeoutSeconds;
int documentTimeoutDefault = publicShell ? DEFAULT_SHELL_EXECUTION_TIMEOUT_SECONDS : timeoutSeconds;
@@ -296,6 +297,10 @@ public class SsmCommandService implements Resettable {
throw SmithyValidationErrors.validationException(
"Value '" + timeoutSeconds + "' at 'timeoutSeconds' failed to satisfy constraint: Member must have value greater than or equal to 30");
}
if (timeoutSeconds > MAX_TIMEOUT_SECONDS) {
throw SmithyValidationErrors.validationException(
"Value '" + timeoutSeconds + "' at 'timeoutSeconds' failed to satisfy constraint: Member must have value less than or equal to 2592000");
}
}
public CommandInvocation getCommandInvocation(String commandId, String instanceId, String region) {
@@ -0,0 +1,41 @@
package io.github.hectorvent.floci.services.ssm;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.AwsException;
final class SsmJsonDeserialization {
private SsmJsonDeserialization() {
}
static int optionalInteger(JsonNode node, int defaultValue) {
if (node.isMissingNode() || node.isNull()) {
return defaultValue;
}
if (!node.isNumber() || Double.isNaN(node.doubleValue())) {
throw serializationException(node, "an Integer");
}
double value = node.doubleValue();
if (value >= Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (value <= Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return node.intValue();
}
static AwsException serializationException(JsonNode node, String targetDescription) {
String token = switch (node.getNodeType()) {
case STRING -> "STRING_VALUE";
case NUMBER -> "NUMBER_VALUE";
case BOOLEAN -> node.booleanValue() ? "TRUE_VALUE" : "FALSE_VALUE";
default -> node.getNodeType().name();
};
String message = switch (node.getNodeType()) {
case OBJECT -> "Start of structure or map found where not expected.";
case ARRAY -> "Start of list found where not expected";
default -> token + " can not be converted to " + targetDescription;
};
return new AwsException("SerializationException", message, 400);
}
}
@@ -38,6 +38,8 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static io.github.hectorvent.floci.services.ssm.SsmJsonDeserialization.serializationException;
@ApplicationScoped
public class SsmJsonHandler {
@@ -1039,7 +1041,7 @@ public class SsmJsonHandler {
} else if (l.isTextual()) {
labels.add(l.textValue());
} else {
throw serializationException(l, "String");
throw serializationException(l, "a String");
}
}
return labels;
@@ -1051,7 +1053,7 @@ public class SsmJsonHandler {
return null;
}
if (!node.isTextual()) {
throw serializationException(node, "String");
throw serializationException(node, "a String");
}
return node.textValue();
}
@@ -1063,21 +1065,11 @@ public class SsmJsonHandler {
return null;
}
if (!node.isNumber()) {
throw serializationException(node, "Long");
throw serializationException(node, "a Long");
}
return node.decimalValue().max(LONG_MIN).min(LONG_MAX).longValue();
}
private static AwsException serializationException(JsonNode node, String targetType) {
String token = switch (node.getNodeType()) {
case STRING -> "STRING_VALUE";
case NUMBER -> "NUMBER_VALUE";
case BOOLEAN -> node.booleanValue() ? "TRUE_VALUE" : "FALSE_VALUE";
default -> node.getNodeType().name();
};
return new AwsException("SerializationException", token + " can not be converted to a " + targetType, 400);
}
private Response handleLabelParameterVersion(JsonNode request, String region) {
String name = request.path("Name").asText();
Long parameterVersion = request.hasNonNull("ParameterVersion")