mirror of
https://github.com/documenso/documenso.git
synced 2026-07-27 02:15:05 +10:00
feat: block disposable email signups (#2883)
Reject disposable / throwaway email providers (mailinator, yopmail, 10minutemail, ...) across all signup paths: email/password, Google, Microsoft, personal OIDC and organisation OIDC. Backed by the mailchecker package (offline, ~55k domains, subdomain-aware). Exposes a SIGNUP_DISPOSABLE_EMAIL error code so the signup form and SSO redirect alert can show a dedicated message instead of the generic 'signup disabled' one.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import MailChecker from 'mailchecker';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { env } from '../utils/env';
|
||||
@@ -121,6 +122,48 @@ export const isEmailDomainAllowedForSignup = (email: string): boolean => {
|
||||
return allowedDomains.includes(emailDomain);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the given email belongs to a known disposable / throwaway provider
|
||||
* (e.g. mailinator, yopmail, 10minutemail, ...).
|
||||
*
|
||||
* Backed by the `mailchecker` package which bundles a static list of 55k+
|
||||
* disposable domains. The check is offline and synchronous.
|
||||
*
|
||||
* Matching also covers subdomains (e.g. `foo.mailinator.com` resolves to
|
||||
* `mailinator.com`).
|
||||
*
|
||||
* Returns `true` when the email is disposable and should be rejected.
|
||||
* Email format validation is intentionally NOT performed here — that is
|
||||
* handled by Zod upstream.
|
||||
*/
|
||||
export const isDisposableEmail = (email: string): boolean => {
|
||||
const domain = email.toLowerCase().split('@').pop();
|
||||
|
||||
if (!domain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const blacklist = MailChecker.blacklist();
|
||||
|
||||
let currentDomain: string | undefined = domain;
|
||||
|
||||
while (currentDomain) {
|
||||
if (blacklist.has(currentDomain)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const nextDot = currentDomain.indexOf('.');
|
||||
|
||||
if (nextDot === -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
currentDomain = currentDomain.slice(nextDot + 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if signup is enabled for the given provider.
|
||||
* The master switch takes precedence over the per-provider flags.
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"konva": "^10.0.9",
|
||||
"kysely": "0.29.2",
|
||||
"luxon": "^3.7.2",
|
||||
"mailchecker": "^6.0.20",
|
||||
"nanoid": "^5.1.6",
|
||||
"oslo": "^0.17.0",
|
||||
"p-map": "^7.0.4",
|
||||
|
||||
Reference in New Issue
Block a user