From 19ae43b02b602a3b8219259d3fdfbac6c9e7a7db Mon Sep 17 00:00:00 2001 From: Giridhar Sriraman Date: Mon, 23 Nov 2026 23:55:37 +0530 Subject: [PATCH] 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 --- src/backend/util/email.test.ts | 15 +++++++++++++++ src/backend/util/email.ts | 17 +++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/backend/util/email.test.ts b/src/backend/util/email.test.ts index 27eedcbc4..0917ea090 100644 --- a/src/backend/util/email.test.ts +++ b/src/backend/util/email.test.ts @@ -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']), diff --git a/src/backend/util/email.ts b/src/backend/util/email.ts index 8e6d5541c..cc51bc7ae 100644 --- a/src/backend/util/email.ts +++ b/src/backend/util/email.ts @@ -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. */