-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
2626482
ci(migrations): fail dev schema push with an actionable error on rena…
TheodoreSpeaks a489c4f
improvement(auth): layer disposable-email-domains into signup email v…
TheodoreSpeaks d70f56d
improvement(auth): defer disposable-domains dataset behind lazy dynam…
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
35 changes: 35 additions & 0 deletions
35
apps/sim/lib/messaging/email/disposable-domains.server.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.