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 a v2 simple send (#9633)
SES v2 SendEmail accepted any additional header on a simple message, but SES refuses the ones it sets itself. 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, now answers 400 BadRequestException "Header <Name> is not supported" with the name as sent, ahead of the configuration set lookup and the sender verification. Other headers are accepted as before.
This commit is contained in:
1 parent
c452942d3f
commit
0b5448e17a
5 files changed
+178
No files matched your search
@@ -304,6 +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).
|
||||
- `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).
|
||||
|
||||
@@ -157,6 +157,7 @@ public class SesSendController {
|
||||
parseHeadersArray(simple.path("Headers"), "content.simple.headers");
|
||||
List<MessageAttachment> attachments =
|
||||
parseAttachmentsArray(simple.path("Attachments"), "content.simple.attachments");
|
||||
requireSupportedHeaders(additionalHeaders);
|
||||
requireNoNullAddress(toAddresses, ccAddresses, bccAddresses, replyToAddresses);
|
||||
SendEmailRequest simpleRequest = sendRequest
|
||||
.content(new EmailContent.Simple(subject, bodyText, bodyHtml, additionalHeaders,
|
||||
@@ -515,6 +516,15 @@ public class SesSendController {
|
||||
return out;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -3,6 +3,9 @@ package io.floci.aws.services.ses.model;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents one entry of the SES V2 {@code Content.Simple.Headers} /
|
||||
* {@code Content.Template.Headers} list — a user-supplied additional header to attach to
|
||||
@@ -13,6 +16,18 @@ 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).
|
||||
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. */
|
||||
public static boolean isSupportedName(String name) {
|
||||
return name == null || !UNSUPPORTED_NAMES.contains(name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this header is safe to attach to an outgoing message: its name must be non-blank and
|
||||
* neither name nor value may contain CR/LF, otherwise it could inject additional headers. Used to
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
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 static io.floci.aws.services.ses.SesV2Requests.DESTINATION;
|
||||
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.hasSize;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* SES V2 SendEmail refuses a {@code Content.Simple.Headers} entry that names a header SES sets
|
||||
* itself, ahead of the configuration set lookup and the sender verification.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesSendUnsupportedHeaderV2IntegrationTest {
|
||||
|
||||
private static final String SENDER = "header-sender@example.com";
|
||||
private static final String UNVERIFIED_SENDER = "header-unverified@example.com";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createSender() {
|
||||
post("/v2/email/identities", "{\"EmailIdentity\": \"" + SENDER + "\"}").statusCode(200);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"From", "To", "Cc", "Bcc", "Subject", "Date", "Message-ID", "Reply-To",
|
||||
"Return-Path", "MIME-Version", "Content-Type", "Content-Disposition", "from"})
|
||||
void unsupportedHeader_isRefusedWithItsNameAsSent(String name) {
|
||||
send(SENDER, name, "")
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Header <" + name + "> is not supported"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"Sender", "DKIM-Signature", "Received", "List-Unsubscribe", "List-Unsubscribe-Post",
|
||||
"X-Custom"})
|
||||
void otherHeader_isAcceptedAndCaptured(String name) {
|
||||
String messageId = send(SENDER, name, "").statusCode(200)
|
||||
.body("MessageId", notNullValue())
|
||||
.extract().path("MessageId");
|
||||
|
||||
given().when().get("/_aws/ses?id=" + messageId).then().statusCode(200)
|
||||
.body("messages", hasSize(1))
|
||||
.body("messages[0].Headers.find { it.Name == '" + name + "' }.Value", equalTo("probe-value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedHeader_isRefusedBeforeAnUnknownConfigurationSet() {
|
||||
send(SENDER, "From", "\"ConfigurationSetName\": \"header-missing-set\",")
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <From> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedHeader_leavesAnUnknownConfigurationSetToAnswer() {
|
||||
send(SENDER, "X-Custom", "\"ConfigurationSetName\": \"header-missing-set\",")
|
||||
.statusCode(404)
|
||||
.header("x-amzn-ErrorType", equalTo("NotFoundException"))
|
||||
.body("message", equalTo("Configuration set <header-missing-set> does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedHeader_isRefusedBeforeAnUnverifiedSender() {
|
||||
send(UNVERIFIED_SENDER, "Subject", "")
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Header <Subject> is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportedHeader_leavesAnUnverifiedSenderToAnswer() {
|
||||
send(UNVERIFIED_SENDER, "X-Custom", "")
|
||||
.statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("MessageRejected"))
|
||||
.body("message", startsWith("Email address is not verified."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void secondHeader_isRefusedWhenTheFirstIsSupported() {
|
||||
post("/v2/email/outbound-emails", """
|
||||
{"FromEmailAddress": "%s",
|
||||
%s,
|
||||
"Content": {"Simple": {
|
||||
"Subject": {"Data": "Headers"},
|
||||
"Body": {"Text": {"Data": "body"}},
|
||||
"Headers": [{"Name": "X-Custom", "Value": "a"}, {"Name": "Reply-To", "Value": "b"}]}}}
|
||||
""".formatted(SENDER, DESTINATION))
|
||||
.statusCode(400)
|
||||
.body("message", equalTo("Header <Reply-To> is not supported"));
|
||||
}
|
||||
|
||||
private static ValidatableResponse send(String sender, String headerName, String extraMember) {
|
||||
return post("/v2/email/outbound-emails", """
|
||||
{"FromEmailAddress": "%s",
|
||||
%s
|
||||
%s,
|
||||
"Content": {"Simple": {
|
||||
"Subject": {"Data": "Headers"},
|
||||
"Body": {"Text": {"Data": "body"}},
|
||||
"Headers": [{"Name": "%s", "Value": "probe-value"}]}}}
|
||||
""".formatted(sender, extraMember, DESTINATION, headerName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.floci.aws.services.ses.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class MessageHeaderTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"From", "To", "Cc", "Bcc", "Subject", "Date", "Message-ID", "Reply-To",
|
||||
"Return-Path", "MIME-Version", "Content-Type", "Content-Disposition"})
|
||||
void isSupportedName_refusesTheHeadersSesSetsItself(String name) {
|
||||
assertFalse(MessageHeader.isSupportedName(name));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"from", "FROM", "message-id", "Mime-Version", "content-TYPE"})
|
||||
void isSupportedName_ignoresTheCaseOfTheName(String name) {
|
||||
assertFalse(MessageHeader.isSupportedName(name));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"Sender", "DKIM-Signature", "Received", "List-Unsubscribe", "List-Unsubscribe-Post",
|
||||
"X-Custom", "X-From", "From-Address"})
|
||||
void isSupportedName_acceptsEveryOtherName(String name) {
|
||||
assertTrue(MessageHeader.isSupportedName(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isSupportedName_leavesAMissingNameToTheOtherChecks() {
|
||||
assertTrue(MessageHeader.isSupportedName(null));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user