Pre-launch whitelist LS_TESTERS: only listed emails/usernames can request or verify a sign-in code; public pages stay visible with the curtain down (Marty 2026-10-08)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-08 06:16:12 -05:00
parent a6bfa1ba42
commit 547c7ba465
+9 -1
View File
@@ -89,6 +89,11 @@ const IS_PROD = process.env.NODE_ENV === 'production';
const OUTBOUND_MAIL = process.env.OUTBOUND === 'on';
const SIGNUPS_OPEN = process.env.SIGNUPS !== 'closed';
const SHUT = { error: 'LinkSpin is not accepting new accounts right now.' };
// pre-launch whitelist (Marty 2026-10-08: public pages visible, nobody signs in unless whitelisted): LS_TESTERS = comma list of
// emails or usernames; empty = everyone with an account may sign in
const TESTERS = new Set(String(process.env.LS_TESTERS || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean));
const TESTING = { error: 'LinkSpin is in testing. Members get in on launch day.' };
const isTester = (email, acct) => !TESTERS.size || TESTERS.has(String(email || '').toLowerCase()) || TESTERS.has(String((acct && acct.username) || '').toLowerCase());
const SITE_FILE = path.join(DATA_DIR, 'site.json');
const db = require('./db');
@@ -1178,7 +1183,9 @@ 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.' });
// closed sign-ups shut the door to NEW accounts only; members already here (incl. imported shells) still get their code
if (!SIGNUPS_OPEN && !(await accounts.byEmail(e))) return json(res, 403, SHUT);
const acct0 = await accounts.byEmail(e);
if (!SIGNUPS_OPEN && !acct0) return json(res, 403, SHUT);
if (!isTester(e, acct0)) return json(res, 403, TESTING);
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.' }); }
const guard = codeGuard(req, b); // honeypot, form age, per-IP + global limits, icon check once limited
@@ -1209,6 +1216,7 @@ const server = http.createServer(async (req, res) => {
const joinedRef = decodeURIComponent(parseCookies(req)['iap.ref'] || '') || null;
// the code door creates an account on first use, so it is a sign-up door too
if (!SIGNUPS_OPEN && !(await accounts.byEmail(e))) return json(res, 403, SHUT);
if (!isTester(e, await accounts.byEmail(e))) return json(res, 403, TESTING);
const r = await accounts.ensure(e, ref, via, joinedRef); // first touch wins; existing accounts unchanged
if (r.error) return json(res, 400, r);
if (r.created) carry.onJoin(r.account, !!ref).catch(() => {}); // network sponsor carries over when no link was used (LinkSpin)