mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ses): refuse more than 50 bulk destinations the way SES does (#6430)
* fix(ses): refuse more than 50 bulk destinations the way SES does SendBulkEmail and SendBulkTemplatedEmail answered MessageRejected "Number of destinations (N) exceeds the maximum of 50." after resolving the stored template, configuration set and tenant. SES answers "You must specify at least 1 destination, and no more than 50 destinations" (BadRequestException on v2, InvalidParameterValue on v1) before those lookups, and v2 answers an empty BulkEmailEntries the same way. An absent v2 BulkEmailEntries is now the Smithy not-null violation. * fix(ses): keep a null bulk entry list on the count error
This commit is contained in:
1 parent
c854046523
commit
e1796b33b1
5 files changed
+216
-41
No files matched your search
@@ -779,8 +779,6 @@ public class SesQueryHandler {
|
||||
"Template or TemplateArn is required.", 400);
|
||||
}
|
||||
String resolvedName = hasName ? templateName : SesTemplateService.templateNameFromArn(templateArn);
|
||||
EmailTemplate template = templateService.getTemplate(resolvedName, region);
|
||||
JsonNode defaultTemplateData = parseTemplateData(defaultDataRaw);
|
||||
|
||||
List<BulkEmailEntry> entries = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
@@ -801,6 +799,10 @@ public class SesQueryHandler {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"At least one destination is required.", 400);
|
||||
}
|
||||
// AWS counts the destinations before it looks the template up (probe-confirmed).
|
||||
SesService.requireBulkDestinationCount(entries.size());
|
||||
EmailTemplate template = templateService.getTemplate(resolvedName, region);
|
||||
JsonNode defaultTemplateData = parseTemplateData(defaultDataRaw);
|
||||
|
||||
String configurationSetName = getParam(params, "ConfigurationSetName");
|
||||
String returnPath = getParam(params, "ReturnPath");
|
||||
|
||||
@@ -247,6 +247,10 @@ public class SesSendController {
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendBulkEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
JsonNode bulkEntries = request.path("BulkEmailEntries");
|
||||
if (bulkEntries.isMissingNode() || bulkEntries.isNull()) {
|
||||
throw constraintViolation(null, "bulkEmailEntries", "Member must not be null");
|
||||
}
|
||||
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
|
||||
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
@@ -281,9 +285,9 @@ public class SesSendController {
|
||||
"DefaultContent.Template requires TemplateName, TemplateArn, or TemplateContent.", 400);
|
||||
}
|
||||
|
||||
String subject;
|
||||
String text;
|
||||
String html;
|
||||
String subject = null;
|
||||
String text = null;
|
||||
String html = null;
|
||||
// Inline template content is not a stored template resource, so it stays out of the
|
||||
// tenant gate below.
|
||||
String gateTemplateName = null;
|
||||
@@ -294,7 +298,11 @@ public class SesSendController {
|
||||
html = inline.path("Html").asText(null);
|
||||
// Shape validation belongs before the tenant gate below, as on SendEmail.
|
||||
SesService.requireInlineTemplateContent(subject, text, html);
|
||||
} else {
|
||||
}
|
||||
// AWS counts the entries after the inline content check and before it looks the stored
|
||||
// template up (probe-confirmed).
|
||||
SesService.requireBulkDestinationCount(bulkEntries.size());
|
||||
if (!hasInline) {
|
||||
String resolvedName = hasName
|
||||
? templateName
|
||||
: SesTemplateService.templateNameFromArn(templateArn);
|
||||
@@ -309,12 +317,6 @@ public class SesSendController {
|
||||
List<MessageHeader> defaultHeaders =
|
||||
parseHeadersArray(template.path("Headers"), "defaultContent.template.headers");
|
||||
|
||||
JsonNode bulkEntries = request.path("BulkEmailEntries");
|
||||
if (!bulkEntries.isArray() || bulkEntries.isEmpty()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"BulkEmailEntries must be a non-empty array.", 400);
|
||||
}
|
||||
|
||||
List<BulkEmailEntry> entries = new ArrayList<>();
|
||||
int entryIndex = 1;
|
||||
for (JsonNode node : bulkEntries) {
|
||||
|
||||
@@ -1708,6 +1708,17 @@ public class SesService {
|
||||
}
|
||||
}
|
||||
|
||||
// Probe-confirmed: both bulk sends count the destinations before the stored template lookup,
|
||||
// v2 also before the configuration set and tenant lookups, and v2 answers an empty list with
|
||||
// the same message. The v1 order against the configuration set has not been probed.
|
||||
static void requireBulkDestinationCount(int count) {
|
||||
if (count < 1 || count > MAX_BULK_DESTINATIONS) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"You must specify at least 1 destination, and no more than "
|
||||
+ MAX_BULK_DESTINATIONS + " destinations", 400);
|
||||
}
|
||||
}
|
||||
|
||||
// SES refuses the send outright for an attachment type it does not accept, unlike the content
|
||||
// scan, which accepts the message and rejects it afterwards.
|
||||
private static void rejectBlockedAttachments(Message parsed) {
|
||||
@@ -1722,16 +1733,8 @@ public class SesService {
|
||||
throw new AwsException("InvalidParameterValue", "Source email is required.", 400);
|
||||
}
|
||||
requireInlineTemplateContent(template.subject(), template.textPart(), template.htmlPart());
|
||||
if (request.entries() == null || request.entries().isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"At least one destination entry is required.", 400);
|
||||
}
|
||||
requireBulkDestinationCount(sizeOf(request.entries()));
|
||||
configSetService.validateForSending(request.configurationSetName(), request.region());
|
||||
if (request.entries().size() > MAX_BULK_DESTINATIONS) {
|
||||
throw new AwsException("MessageRejected",
|
||||
"Number of destinations (" + request.entries().size() + ") exceeds the maximum of "
|
||||
+ MAX_BULK_DESTINATIONS + ".", 400);
|
||||
}
|
||||
for (BulkEmailEntry entry : request.entries()) {
|
||||
int recipientCount = sizeOf(entry.toAddresses())
|
||||
+ sizeOf(entry.ccAddresses())
|
||||
|
||||
Reference in new issue
Block a user