fix(ses): coerce a v2 boolean string only when it names a boolean (#4887)

SES v2 accepts a JSON string for a boolean member only when it reads,
case-insensitively, as true/yes/y/t/1 or false/no/n/f/0; any other string
is a SerializationException. Floci turned every string into true, so
UnsubscribeAll "false" stored true. Affects UnsubscribeAll, SendingEnabled
and AutoWarmupEnabled.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-02 09:47:03 -04:00
1 parent ae216f22a0
commit 5b6c53d0df
9 files changed
+73 -26

No files matched your search

@@ -226,7 +226,7 @@ public class SesAccountController {
JsonNode enabledNode = request.path("AutoWarmupEnabled");
// AutoWarmupEnabled has a default of false: the SDK omits it when false, so a missing
// member is treated as false rather than rejected. A present value goes through the
// shared SES v2 boolean coercion (string→true, null/number/container→SerializationException).
// shared SES v2 boolean coercion.
boolean enabled = enabledNode.isMissingNode() ? false : coerceBoolean(enabledNode);
accountService.setDedicatedIpAutoWarmup(region, enabled);
LOG.infov("SES V2 PutAccountDedicatedIpWarmupAttributes: {0}", enabled);
@@ -238,8 +238,8 @@ public class SesConfigurationSetController {
String region = regionResolver.resolveRegion(headers);
try {
// Reuse the AWS-aligned SendingEnabled deserialization shared with CreateConfigurationSet:
// absent -> false, string -> true, null/number -> SerializationException. An empty body
// / {} therefore disables sending (200). Verified against real AWS.
// absent -> false, otherwise SesV2Json.coerceBoolean. An empty body / {} therefore
// disables sending (200). Verified against real AWS.
boolean enabled = parseSendingEnabled(
readOptionBody(objectMapper, body).path("SendingEnabled"));
configSetService.setSendingEnabled(name, enabled, region);
@@ -315,8 +315,7 @@ public class SesContactController {
}
// UnsubscribeAll is a Boolean; AWS coerces it the same way as any other SES v2 boolean
// (see parseSendingEnabled): a JSON string coerces to true, a number/null/array/object is a
// SerializationException. Absent leaves it unset.
// (see coerceBoolean). Absent leaves it unset.
private static Boolean parseUnsubscribeAll(JsonNode request) {
if (!request.has("UnsubscribeAll")) {
return null;
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.ses.model.Tag;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* Helpers shared by the SES v2 REST JSON controllers: body and member shape checks that answer
@@ -119,14 +120,20 @@ final class SesV2Json {
return node.asText();
}
// AWS-verified Jackson coercion for a SES v2 boolean field: a JSON string coerces to true,
// while a number/null/array/object is a SerializationException.
// AWS-verified coercion for a SES v2 boolean field: a JSON string coerces only when it names a
// boolean (case-insensitive, untrimmed); any other string, a number, null, an array or an object
// is a SerializationException.
static boolean coerceBoolean(JsonNode node) {
if (node.isBoolean()) {
return node.booleanValue();
}
if (node.isTextual()) {
return true;
return switch (node.textValue().toLowerCase(Locale.ROOT)) {
case "true", "yes", "y", "t", "1" -> true;
case "false", "no", "n", "f", "0" -> false;
default -> throw new AwsException("SerializationException",
"STRING_VALUE can not be converted to an Boolean", 400);
};
}
if (node.isNull()) {
throw new AwsException("SerializationException", null, 400);
@@ -241,9 +248,8 @@ final class SesV2Json {
/**
* Reproduces the AWS deserialization behavior for {@code SendingEnabled}
* (verified against real AWS SES V2 on 2026-06-13): a missing member
* defaults to {@code false}, any string coerces to {@code true}, and
* explicit {@code null} or non-boolean scalars fail with
* {@code SerializationException}.
* defaults to {@code false}, and a present value goes through
* {@link #coerceBoolean(JsonNode)}.
*/
static boolean parseSendingEnabled(JsonNode enabledNode) {
if (enabledNode.isMissingNode()) {