Email typo check on new addresses: "Did you mean you@gmail.com?" for gmai.com / gmial.com / hotmial.com / outlook.comz / gmail.con etc., and refuse domains that cannot receive mail (no MX/A). Applies only to addresses with no account yet (existing members always sign in), on sign-in/sign-up, password signup and the support form; skipped when the server has no mail key (local QA). DNS errors fail open. Same emailcheck.js in IAP and LinkSpin. Prompted by SendGrid bounces to gmai.com and outlook.comz (2026-10-22).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-22 06:09:38 -05:00
parent 8b1395a90c
commit 3ee605a8bf
2 changed files with 112 additions and 0 deletions
+8
View File
@@ -18,6 +18,10 @@ const auth = require('./auth');
const accounts = require('./accounts');
const ads = require('./ads');
const mailer = require('./mailer');
const { emailIssue } = require('./emailcheck'); // typo / no-mail-domain check for NEW addresses (2026-10-22)
// only addresses we have never seen get the typo check; existing members always sign in with what they have.
// Skipped when this server cannot send mail (local QA copies sign in as @example.com via devCode).
const newEmailIssue = async e => (!mailer.hasKey() || (await accounts.byEmail(e)) ? null : emailIssue(e));
const messages = require('./messages');
const reports = require('./reports');
const drip = require('./drip');
@@ -2201,6 +2205,7 @@ const server = http.createServer(async (req, res) => {
const acct = s && s.email ? await accounts.byEmail(s.email) : null; // signed in: the ticket is theirs, whatever was typed
const email = acct ? acct.email : String(b.email || '').trim().toLowerCase();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) return json(res, 400, { error: 'That email address does not look right.' });
if (!acct) { const iss = await newEmailIssue(email); if (iss) return json(res, 400, { error: iss.error, suggestion: iss.suggestion }); } // replies must reach them
const guard = supportGuard(req, b, email);
if (guard) return json(res, guard.status, guard.body);
const r = await tickets.create({ source: 'public', email, name: b.name || (acct && acct.username) || '', username: acct && acct.username, subject: b.subject, category: b.category, body: b.body });
@@ -2241,6 +2246,7 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/signup' && req.method === 'POST') {
const b = await readBody(req);
if (fraud.isBlocked(b.email)) return json(res, 403, { error: 'This address cannot open an account.' });
{ const iss = await newEmailIssue(String(b.email || '').trim().toLowerCase()); if (iss) return json(res, 400, { error: iss.error, suggestion: iss.suggestion }); }
const pendS = pendingSponsor.get(String(b.email || '').trim().toLowerCase());
const ref = pageTok(b.ref) || parseCookies(req)['iap.sponsor'] || (pendS && pendS.ref) || ''; // last-touch attribution, locked at account creation
const r = await accounts.signup(b.email, b.password, ref);
@@ -2269,6 +2275,7 @@ const server = http.createServer(async (req, res) => {
const devHdr = fraud.deviceOf(req) ? undefined : { 'Set-Cookie': fraud.deviceCookie(fraud.newDeviceId(), IS_PROD) }; // browser id for one-account-per-person checks
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(e)) return json(res, 400, { error: 'That email address does not look right.' });
if (fraud.isBlocked(e)) return json(res, 403, { error: 'This address cannot open an account.' });
{ const iss = await newEmailIssue(e); if (iss) return json(res, 400, { error: iss.error, suggestion: iss.suggestion }); }
const prev = emailCodes.get(e);
if (prev && Date.now() < prev.nextAt) { console.log('signup-guard cooldown', clientIp(req), e.replace(/^(.).*(@.*)$/, '$1***$2')); return json(res, 429, { error: 'Code already sent. Give it a minute, then try again.' }, devHdr); }
const guard = codeGuard(req, b); // honeypot, form age, per-IP + global limits, icon check once limited
@@ -2374,6 +2381,7 @@ const server = http.createServer(async (req, res) => {
const e = String(b.email || '').trim().toLowerCase();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(e)) return json(res, 400, { error: 'That email address does not look right.' }, cors);
if (fraud.isBlocked(e)) return json(res, 403, { error: 'This address cannot open an account.' }, cors);
{ const iss = await newEmailIssue(e); if (iss) return json(res, 400, { error: iss.error, suggestion: iss.suggestion }, cors); }
const prev = emailCodes.get(e);
if (prev && Date.now() < prev.nextAt) return json(res, 429, { error: 'Code already sent. Give it a minute, then try again.' }, cors);
const guard = codeGuard(req, b); // honeypot, form age, per-IP + global limits, icon check once limited