diff --git a/docs/services/ses.md b/docs/services/ses.md index 03a819450b..77cdf8a424 100644 --- a/docs/services/ses.md +++ b/docs/services/ses.md @@ -288,7 +288,7 @@ Suppressed recipients are filtered out of the SMTP relay step (non-suppressed re For a **single-recipient** list-managed send, Floci injects a functional unsubscribe link (matching AWS, which only does this for one recipient): the `{{amazonSESUnsubscribeUrl}}` body placeholder is replaced (up to twice) and a `List-Unsubscribe` header plus `List-Unsubscribe-Post: List-Unsubscribe=One-Click` are added (applied to the relayed message and shown under `Headers` at `GET /_aws/ses`; a caller-supplied `List-Unsubscribe` is overridden, matching AWS). The `{{amazonSESUnsubscribeUrl}}` placeholder is also preserved through template rendering so a templated body can carry it. On a send without `ListManagementOptions`, the placeholder is left in the body verbatim (neither replaced nor stripped) — this specific behavior is Floci's choice and is not verified against real SES. Unlike AWS's opaque hosted URL, the link points at Floci's own `/_aws/ses/unsubscribe?region=…&contactList=…&address=…&topic=…` endpoint. `GET` (a browser click) only renders a confirmation page and changes nothing — matching AWS's landing-page behavior and avoiding the RFC 8058 hazard where a client or bot that prefetches the link would silently unsubscribe the contact — while `POST` (the one-click request the confirmation form submits) applies the opt-out (a topic → `OPT_OUT` for that topic; no topic → `UnsubscribeAll`), auto-creating the contact if needed. Two deviations from AWS here: the link is carried as readable query parameters rather than an opaque token (so, like the rest of Floci, the endpoint is unauthenticated and only safe on a trusted dev/test network — a `POST` can opt out any contact), and only the one-click URL entry is emitted — its scheme follows Floci's base URL (`http` unless TLS is enabled) — whereas AWS also includes a `mailto:` entry, which Floci can't service since it has no inbound mail endpoint. Raw (MIME) sends do not get link injection yet. -Tag operations support these ARN forms: `arn:aws:ses:::configuration-set/`, `arn:aws:ses:::template/`, and `arn:aws:ses:::identity/`. Tags supplied to `CreateConfigurationSet`, `CreateEmailTemplate`, and `CreateEmailIdentity` are reachable through `ListTagsForResource`; `UpdateEmailTemplate` does not modify tags. Other resource types return `NotFoundException`. +Tag operations support these ARN forms: `arn:aws:ses:::configuration-set/`, `arn:aws:ses:::template/`, and `arn:aws:ses:::identity/`. Tags supplied to `CreateConfigurationSet`, `CreateEmailTemplate`, and `CreateEmailIdentity` are reachable through `ListTagsForResource`; `UpdateEmailTemplate` does not modify tags. Other resource types return `NotFoundException`. A non-string tag `Key` or `Value` (number, boolean, object, array), or a `Tags` element that is not an object, is rejected with `SerializationException` rather than being coerced, matching AWS's restJson1 deserializer. The same AWS-compatible validation applies wherever tags are set (including `CreateContactList` and `TagResource`): at most 50 tags, unique keys, keys 1–128 / values 0–256 code points, characters limited to letters, numbers, Unicode whitespace and `_ . : / = + - @`, and the reserved `aws:` key prefix. `TagResource` applies the 50-tag limit to the merged (existing + incoming) set. Violations return `BadRequestException` with AWS's messages. diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java index 1d2542c18e..e1b9c3fe98 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java @@ -2453,13 +2453,30 @@ public class SesController { } List out = new ArrayList<>(); for (JsonNode t : tagsNode) { - out.add(new Tag( - t.path("Key").asText(null), - t.path("Value").asText(null))); + // Each element must be a JSON object. A scalar/array/null element is a wire deserialization + // error (AWS returns SerializationException for a scalar/array element; it returns a 500 + // InternalFailure for a null element, a server-side bug we normalize to the same 400). + if (!t.isObject()) { + throw new AwsException("SerializationException", null, 400); + } + JsonNode key = t.path("Key"); + JsonNode value = t.path("Value"); + // A present-but-non-string Key/Value (number, boolean, object, array) is a wire + // deserialization error, not a coercible value: AWS restJson1 rejects it with + // SerializationException rather than turning 123 into "123". A missing/null member is left + // to the downstream service validation, matching AWS. + if (nonStringMember(key) || nonStringMember(value)) { + throw new AwsException("SerializationException", null, 400); + } + out.add(new Tag(key.asText(null), value.asText(null))); } return out; } + private static boolean nonStringMember(JsonNode node) { + return !node.isMissingNode() && !node.isNull() && !node.isTextual(); + } + /** * Parses a {@code SuppressedReasons} JSON array into a list, validating * structure only; reason values are validated by the service layer. diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java index d258834a85..ff12bc0f7f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java @@ -1236,6 +1236,48 @@ class SesConfigurationSetV2IntegrationTest { .body("DeliveryOptions.SendingPoolName", equalTo("v2-cs-pool-ref")); } + @Test + @Order(62) + void createConfigurationSet_nonStringTagKey_returnsSerializationException() { + // AWS restJson1 rejects a non-string tag member with SerializationException rather than + // coercing it (probe-confirmed: a numeric Key returns "NUMBER_VALUE can not be converted to a + // String"). Floci matches the type/status; its error body uses __type (project-wide). + given().contentType("application/json").header("Authorization", AUTH_HEADER) + .body("{\"ConfigurationSetName\": \"v2-cs-nonstr-key\", \"Tags\": [{\"Key\": 123, \"Value\": \"v\"}]}") + .when().post("/v2/email/configuration-sets") + .then().statusCode(400).body("__type", equalTo("SerializationException")); + } + + @Test + @Order(63) + void createConfigurationSet_nonStringTagValue_returnsSerializationException() { + // A boolean value and an object value are both non-string members and rejected the same way. + given().contentType("application/json").header("Authorization", AUTH_HEADER) + .body("{\"ConfigurationSetName\": \"v2-cs-nonstr-val\", \"Tags\": [{\"Key\": \"k\", \"Value\": true}]}") + .when().post("/v2/email/configuration-sets") + .then().statusCode(400).body("__type", equalTo("SerializationException")); + + given().contentType("application/json").header("Authorization", AUTH_HEADER) + .body("{\"ConfigurationSetName\": \"v2-cs-nonstr-obj\", \"Tags\": [{\"Key\": \"k\", \"Value\": {\"x\": 1}}]}") + .when().post("/v2/email/configuration-sets") + .then().statusCode(400).body("__type", equalTo("SerializationException")); + } + + @Test + @Order(64) + void createConfigurationSet_nonObjectTagElement_returnsSerializationException() { + // A tag list element that is not an object (scalar, array, or null) is a wire deserialization + // error. AWS returns SerializationException for scalar/array elements and a 500 InternalFailure + // for a null element (a server-side bug); Floci normalizes all of them to 400 + // SerializationException. Probe-confirmed against real AWS. + for (String badElement : new String[] {"true", "123", "\"k\"", "[\"k\",\"v\"]", "null"}) { + given().contentType("application/json").header("Authorization", AUTH_HEADER) + .body("{\"ConfigurationSetName\": \"v2-cs-bad-el\", \"Tags\": [" + badElement + "]}") + .when().post("/v2/email/configuration-sets") + .then().statusCode(400).body("__type", equalTo("SerializationException")); + } + } + private static void putConfigSet(String name) { given().contentType("application/json").header("Authorization", AUTH_HEADER) .body("{\"ConfigurationSetName\": \"" + name + "\"}")