mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ses): reject non-array v2 reply-to and bulk destination members (#5477)
ReplyToAddresses in SendEmail and SendBulkEmail, and the To/Cc/Bcc of each SendBulkEmail entry, read a value of the wrong JSON type as an empty list. They are rejected with SerializationException, as the SendEmail Destination members already are.
This commit is contained in:
1 parent
1e92b7e17b
commit
a96cc04fab
4 files changed
+80
-24
No files matched your search
@@ -51,7 +51,8 @@ final class SesAddressSyntax {
|
||||
/**
|
||||
* Checks the To, Cc and Bcc of one bulk entry, then the request's Reply-To. AWS reports a
|
||||
* malformed entry recipient as that entry's status, and a malformed Reply-To as the status of
|
||||
* every entry, not as a request error (probe-confirmed).
|
||||
* every entry, not as a request error (probe-confirmed). An address list of the wrong JSON type
|
||||
* never reaches this check: the controller rejects the whole request with SerializationException.
|
||||
*/
|
||||
static void requireBulkDestination(BulkEmailEntry entry, List<String> replyToAddresses) {
|
||||
for (List<String> addresses : Arrays.asList(entry.toAddresses(), entry.ccAddresses(), entry.bccAddresses(),
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.jboss.logging.Logger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -103,10 +102,10 @@ public class SesSendController {
|
||||
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
|
||||
|
||||
JsonNode destination = requireObjectOrAbsent(request, "Destination");
|
||||
List<String> toAddresses = destinationAddresses(destination, "ToAddresses");
|
||||
List<String> ccAddresses = destinationAddresses(destination, "CcAddresses");
|
||||
List<String> bccAddresses = destinationAddresses(destination, "BccAddresses");
|
||||
List<String> replyToAddresses = jsonArrayToList(request.path("ReplyToAddresses"));
|
||||
List<String> toAddresses = addressList(destination, "ToAddresses");
|
||||
List<String> ccAddresses = addressList(destination, "CcAddresses");
|
||||
List<String> bccAddresses = addressList(destination, "BccAddresses");
|
||||
List<String> replyToAddresses = addressList(request, "ReplyToAddresses");
|
||||
String feedbackForwardingAddress =
|
||||
request.path("FeedbackForwardingEmailAddress").asText(null);
|
||||
String configurationSetName = request.path("ConfigurationSetName").asText(null);
|
||||
@@ -243,7 +242,7 @@ public class SesSendController {
|
||||
"FromEmailAddress is required.", 400);
|
||||
}
|
||||
SesAddressSyntax.requireBulkAddress(fromEmailAddress);
|
||||
List<String> replyToAddresses = jsonArrayToList(request.path("ReplyToAddresses"));
|
||||
List<String> replyToAddresses = addressList(request, "ReplyToAddresses");
|
||||
String feedbackForwardingAddress =
|
||||
request.path("FeedbackForwardingEmailAddress").asText(null);
|
||||
SesAddressSyntax.requireBulkAddress(feedbackForwardingAddress);
|
||||
@@ -314,9 +313,9 @@ public class SesSendController {
|
||||
"BulkEmailEntries elements must be JSON objects.", 400);
|
||||
}
|
||||
JsonNode dest = requireObjectOrAbsent(node, "Destination");
|
||||
List<String> to = jsonArrayToList(dest.path("ToAddresses"));
|
||||
List<String> cc = jsonArrayToList(dest.path("CcAddresses"));
|
||||
List<String> bcc = jsonArrayToList(dest.path("BccAddresses"));
|
||||
List<String> to = addressList(dest, "ToAddresses");
|
||||
List<String> cc = addressList(dest, "CcAddresses");
|
||||
List<String> bcc = addressList(dest, "BccAddresses");
|
||||
JsonNode replacementContent = requireObjectOrAbsent(node, "ReplacementEmailContent");
|
||||
JsonNode replacementTemplate = requireObjectOrAbsent(replacementContent, "ReplacementTemplate");
|
||||
JsonNode replacementData = parseTemplateData(replacementTemplate, "ReplacementTemplateData");
|
||||
@@ -405,19 +404,10 @@ public class SesSendController {
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
// A Raw send falls back to the MIME recipients when no destination is given, so a present member
|
||||
// of the wrong JSON type must be rejected rather than read as an omitted one.
|
||||
private static List<String> destinationAddresses(JsonNode destination, String field) {
|
||||
return Objects.requireNonNullElse(stringArrayOrAbsent(destination, field), List.of());
|
||||
}
|
||||
|
||||
private List<String> jsonArrayToList(JsonNode arrayNode) {
|
||||
if (arrayNode == null || arrayNode.isMissingNode() || !arrayNode.isArray()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
arrayNode.forEach(node -> list.add(node.asText()));
|
||||
return list;
|
||||
// A present address list of the wrong JSON type, or with a non-string element, is rejected
|
||||
// rather than read as empty or coerced.
|
||||
private static List<String> addressList(JsonNode parent, String field) {
|
||||
return Objects.requireNonNullElse(stringArrayOrAbsent(parent, field), List.of());
|
||||
}
|
||||
|
||||
private JsonNode parseTemplateData(JsonNode parent, String fieldName) {
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class SesSendAddressListTypeIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
|
||||
private static final String TO = "success@simulator.amazonses.com";
|
||||
|
||||
private static void assertSerializationException(String path, String body) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH)
|
||||
.body(body)
|
||||
.when()
|
||||
.post(path)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
}
|
||||
|
||||
private static String bulkSend(String replyTo, String entryDestination) {
|
||||
return """
|
||||
{
|
||||
"FromEmailAddress": "sender@example.com",
|
||||
%s
|
||||
"DefaultContent": {"Template": {
|
||||
"TemplateContent": {"Subject": "s", "Text": "b"},
|
||||
"TemplateData": "{}"}},
|
||||
"BulkEmailEntries": [{"Destination": %s}]
|
||||
}
|
||||
""".formatted(replyTo, entryDestination);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_nonArrayReplyTo_returnsSerializationException() {
|
||||
assertSerializationException("/v2/email/outbound-emails", """
|
||||
{
|
||||
"FromEmailAddress": "sender@example.com",
|
||||
"Destination": {"ToAddresses": ["%s"]},
|
||||
"ReplyToAddresses": "reply@example.com",
|
||||
"Content": {"Simple": {"Subject": {"Data": "s"}, "Body": {"Text": {"Data": "b"}}}}
|
||||
}
|
||||
""".formatted(TO));
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_nonArrayReplyTo_returnsSerializationException() {
|
||||
assertSerializationException("/v2/email/outbound-bulk-emails",
|
||||
bulkSend("\"ReplyToAddresses\": \"reply@example.com\",", "{\"ToAddresses\": [\"" + TO + "\"]}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_nonArrayEntryDestinationMember_returnsSerializationException() {
|
||||
assertSerializationException("/v2/email/outbound-bulk-emails",
|
||||
bulkSend("", "{\"ToAddresses\": [\"" + TO + "\"], \"CcAddresses\": \"bad-shape\"}"));
|
||||
}
|
||||
}
|
||||
@@ -217,13 +217,14 @@ class SesV2JsonTest {
|
||||
|
||||
@Test
|
||||
void stringArrayOrAbsent_keepsEmptyListDistinctFromAbsent() {
|
||||
JsonNode node = json("{\"a\":[\"x\",\"y\"],\"e\":[],\"z\":null,\"s\":\"x\",\"m\":[1]}");
|
||||
JsonNode node = json("{\"a\":[\"x\",\"y\"],\"e\":[],\"z\":null,\"s\":\"x\",\"m\":[1],\"n\":[null]}");
|
||||
assertEquals(List.of("x", "y"), SesV2Json.stringArrayOrAbsent(node, "a"));
|
||||
assertEquals(List.of(), SesV2Json.stringArrayOrAbsent(node, "e"));
|
||||
assertNull(SesV2Json.stringArrayOrAbsent(node, "z"));
|
||||
assertNull(SesV2Json.stringArrayOrAbsent(node, "missing"));
|
||||
assertAws("SerializationException", 400, () -> SesV2Json.stringArrayOrAbsent(node, "s"));
|
||||
assertAws("SerializationException", 400, () -> SesV2Json.stringArrayOrAbsent(node, "m"));
|
||||
assertAws("SerializationException", 400, () -> SesV2Json.stringArrayOrAbsent(node, "n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user