mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(ses): reject non-string tag members with SerializationException (#2512)
* fix(ses): reject non-string tag members with SerializationException SesController.parseTagsArray coerced tag Key/Value via asText(null), so a non-string member (number, boolean, object, array) was silently turned into a string (123 -> "123") and accepted, across all five SES tag entry points that share the method (CreateEmailIdentity, CreateConfigurationSet, CreateEmailTemplate, CreateContactList, TagResource). AWS's restJson1 deserializer rejects a non-string tag member with SerializationException / 400 (probe-confirmed). parseTagsArray now rejects a present-but-non-string Key/Value the same way, leaving missing/null members to the downstream service validation. * fix(ses): reject non-object tag list elements with SerializationException parseTagsArray validated Key/Value types but not that each Tags element is a JSON object, so a scalar/array/null element fell through to service-layer validation. Reject a non-object element with SerializationException, matching AWS's restJson1 deserializer (AWS returns 500 for a null element, a server-side bug, normalized to the same 400).
This commit is contained in:
1 parent
29f6e7ac6b
commit
60dd795703
3 files changed
+63
-4
No files matched your search
@@ -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:<region>:<account>:configuration-set/<name>`, `arn:aws:ses:<region>:<account>:template/<name>`, and `arn:aws:ses:<region>:<account>:identity/<email-or-domain>`. 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:<region>:<account>:configuration-set/<name>`, `arn:aws:ses:<region>:<account>:template/<name>`, and `arn:aws:ses:<region>:<account>:identity/<email-or-domain>`. 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.
|
||||
|
||||
|
||||
@@ -2453,13 +2453,30 @@ public class SesController {
|
||||
}
|
||||
List<Tag> 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.
|
||||
|
||||
+42
@@ -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 + "\"}")
|
||||
|
||||
Reference in new issue
Block a user