fix(email): match blocked domains on a label boundary (#4647)

isBlockedEmail compared each blocked entry as a raw suffix of the whole
address, so `mailinator.com` also blocked `notmailinator.com` and a TLD
entry like `ru` blocked `site.guru`. A bare entry now matches the
address's domain exactly or as a parent domain. Entries containing `@`
or starting with `.` keep matching as written.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Giridhar SriramanandClaude Opus 5.5 authored and GitHub committed 2026-11-23 11:25:37 -07:00
1 parent 19590857a6
commit 19ae43b02b
2 files changed
+26 -6

No files matched your search

+15
View File
@@ -143,6 +143,21 @@ describe('isBlockedEmail', () => {
expect(isBlockedEmail('a@example.com', ['mailinator.com'])).toBe(false);
});
it('does not block a different domain that merely ends in the same characters', () => {
expect(
isBlockedEmail('a@notmailinator.com', ['mailinator.com']),
).toBe(false);
});
it('applies the same label boundary to a bare TLD entry', () => {
expect(isBlockedEmail('a@site.guru', ['ru'])).toBe(false);
expect(isBlockedEmail('a@site.ru', ['ru'])).toBe(true);
});
it('still matches a full-address entry', () => {
expect(isBlockedEmail('spammer@x.com', ['spammer@x.com'])).toBe(true);
});
it('matches on the cleaned address, so aliasing cannot bypass the list', () => {
expect(
isBlockedEmail('A.B+tag@MAILINATOR.com', ['mailinator.com']),
+11 -6
View File
@@ -188,9 +188,9 @@ export function isProviderCanonicalized(email: string): boolean {
}
/**
* Returns true when the (cleaned) email matches any of the blocked domain
* suffixes. Suffix-match so `mailinator.com` blocks `foo@bar.mailinator.com`;
* case-insensitive on both sides.
* Returns true when the (cleaned) email's domain equals a blocked entry or is a
* subdomain of it, case-insensitively. Entries containing `@` or starting with
* `.` already carry a boundary and match the address suffix as written.
*/
export function isBlockedEmail(
email: string,
@@ -198,9 +198,14 @@ export function isBlockedEmail(
): boolean {
if (!blockedDomains || blockedDomains.length === 0) return false;
const clean = cleanEmail(email);
return blockedDomains.some((suffix) =>
clean.endsWith(suffix.toLowerCase()),
);
const domain = clean.slice(clean.lastIndexOf('@') + 1);
return blockedDomains.some((entry) => {
const blocked = entry.toLowerCase();
if (blocked.includes('@') || blocked.startsWith('.')) {
return clean.endsWith(blocked);
}
return domain === blocked || domain.endsWith(`.${blocked}`);
});
}
/** The addresses of `to` that no `email.notify.validate` listener declined. */