carlos / platform Public

mail: expand ValidDomain wildcard test coverage

Add test cases for wildcard rejection (* and *.example.com) with a
comment explaining the security implication: the domain string becomes
an IAM ses:FromAddress condition value, where wildcards would match
every address on earth. Regex validation remains unchanged; this fix
only expands test coverage to prevent regression.
Paul Campbell 31c506576ed45bf35cb248629e58839be20a0474 parent e7c1b7e
1 file changed, +5 −1
  • internal/mail/domain_test.go +5 −1
diff --git a/internal/mail/domain_test.go b/internal/mail/domain_test.go
index 4d9354537..0624a3ffd 100644
--- a/internal/mail/domain_test.go
+++ b/internal/mail/domain_test.go
@@ -25,7 +25,11 @@ func TestValidDomainRefusesWhatWouldEscapeTheKey(t *testing.T) {
// A domain becomes a bucket KEY and an IAM policy RESOURCE. Anything
// that could traverse or inject must be refused here, at the only
// place every caller passes through.
- for _, bad := range []string{"", ".", "../etc", "a/b.com", "UPPER.com", "-lead.com", "trail-.com", "a..b.com"} {
+ for _, bad := range []string{"", ".", "../etc", "a/b.com", "UPPER.com", "-lead.com", "trail-.com", "a..b.com",
+ // Wildcards are dangerous: the domain string becomes an IAM
+ // ses:FromAddress condition value, where * would match every
+ // address on earth.
+ "*", "*.example.com"} {
if ValidDomain(bad) {
t.Fatalf("ValidDomain(%q) = true, want false", bad)
}