fix(ses): check the template name of a send as SES does (#9271)

This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-11-23 10:36:52 -04:00
1 parent 64f74c6bc4
commit 7b2e60cfe0
6 files changed
+239 -1

No files matched your search

@@ -229,6 +229,11 @@ public class SesSendController {
JsonNode request = readOptionBody(objectMapper, body);
SesV2RequestShapes.check("SendBulkEmail", request);
validateTrackingOverrides(request);
JsonNode defaultTemplateName = request.path("DefaultContent").path("Template").path("TemplateName");
if (defaultTemplateName.isTextual() && defaultTemplateName.textValue().isEmpty()) {
throw SmithyValidationErrors.badRequest("Value at 'defaultContent.template.templateName' failed to "
+ "satisfy constraint: Member must have length greater than or equal to 1");
}
JsonNode bulkEntries = request.path("BulkEmailEntries");
if (bulkEntries.isMissingNode() || bulkEntries.isNull()) {
throw SmithyValidationErrors.badRequest(SmithyValidationErrors.notNullWithoutValue("bulkEmailEntries"));
@@ -254,7 +259,7 @@ public class SesSendController {
TemplateSelector selector = TemplateSelector.of(template);
if (selector.isEmpty()) {
throw new AwsException("BadRequestException",
"DefaultContent.Template requires TemplateName, TemplateArn, or TemplateContent.", 400);
"TemplateName and TemplateArn both can not be empty", 400);
}
// AWS counts the entries after the inline content check and the sender checks, and
// before it rejects a stored template named beside the content or looks one up
@@ -292,6 +292,9 @@ public class SesService {
SesAddressSyntax.requireEnvelope(request);
String effectiveConfigSet = validateEnvelope(request);
SesAddressLength.requireEnvelope(request);
if (request.content() instanceof EmailContent.Template template) {
SesTemplateService.requireSendTemplateName(template.templateName());
}
if (requireVerifiedSender) {
requireVerifiedSenders(List.of(
new SendingAddress(request.source(), request.sourceArn()),
@@ -1727,6 +1730,9 @@ public class SesService {
"Destination cannot be empty"))
.toList();
}
if (request.templateName() != null) {
SesTemplateService.requireSendTemplateName(request.templateName());
}
// The sender and return path are checked once for the whole call, then a stored template is
// looked up, then the tenant associations, as on a single send (probe-confirmed).
requireVerifiedSenders(List.of(
@@ -269,9 +269,26 @@ public class SesTemplateService implements SesTaggable {
if (name.isEmpty()) {
throw new AwsException("InvalidParameterValue", "The template name must be specified.", 400);
}
SesNames.requireAllowedCharacters(name, "InvalidParameterValue", "Template name");
return name;
}
/**
* The name rule a send applies to the stored template it names, worded unlike the template
* operations' rule and checked just before the sender verification (probe-confirmed on the v1
* and v2 sends).
*/
public static void requireSendTemplateName(String name) {
if (name.length() > SesNames.MAX_LENGTH) {
throw new AwsException("InvalidParameterValue",
"Template name " + name + " exceeds maximum allowed length " + SesNames.MAX_LENGTH, 400);
}
if (!SesNames.hasOnlyAllowedCharacters(name)) {
throw new AwsException("InvalidParameterValue", "Template name " + name
+ " is only allowed to contain alphanumeric characters, underscore, and dash", 400);
}
}
/**
* A send may name its template beside a {@code TemplateArn} only when both name the same
* template; a malformed ARN is reported first (probe-confirmed on both protocols).