Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(auth): layer disposable-email-domains into signup email validation#5010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2626482a489c4fd70f56dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** Ambient types for `disposable-email-domains` — ships JSON arrays with no bundled types. */ | ||
| declare module 'disposable-email-domains' { | ||
| const domains: string[] | ||
| export default domains | ||
| } | ||
| declare module 'disposable-email-domains/wildcard.json' { | ||
| const baseDomains: string[] | ||
| export default baseDomains | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { isDisposableEmailDomain } from '@/lib/messaging/email/disposable-domains.server' | ||
| describe('isDisposableEmailDomain', () => { | ||
| it('flags a known disposable domain', async () => { | ||
| expect(await isDisposableEmailDomain('someone@mailinator.com')).toBe(true) | ||
| }) | ||
| it('flags a subdomain of a wildcard base domain', async () => { | ||
| expect(await isDisposableEmailDomain('someone@inbox.10mail.org')).toBe(true) | ||
| }) | ||
| it('flags the bare wildcard base domain itself', async () => { | ||
| expect(await isDisposableEmailDomain('someone@10mail.org')).toBe(true) | ||
| }) | ||
| it('is case-insensitive on the domain', async () => { | ||
| expect(await isDisposableEmailDomain('Someone@MailInator.com')).toBe(true) | ||
| }) | ||
| it('allows a normal provider domain', async () => { | ||
| expect(await isDisposableEmailDomain('someone@gmail.com')).toBe(false) | ||
| }) | ||
| it('allows a custom catch-all domain that is not on the list', async () => { | ||
| expect(await isDisposableEmailDomain('sim6dc088f506@lordfortescue.org.uk')).toBe(false) | ||
| }) | ||
| it('returns false for malformed input with no domain', async () => { | ||
| expect(await isDisposableEmailDomain('not-an-email')).toBe(false) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| let cache: { exact: Set<string>; wildcards: string[] } | undefined | ||
| /** | ||
| * Lazily loads the `disposable-email-domains` dataset (~120K exact domains plus | ||
| * wildcard base domains) on first use and memoizes it. Deferred behind a dynamic | ||
| * import so deployments with signup email validation disabled never load it. | ||
| */ | ||
| async function loadDisposableData(): Promise<{ exact: Set<string>; wildcards: string[] }> { | ||
| if (!cache) { | ||
| const [{ default: exactList }, { default: wildcards }] = await Promise.all([ | ||
| import('disposable-email-domains'), | ||
| import('disposable-email-domains/wildcard.json'), | ||
| ]) | ||
| cache = { exact: new Set(exactList), wildcards } | ||
| } | ||
| return cache | ||
| } | ||
| /** | ||
| * Server-only disposable-email-domain check. Layered alongside better-auth-harmony's | ||
| * bundled Mailchecker list at the signup gate. Matches exact domains and any subdomain | ||
| * of (or the bare) wildcard base domain. | ||
| * | ||
| * Never import from client code — the dataset would bloat the browser bundle. | ||
| */ | ||
| export async function isDisposableEmailDomain(email: string): Promise<boolean> { | ||
| const domain = email.split('@')[1]?.toLowerCase() | ||
| if (!domain) return false | ||
| const { exact, wildcards } = await loadDisposableData() | ||
| if (exact.has(domain)) return true | ||
| return wildcards.some((base) => domain === base || domain.endsWith(`.${base}`)) | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.