mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ses): refuse the headers SES sets itself on v2 templated and bulk sends (#9726)
SES v2 refused the headers it sets itself (From, To, Cc, Bcc, Subject, Date, Message-ID, Reply-To, Return-Path, MIME-Version, Content-Type and Content-Disposition, in any case) only in a SendEmail's Content.Simple.Headers. Content.Template.Headers and the SendBulkEmail default and replacement headers now refuse them too, with 400 BadRequestException "Header <Name> is not supported" and the name as sent. On SendBulkEmail one refused header, default or in any entry, fails the whole call. As probed on AWS, the refusal comes right after the request shape, ahead of the sender, content and template data checks, the destination count, the template and configuration set lookups and the sender verification.
This commit is contained in:
1 parent
3909e10e2e
commit
3974568cd3
4 files changed
+260
-7
No files matched your search
@@ -304,7 +304,7 @@ curl $AWS_ENDPOINT_URL/_aws/ses
|
||||
|
||||
- An email address identity is verified as soon as it is created; no inbox verification flow is required. A domain identity stays `Pending` until its DKIM CNAME records exist in a Route 53 hosted zone in Floci, then becomes `Success`.
|
||||
- `SendEmail`, `SendRawEmail`, `SendTemplatedEmail` and `SendBulkTemplatedEmail`, and v2 `SendEmail` and `SendBulkEmail`, require verified senders, as on AWS ([SendEmail](https://docs.aws.amazon.com/ses/latest/APIReference/API_SendEmail.html), [Email sending errors](https://docs.aws.amazon.com/ses/latest/dg/troubleshoot-error-messages.html)): each address used as a "From", "Source", "Sender" or "Return-Path" address must be a verified email address identity or an address in a verified domain identity or one of its subdomains. That is the `Source` or `FromEmailAddress` and the `ReturnPath` or `FeedbackForwardingEmailAddress`, plus, on a raw message, every mailbox of its `From` header, its `Sender` and its `Return-Path` header. A v2 raw send reads the `From` header only in place of a missing `FromEmailAddress` and accepts any `From` header when one is given (probe-confirmed), so the header is checked only then. Every other address present is checked; whether AWS still checks a `Return-Path` header that the request's return path overrides has not been probed. One `MessageRejected` lists every unverified address ("Email address is not verified. The following identities failed the check in region US-EAST-1: a@example.com, b@example.com") and nothing is captured or relayed. An address covered by a sending-authorization ARN of another account (`SourceArn`, `FromArn`, `ReturnPathArn`, their `X-SES-*-ARN` headers, or v2 `FromEmailAddressIdentityArn` and `FeedbackForwardingEmailAddressIdentityArn`) is not checked, since it is the owner's identity; on a raw send the source ARN also covers the `From` and return-path addresses that have no ARN of their own. A bulk send checks its sender and return path once and rejects the whole call; when no entry has a recipient it checks neither and every entry fails on its own (probe-confirmed on v2 `SendBulkEmail` and v1 `SendBulkTemplatedEmail`). On v2 `SendEmail` and `SendBulkEmail`, and v1 `SendTemplatedEmail` and `SendBulkTemplatedEmail`, an unknown configuration set is reported before the check and an unknown stored template only after it (probe-confirmed). The verification codes and invitations Cognito sends are not affected.
|
||||
- v2 `SendEmail` refuses a `Content.Simple.Headers` entry named `From`, `To`, `Cc`, `Bcc`, `Subject`, `Date`, `Message-ID`, `Reply-To`, `Return-Path`, `MIME-Version`, `Content-Type` or `Content-Disposition`, in any case, with a 400 `BadRequestException` ("Header <From> is not supported"), ahead of the configuration set lookup and the sender verification (probe-confirmed). The headers of a templated send, `Content.Template.Headers` and the `SendBulkEmail` default and replacement headers, are not checked (not probed).
|
||||
- v2 `SendEmail` refuses a `Content.Simple.Headers` entry named `From`, `To`, `Cc`, `Bcc`, `Subject`, `Date`, `Message-ID`, `Reply-To`, `Return-Path`, `MIME-Version`, `Content-Type` or `Content-Disposition`, in any case, with a 400 `BadRequestException` ("Header <From> is not supported"), ahead of the configuration set lookup and the sender verification (probe-confirmed). The same names are refused in `Content.Template.Headers` and in the `SendBulkEmail` default and replacement headers, where one refused header in any entry fails the whole call. On these sends the refusal comes ahead of every other check of the request after its shape: a missing sender, incomplete inline content, missing template data, the destination count, an all-empty bulk, the template lookup, the configuration set and the sender verification (probe-confirmed).
|
||||
- `SendBulkTemplatedEmail` reads every `Destinations.member.N` up to the highest N. A missing `Template` (whatever `TemplateArn` holds), missing `Destinations`, and an entry without a `Destination` or a skipped N are model violations, answered together as one 400 `ValidationError` ("2 validation errors detected: Value at 'template' failed to satisfy constraint: Member must not be null; Value at 'destinations.2.member.destination' failed to satisfy constraint: Member must not be null") ahead of every other check of the request, the address syntax and the destination count included (probe-confirmed). Floci lists the skipped entries of the first 1000 indexes only; a higher index fails the destination count. On both bulk sends an entry whose address lists are empty answers "Missing required header 'To'." on its own when another entry has a recipient, and when none has one every entry answers "Destination cannot be empty" (probe-confirmed). A `DefaultTags` or `ReplacementTags` tag without a `Name` or a `Value` is a model violation too, a skipped tag index listing both, and the top-level members are listed ahead of the nested ones ('template' before 'defaultTags.1.member.name'). A missing or empty `DefaultTemplateData` is a 400 `InvalidParameterValue` ("The default template data does not exist"), answered after the `Source` syntax and the destination count and before the template lookup and the sender verification (probe-confirmed). On `SendBulkTemplatedEmail` an entry with more than 50 recipients ("Recipient count exceeds 50."), template data that is not a JSON object ("The template data is invalid") or a tag with an empty name ("The tag name must be specified.") fails on its own with `InvalidParameterValue`. Invalid `DefaultTemplateData` or an empty `DefaultTags` name fails every entry, and within one entry an address syntax error wins over an empty tag name, which wins over invalid template data, which wins over the recipient count (probe-confirmed). v2 `SendBulkEmail` still rejects the whole call for more than 50 recipients in a destination (not probed).
|
||||
- A `TemplateArn` on v1 `SendTemplatedEmail` and `SendBulkTemplatedEmail` and v2 `SendEmail` and `SendBulkEmail` must be in the request's partition and region, name the `ses` service and start its resource with `template/`; its account is not checked. Each mismatch has its own message ("Invalid template ARN <arn>. Template must be in region <us-east-1>"), a value that does not start with `arn:` answers "ARNs must start with 'arn:': <value>", and an ARN beside a template name must name the same template ("The SES resource '<name>' does not align with the given ARN '<arn>'."). The checks run before the sender verification; v1 answers `InvalidParameterValue` and v2 `BadRequestException` (probe-confirmed). The v1 sends require `Template` even beside a `TemplateArn`, and an empty one answers "Template cannot be empty" ahead of the ARN checks; `SendBulkTemplatedEmail` answers the same for a whitespace-only `Template` (probe-confirmed).
|
||||
- The v1 and v2 templated sends check the name of the stored template they use just before the sender verification, length first: "Template name <name> exceeds maximum allowed length 64", then "Template name <name> is only allowed to contain alphanumeric characters, underscore, and dash". A bulk send in which no entry names a recipient answers every entry "Destination cannot be empty" instead. A `TemplateArn` naming such a template answers the template operations' wording ("Template name <a.b>: only alphanumeric ASCII characters, '_', and '-' are allowed.") with the other ARN checks. v2 `SendBulkEmail` answers a template with no name, ARN or content, or a whitespace-only name, "TemplateName and TemplateArn both can not be empty", and an empty `TemplateName` is a model violation (probe-confirmed).
|
||||
|
||||
@@ -90,6 +90,9 @@ public class SesSendController {
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
if (!request.path("Content").has("Raw") && !request.path("Content").has("Simple")) {
|
||||
requireSupportedHeaderNames(request.path("Content").path("Template").path("Headers"));
|
||||
}
|
||||
|
||||
// FromEmailAddress is optional per the AWS v2 contract. Each content type below
|
||||
// enforces the sender requirement the way AWS does: Raw can take its From from the
|
||||
@@ -234,6 +237,10 @@ public class SesSendController {
|
||||
if (bulkEntries.isMissingNode() || bulkEntries.isNull()) {
|
||||
throw SmithyValidationErrors.badRequest(SmithyValidationErrors.notNullWithoutValue("bulkEmailEntries"));
|
||||
}
|
||||
requireSupportedHeaderNames(request.path("DefaultContent").path("Template").path("Headers"));
|
||||
for (JsonNode entry : bulkEntries) {
|
||||
requireSupportedHeaderNames(entry.path("ReplacementHeaders"));
|
||||
}
|
||||
requireInlineTemplateFields(request.path("DefaultContent").path("Template"));
|
||||
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
|
||||
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
|
||||
@@ -519,12 +526,28 @@ public class SesSendController {
|
||||
private static void requireSupportedHeaders(List<MessageHeader> headers) {
|
||||
for (MessageHeader header : headers) {
|
||||
if (!MessageHeader.isSupportedName(header.name())) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Header <" + header.name() + "> is not supported", 400);
|
||||
throw unsupportedHeader(header.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A templated or bulk send that names a header SES sets itself is refused ahead of every check
|
||||
// after the request shape: a missing sender, incomplete inline content, missing template data,
|
||||
// the destination count and an all-empty bulk (probe-confirmed). The shape of each header is
|
||||
// still checked where the headers are parsed.
|
||||
private static void requireSupportedHeaderNames(JsonNode headersNode) {
|
||||
for (JsonNode header : headersNode) {
|
||||
JsonNode name = header.path("Name");
|
||||
if (name.isTextual() && !MessageHeader.isSupportedName(name.textValue())) {
|
||||
throw unsupportedHeader(name.textValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException unsupportedHeader(String name) {
|
||||
return new AwsException("BadRequestException", "Header <" + name + "> is not supported", 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a V2 SES {@code Content.Simple.Attachments} array. {@code FileName} and
|
||||
* {@code RawContent} are required, the string members carry the documented length limits and
|
||||
|
||||
@@ -16,14 +16,14 @@ public record MessageHeader(
|
||||
@JsonProperty("Name") String name,
|
||||
@JsonProperty("Value") String value) {
|
||||
|
||||
// SES sets these itself and refuses them as an additional header of a v2 SendEmail, whatever
|
||||
// the case of the name. Sender, DKIM-Signature, Received and the List-Unsubscribe pair are
|
||||
// accepted (probed on Content.Simple.Headers).
|
||||
// SES sets these itself and refuses them as an additional header of a v2 SendEmail or
|
||||
// SendBulkEmail, whatever the case of the name. Sender, DKIM-Signature, Received and the
|
||||
// List-Unsubscribe pair are accepted (probed on Content.Simple.Headers).
|
||||
private static final Set<String> UNSUPPORTED_NAMES = Set.of(
|
||||
"from", "to", "cc", "bcc", "subject", "date", "message-id", "reply-to", "return-path",
|
||||
"mime-version", "content-type", "content-disposition");
|
||||
|
||||
/** Whether SES accepts {@code name} as the name of an additional header of a simple message. */
|
||||
/** Whether SES accepts {@code name} as the name of an additional header of a v2 send. */
|
||||
public static boolean isSupportedName(String name) {
|
||||
return name == null || !UNSUPPORTED_NAMES.contains(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
package io.floci.aws.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static io.floci.aws.services.ses.SesV2Requests.DESTINATION;
|
||||
import static io.floci.aws.services.ses.SesV2Requests.ENTRY;
|
||||
import static io.floci.aws.services.ses.SesV2Requests.TO;
|
||||
import static io.floci.aws.services.ses.SesV2Requests.post;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* SES V2 refuses a header SES sets itself in {@code Content.Template.Headers} of SendEmail and in
|
||||
* the default and replacement headers of SendBulkEmail, for the whole call and ahead of the
|
||||
* configuration set lookup and the sender verification.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesSendUnsupportedTemplateHeaderV2IntegrationTest {
|
||||
|
||||
private static final String SENDER = "template-header-sender@example.com";
|
||||
private static final String UNVERIFIED_SENDER = "template-header-unverified@example.com";
|
||||
private static final String INLINE = "\"TemplateContent\": {\"Subject\": \"S {{n}}\", \"Text\": \"T {{n}}\"}";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createSender() {
|
||||
post("/v2/email/identities", "{\"EmailIdentity\": \"" + SENDER + "\"}").statusCode(200);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"From", "content-disposition"})
|
||||
void templateHeader_isRefusedWithItsNameAsSent(String name) {
|
||||
sendTemplate(UNVERIFIED_SENDER, "", INLINE + ", \"TemplateData\": \"{}\"", name)
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Header <" + name + "> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateHeader_isRefusedBeforeAMissingStoredTemplate() {
|
||||
sendTemplate(UNVERIFIED_SENDER, "",
|
||||
"\"TemplateName\": \"template-header-missing\", \"TemplateData\": \"{}\"", "From")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateHeader_isRefusedBeforeAnUnknownConfigurationSet() {
|
||||
sendTemplate(SENDER, "\"ConfigurationSetName\": \"template-header-missing-set\",",
|
||||
INLINE + ", \"TemplateData\": \"{}\"", "From")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateHeader_isRefusedWithoutTemplateData() {
|
||||
sendTemplate(UNVERIFIED_SENDER, "", INLINE, "From")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateHeader_isRefusedBeforeIncompleteInlineContent() {
|
||||
sendTemplate(UNVERIFIED_SENDER, "",
|
||||
"\"TemplateContent\": {\"Text\": \"T\"}, \"TemplateData\": \"{}\"", "From")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateHeader_isRefusedBeforeAMissingSender() {
|
||||
post("/v2/email/outbound-emails", """
|
||||
{%s,
|
||||
"Content": {"Template": {%s, "TemplateData": "{}", "Headers": %s}}}
|
||||
""".formatted(DESTINATION, INLINE, headers("From")))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedTemplateHeader_leavesAnUnverifiedSenderToAnswer() {
|
||||
sendTemplate(UNVERIFIED_SENDER, "", INLINE + ", \"TemplateData\": \"{}\"", "X-Custom")
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("MessageRejected"))
|
||||
.body("message", startsWith("Email address is not verified."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedTemplateHeader_isSent() {
|
||||
String messageId = sendTemplate(SENDER, "", INLINE + ", \"TemplateData\": \"{\\\"n\\\": \\\"1\\\"}\"",
|
||||
"X-Custom")
|
||||
.statusCode(200)
|
||||
.extract().path("MessageId");
|
||||
|
||||
assertCapturedHeader(messageId, "X-Custom");
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkDefaultHeader_failsTheWholeCall() {
|
||||
sendBulk(UNVERIFIED_SENDER, "", ", \"Headers\": " + headers("From"), ENTRY)
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkDefaultHeader_isRefusedWithoutDefaultTemplateData() {
|
||||
post("/v2/email/outbound-bulk-emails", """
|
||||
{"FromEmailAddress": "%s",
|
||||
"DefaultContent": {"Template": {%s, "Headers": %s}},
|
||||
"BulkEmailEntries": [%s]}
|
||||
""".formatted(UNVERIFIED_SENDER, INLINE, headers("From"), ENTRY))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkDefaultHeader_isRefusedBeforeAMissingSender() {
|
||||
post("/v2/email/outbound-bulk-emails", """
|
||||
{"DefaultContent": {"Template": {%s, "TemplateData": "{}", "Headers": %s}},
|
||||
"BulkEmailEntries": [%s]}
|
||||
""".formatted(INLINE, headers("From"), ENTRY))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkDefaultHeader_isRefusedBeforeTheDestinationCount() {
|
||||
sendBulk(UNVERIFIED_SENDER, "", ", \"Headers\": " + headers("From"), String.join(", ", Collections.nCopies(51, ENTRY)))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkDefaultHeader_isRefusedBeforeAnAllEmptyBulk() {
|
||||
sendBulk(UNVERIFIED_SENDER, "", ", \"Headers\": " + headers("From"), "{\"Destination\": {}}")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkReplacementHeader_isRefusedBeforeAnEarlierEntrysTemplateData() {
|
||||
String invalidData = "{\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ReplacementEmailContent\": "
|
||||
+ "{\"ReplacementTemplate\": {\"ReplacementTemplateData\": \"not json\"}}}";
|
||||
sendBulk(UNVERIFIED_SENDER, "", "", invalidData + ", " + replacementEntry("From"))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkReplacementHeader_failsTheWholeCall() {
|
||||
sendBulk(UNVERIFIED_SENDER, "", "", ENTRY + ", " + replacementEntry("Message-ID"))
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Header <Message-ID> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bulkReplacementHeader_isRefusedBeforeAnUnknownConfigurationSet() {
|
||||
sendBulk(SENDER, "\"ConfigurationSetName\": \"template-header-missing-set\",", "",
|
||||
replacementEntry("From"))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedBulkReplacementHeader_leavesAnUnverifiedSenderToAnswer() {
|
||||
sendBulk(UNVERIFIED_SENDER, "", "", replacementEntry("X-Custom"))
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("MessageRejected"))
|
||||
.body("message", startsWith("Email address is not verified."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedBulkHeaders_areSent() {
|
||||
String messageId = sendBulk(SENDER, "", ", \"Headers\": " + headers("X-Default"),
|
||||
replacementEntry("X-Custom"))
|
||||
.statusCode(200)
|
||||
.body("BulkEmailEntryResults[0].Status", equalTo("SUCCESS"))
|
||||
.extract().path("BulkEmailEntryResults[0].MessageId");
|
||||
|
||||
assertCapturedHeader(messageId, "X-Default");
|
||||
assertCapturedHeader(messageId, "X-Custom");
|
||||
}
|
||||
|
||||
private static void assertCapturedHeader(String messageId, String name) {
|
||||
given().when().get("/_aws/ses?id=" + messageId).then().statusCode(200)
|
||||
.body("messages[0].Headers.find { it.Name == '" + name + "' }.Value", equalTo("probe-value"));
|
||||
}
|
||||
|
||||
private static String headers(String name) {
|
||||
return "[{\"Name\": \"" + name + "\", \"Value\": \"probe-value\"}]";
|
||||
}
|
||||
|
||||
private static String replacementEntry(String headerName) {
|
||||
return "{\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ReplacementHeaders\": "
|
||||
+ headers(headerName) + "}";
|
||||
}
|
||||
|
||||
private static ValidatableResponse sendTemplate(String sender, String extraMember, String template,
|
||||
String headerName) {
|
||||
return post("/v2/email/outbound-emails", """
|
||||
{"FromEmailAddress": "%s",
|
||||
%s
|
||||
%s,
|
||||
"Content": {"Template": {%s, "Headers": %s}}}
|
||||
""".formatted(sender, extraMember, DESTINATION, template, headers(headerName)));
|
||||
}
|
||||
|
||||
private static ValidatableResponse sendBulk(String sender, String extraMember, String defaultHeaders,
|
||||
String entries) {
|
||||
return post("/v2/email/outbound-bulk-emails", """
|
||||
{"FromEmailAddress": "%s",
|
||||
%s
|
||||
"DefaultContent": {"Template": {%s, "TemplateData": "{\\"n\\": \\"1\\"}"%s}},
|
||||
"BulkEmailEntries": [%s]}
|
||||
""".formatted(sender, extraMember, INLINE, defaultHeaders, entries));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user