Sponsor survives a lost cookie: join page sends its own token with the code request, server remembers it per email for 30 days, framed visitors offered a full window

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-29 09:48:06 -05:00
parent b5baaf27e8
commit a7a15615ec
21 changed files with 1217 additions and 1188 deletions
+1 -1
View File
@@ -510,7 +510,7 @@
</div>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/admin.js?v=20260928c"></script>
</body>
</html>
+1 -1
View File
@@ -189,7 +189,7 @@ window.IAP = (function () {
await formSettled();
for (let i = 0; i < 4; i++) {
const r = await (await fetch('/api/auth/email/start', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, fts: FORM_TS, hp_field_x9: hpValue(o.honeypot), pick }) })).json();
body: JSON.stringify({ email, fts: FORM_TS, hp_field_x9: hpValue(o.honeypot), pick, ref: o.ref || null, angle: o.angle || null }) })).json(); // ref = the join page's own link token, so the sponsor survives a lost cookie
if (r.challenge && o.host) { pick = await iconCheck(o.host, r.challenge, r.error); continue; }
if (r.error) throw new Error(r.error);
return r;
+7 -2
View File
@@ -62,7 +62,7 @@
function busy(btn, fn) {
return async () => { if (btn.disabled) return; btn.disabled = true; err(''); try { await fn(); } catch (e) { err(e.message || 'Something went wrong.'); } finally { btn.disabled = false; } };
}
const codeOpts = () => ({ honeypot: $('jnWebsite'), host: $('jnCheck') });
const codeOpts = () => ({ honeypot: $('jnWebsite'), host: $('jnCheck'), ref: linkTok, angle: v || '' }); // the page's own token rides with the code request (cookie may be blocked in a frame)
const send = busy($('jnSend'), async () => {
const r = await IAP.requestCode($('jnEmail').value, codeOpts());
$('jnCodeRow').hidden = false; $('jnVerify').hidden = false; $('jnSend').hidden = true; $('jnResend').hidden = false;
@@ -79,7 +79,7 @@
IAP.status('Fresh code sent.', 'ok');
}));
$('jnVerify').addEventListener('click', busy($('jnVerify'), async () => {
await api('/api/auth/email/verify', { email: $('jnEmail').value, code: $('jnCode').value, newsletter: !!$('jnNews').checked, followups: !!$('jnNews').checked });
await api('/api/auth/email/verify', { email: $('jnEmail').value, code: $('jnCode').value, newsletter: !!$('jnNews').checked, followups: !!$('jnNews').checked, ref: linkTok });
IAP.status('You are in. Taking you to your dashboard…', 'ok');
location.href = '/my?welcome=1'; // dashboard runs the username step + welcome tour on arrival
}));
@@ -89,6 +89,11 @@
// sponsor line (the link opened most recently sets the sponsor; it locks at account creation)
let sponsorName = '';
const linkTok = (location.pathname.match(/^\/join\/([^/?#]+)/) || [])[1] || '';
// Shown inside another site (a traffic-exchange frame)? Browsers refuse our cookies there, so the invitation
// could be lost. Offer the full window; the link carries the token, so the top-level visit sets the cookie.
try { if (window.top !== window.self) { const n = document.createElement('p'); n.className = 'small'; n.style.cssText = 'margin:0 0 10px;padding:10px 12px;border:1px solid var(--line-strong);border-radius:10px;background:var(--mint-soft)';
n.innerHTML = '<b>Viewing this inside another site?</b> <a href="' + location.href.replace(/"/g, '') + '" target="_top" rel="noopener">Open InstantAdPay in a full window</a> so your invitation stays attached to your account.';
const row = $('jnEmail') && $('jnEmail').closest('p'); if (row) row.parentNode.insertBefore(n, row); } } catch (e) {}
fetch('/api/sponsor' + (linkTok ? '?ref=' + encodeURIComponent(linkTok) : '')).then(r => r.json()).then(sp => {
if (sp && sp.invited && sp.name) {
sponsorName = sp.name;
+1 -1
View File
@@ -141,7 +141,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.</div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/contract.js?v=20260908p"></script>
<script src="/assets/chat.js?v=20260906m"></script>
</body>
+1 -1
View File
@@ -26,7 +26,7 @@
<p class="muted small">You decide whether, and how much, to spend. Never spend more than you can afford to lose.</p>
</div>
</div></section>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/legal.js?v=20260908a"></script>
</body>
</html>
+1 -1
View File
@@ -83,6 +83,6 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
</body>
</html>
+1 -1
View File
@@ -70,6 +70,6 @@
</footer>
</div>
<script src="/assets/friday.js?v=20260925a"></script>
<script src="/assets/common.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script>
</body>
</html>
+1 -1
View File
@@ -497,7 +497,7 @@
</div>
</section>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/wallet.js?v=20260909c"></script>
<script src="/assets/home.js?v=20260929b"></script>
<script src="/assets/chat.js?v=20260906m"></script>
+2 -2
View File
@@ -157,7 +157,7 @@
InstantAdPay · <a href="/contract">Contract</a> · <a href="/terms">Terms</a> · <a href="/privacy">Privacy</a> · <a href="/disclaimer">Disclaimer</a>
</div>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/join.js?v=20260914a"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/join.js?v=20260929b"></script>
</body>
</html>
+1 -1
View File
@@ -104,7 +104,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees.</div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/launch.js?v=20260915b"></script>
</body>
</html>
+1 -1
View File
@@ -39,7 +39,7 @@
<div>InstantAdPay · <a href="/">how it works</a> · <a id="contractLink" href="#" target="_blank" rel="noopener">contract source ↗</a></div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/ledger.js?v=20260906m"></script>
<script src="https://polhunter.com/embed.js" data-slots="1" async></script>
<script src="/assets/chat.js?v=20260906m"></script>
+1 -1
View File
@@ -1082,7 +1082,7 @@
</div>
</div>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/wallet.js?v=20260911a"></script>
<script src="/assets/promo.js?v=20260929c"></script>
<script src="/assets/my.js?v=20260929g"></script>
+1 -1
View File
@@ -128,7 +128,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford to lose.</div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/partners.js?v=20260914a"></script>
</body>
</html>
+1 -1
View File
@@ -192,7 +192,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never spend what you cannot afford.</div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/plays.js?v=20260910b"></script>
</body>
</html>
+1 -1
View File
@@ -29,7 +29,7 @@
<p class="muted small">We use reasonable safeguards, but no system is perfectly secure. Protect your email and your wallet.</p>
</div>
</div></section>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/legal.js?v=20260908a"></script>
</body>
</html>
+1 -1
View File
@@ -38,7 +38,7 @@
<p class="muted small" style="margin-top:18px">See also the <a href="/disclaimer">Disclaimer</a> and <a href="/privacy">Privacy Policy</a>.</p>
</div>
</div></section>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/legal.js?v=20260908a"></script>
</body>
</html>
+1 -1
View File
@@ -34,7 +34,7 @@
<p><a href="/ledger">← Back to the live ledger</a> · <a href="/contract">Read the contract review</a></p>
</div>
</section>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/tx.js?v=20260906m"></script>
</body>
</html>
+1 -1
View File
@@ -47,7 +47,7 @@
</div>
</div>
</section>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/wall.js?v=20260911v"></script>
</body>
</html>
+1 -1
View File
@@ -121,7 +121,7 @@
<div class="small">Advertising services with a performance referral program. Not an investment product; no income guarantees. Crypto transactions are irreversible. Never share your recovery phrase.</div>
</footer>
</div>
<script src="/assets/common.js?v=20260923b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/wallets.js?v=20260911b"></script>
</body>
</html>
+1 -1
View File
@@ -63,6 +63,6 @@
</footer>
</div>
<script src="/assets/wednesday.js?v=20260929c"></script>
<script src="/assets/common.js?v=20260923b"></script>
<script src="/assets/common.js?v=20260929b"></script>
</body>
</html>
+28 -4
View File
@@ -183,6 +183,23 @@ function chatLimited(ip) {
}
// magic-code sign-in: emailLower -> {code, exp, tries}
const emailCodes = new Map();
// Sponsor bound to the sign-up, not only to a cookie (Marty, 2026-09-29: nancyr #180 and others "supposed to land under
// Mad Dog" were created with no sponsor and fell to the company). The iap.sponsor cookie is SameSite=Lax, so it is
// rejected when the join page is shown inside another site (traffic-exchange frames), and it never crosses browsers
// (in-app browser -> mail app -> default browser). So: the join page sends the token from its own URL with the code
// request, the server remembers "this email asked for a code under <token>" for 30 days on disk (deploys restart the
// process), and account creation uses page token, then cookie, then that memory. A token-less request never
// overwrites a remembered token.
const pendingSponsor = {
FILE: () => path.join(DATA_DIR, 'pending-sponsors.json'), db: null,
load() { try { this.db = JSON.parse(fs.readFileSync(this.FILE(), 'utf8')); } catch (e) { this.db = {}; } },
save() { try { fs.writeFileSync(this.FILE(), JSON.stringify(this.db)); } catch (e) {} },
set(email, f) { if (!email || !f || !f.ref) return; if (!this.db) this.load(); this.db[email] = { ref: f.ref, via: f.via || '', joinedRef: f.joinedRef || null, at: Date.now() }; this.prune(); this.save(); },
get(email) { if (!this.db) this.load(); const r = this.db[email]; return r && Date.now() - r.at < 30 * 86400e3 ? r : null; },
del(email) { if (!this.db) this.load(); if (this.db[email]) { delete this.db[email]; this.save(); } },
prune() { const cut = Date.now() - 30 * 86400e3; for (const k of Object.keys(this.db)) if (this.db[k].at < cut) delete this.db[k]; }
};
const pageTok = v => { const t = String(v || '').trim().toLowerCase(); return /^[a-z0-9_]{1,40}$/.test(t) ? (JOIN_ALIASES[t] || t) : ''; }; // a token the join page read from its own URL
// ── sign-up code guard (Marty, 2026-09-11): the email box is one field and one
// tap, so nothing visible stands in a human's way. Bots hit four invisible walls:
// a honeypot field, a minimum form age, per-IP + global send limits, and, only
@@ -1462,9 +1479,11 @@ 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 ref = parseCookies(req)['iap.sponsor'] || ''; // last-touch attribution, locked at account creation
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);
if (r.error) return json(res, 400, r);
pendingSponsor.del(String(b.email || '').trim().toLowerCase());
// sponsor is notified once the new member picks a username (onboarding),
// so the email can name them — see /api/my/profile
if (b.newsletter) sendy.subscribe(r.account.email, r.account.username || '').catch(() => {}); // pre-checked opt-in, silent
@@ -1494,6 +1513,8 @@ const server = http.createServer(async (req, res) => {
if (guard) return json(res, guard.status, guard.body, devHdr);
const code = String(Math.floor(100000 + Math.random() * 900000));
emailCodes.set(e, { code, exp: Date.now() + 15 * 60 * 1000, tries: 0, nextAt: Date.now() + 60 * 1000 });
{ const ck = parseCookies(req); const bound = pageTok(b.ref) || ck['iap.sponsor'] || '';
if (bound && !(await accounts.byEmail(e))) pendingSponsor.set(e, { ref: bound, via: pageTok(b.ref) ? (String(b.angle || '').toLowerCase().slice(0, 20) || ck['iap.angle'] || 'page') : (ck['iap.angle'] || ''), joinedRef: decodeURIComponent(ck['iap.ref'] || '') || null }); }
if (mailer.hasKey()) {
try { await mailer.sendCode(e, code); } catch (err) {
console.error('sendCode failed', err.message);
@@ -1513,9 +1534,11 @@ const server = http.createServer(async (req, res) => {
if (rec.tries > 6) { emailCodes.delete(e); return json(res, 400, { error: 'Too many tries. Request a fresh code.' }); }
if (String(b.code || '').trim() !== rec.code) return json(res, 400, { error: 'That code does not match.' });
emailCodes.delete(e);
const ref = parseCookies(req)['iap.sponsor'] || '';
const via = parseCookies(req)['iap.angle'] || '';
const joinedRef = decodeURIComponent(parseCookies(req)['iap.ref'] || '') || null;
const pend = pendingSponsor.get(e);
const ref = pageTok(b.ref) || parseCookies(req)['iap.sponsor'] || (pend && pend.ref) || '';
const via = parseCookies(req)['iap.angle'] || (pend && pend.via) || '';
const joinedRef = decodeURIComponent(parseCookies(req)['iap.ref'] || '') || (pend && pend.joinedRef) || null;
if (ref && !parseCookies(req)['iap.sponsor']) console.log('sponsor recovered without cookie', e.replace(/^(.).*(@.*)$/, '$1***$2'), 'ref', ref, pageTok(b.ref) ? '(page token)' : '(remembered from the code request)');
if (fraud.isSuspended(e)) return json(res, 403, { error: 'This account is suspended. Contact support.' });
let fraudFlags = [];
const existing = await accounts.byEmail(e);
@@ -1530,6 +1553,7 @@ const server = http.createServer(async (req, res) => {
}
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) pendingSponsor.del(e);
if (r.created) { fraud.recordSignup(e, req, fraudFlags).catch(() => {}); if (fraudFlags.length) fraudAlert(e, { flags: fraudFlags, ip: fraud.ipOf(req) }, null, false); }
else fraud.recordSeen(e, req).catch(() => {});
// the lead is in the door: queue the getting-started sequence (opt-in box is pre-checked on both forms)