networksso.js: the network-wide copy (Marty 2026-11-15). Loop guard TRIED_AGE 30 min -> 120 s (the 30-minute guard blocked Marty's silent sign-in on LinkSpin); NAMES gains fivex (5xYourTeam); a provider refuses an unknown r= instead of answering it as its peer (IAP answered 5xYourTeam as LinkSpin, the loop Marty hit). Byte-identical in IAP, LinkSpin, VBB, DLB, ViralAdBlitz, DownlineHydra, 5xYourTeam (DLB also catches up with the 2026-11-14 deliberate-tap pieces it was missing). qa smoke: 5x 160/160, VBB 249/249, VAB 198/198, DLB 131/131, DH 210/211 (the 1 front-page check also fails on a clean HEAD).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+27
-8
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// One flow, used two ways. R = the site the member is going TO (receiver), P = the site they are signed in on (provider).
|
// One flow, used two ways. R = the site the member is going TO (receiver), P = the site they are signed in on (provider).
|
||||||
// 1. R GET /sso/start?mode=go|check&to=/path R makes a random state, keeps it in a 5-minute HttpOnly cookie (nsso.st),
|
// 1. R GET /sso/start?mode=go|check&to=/path R makes a random state, keeps it in a 5-minute HttpOnly cookie (nsso.st),
|
||||||
// sets the loop guard (nsso.tried, 30 minutes) and sends the browser to P.
|
// sets the loop guard (nsso.tried, 2 minutes) and sends the browser to P.
|
||||||
// 2. P GET /sso/check?st=<state>&to=/path P looks at its OWN member session (never the admin portal). Signed in:
|
// 2. P GET /sso/check?st=<state>&to=/path P looks at its OWN member session (never the admin portal). Signed in:
|
||||||
// P mints a token bound to R, the state and the email, and sends the browser
|
// P mints a token bound to R, the state and the email, and sends the browser
|
||||||
// to R /sso/in?t=<token>. Not signed in: R /sso/in?none=1&to=/path.
|
// to R /sso/in?t=<token>. Not signed in: R /sso/in?none=1&to=/path.
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
// Outbound links: P GET /go/<peer>?to=/path is the hop a signed-in member's cross-site link points at. Signed out (or the
|
// Outbound links: P GET /go/<peer>?to=/path is the hop a signed-in member's cross-site link points at. Signed out (or the
|
||||||
// secret not set), it is a plain redirect to the other site, so it is always safe to link through.
|
// secret not set), it is a plain redirect to the other site, so it is always safe to link through.
|
||||||
// Silent check: R's sign-in page calls GET /api/sso/status; { check: true } means "bounce once through P". The guard cookie
|
// Silent check: R's sign-in page calls GET /api/sso/status; { check: true } means "bounce once through P". The guard cookie
|
||||||
// stops a second bounce for 30 minutes, signing out sets nsso.off (12 hours, cleared by the next deliberate cross-site link),
|
// stops a second bounce for 2 minutes (30 until 2026-11-15, when it blocked Marty's silent sign-in on LinkSpin), signing out sets nsso.off (12 hours, cleared by the next deliberate cross-site link),
|
||||||
// bots and non-page fetches never bounce.
|
// bots and non-page fetches never bounce.
|
||||||
// Token: "v1.<base64url JSON>.<base64url HMAC-SHA256(NETWORK_SSO_SECRET, 'nsso.v1.' + JSON part)>", JSON = { iss, aud, email,
|
// Token: "v1.<base64url JSON>.<base64url HMAC-SHA256(NETWORK_SSO_SECRET, 'nsso.v1.' + JSON part)>", JSON = { iss, aud, email,
|
||||||
// st, to, iat, exp, n[, wallet, name] }. The token grants a plain member session and nothing else: no wallet action, payout or purchase rides on it.
|
// st, to, iat, exp, n[, wallet, name] }. The token grants a plain member session and nothing else: no wallet action, payout or purchase rides on it.
|
||||||
@@ -34,10 +34,12 @@ const enabled = () => SECRET().length >= 32;
|
|||||||
const TTL = 60 * 1000; // token life
|
const TTL = 60 * 1000; // token life
|
||||||
const SKEW = 30 * 1000; // clock skew allowed between the two servers
|
const SKEW = 30 * 1000; // clock skew allowed between the two servers
|
||||||
const STATE_AGE = 300; // seconds: the state cookie
|
const STATE_AGE = 300; // seconds: the state cookie
|
||||||
const TRIED_AGE = 1800; // seconds: one silent check per browser per 30 minutes
|
const GO_STATE_AGE = 1200; // seconds: the state cookie on a deliberate tap (time to sign in on the provider first, 2026-11-14)
|
||||||
|
const BACK_AGE = 1200; // seconds: the provider remembers an unfinished deliberate check while the member signs in
|
||||||
|
const TRIED_AGE = 120; // seconds: one silent check per browser per 2 minutes (loop guard only; 30 minutes until 2026-11-15)
|
||||||
const OFF_AGE = 12 * 3600; // seconds: no silent check after a sign-out on this site
|
const OFF_AGE = 12 * 3600; // seconds: no silent check after a sign-out on this site
|
||||||
const HINT_AGE = 300; // seconds: the email prefill when the member is not here yet
|
const HINT_AGE = 300; // seconds: the email prefill when the member is not here yet
|
||||||
const NAMES = { iap: 'InstantAdPay', linkspin: 'LinkSpin', bannerline: 'Downline Banners' };
|
const NAMES = { iap: 'InstantAdPay', linkspin: 'LinkSpin', bannerline: 'Downline Banners', vbb: 'Viral Banner Blitz', viraladblitz: 'ViralAdBlitz', downlinehydra: 'DownlineHydra', fivex: '5xYourTeam' }; // vbb = Viral Banner Blitz, a wallet site like Downline Banners (2026-11-14); viraladblitz = ViralAdBlitz, a wallet site like VBB (2026-11-15); downlinehydra = DownlineHydra (2026-11-15); fivex = 5xYourTeam (2026-11-15)
|
||||||
const WALLET_RE = /^0x[0-9a-f]{40}$/;
|
const WALLET_RE = /^0x[0-9a-f]{40}$/;
|
||||||
|
|
||||||
let C = null; // { self, peer, peerBase(), isProd, dataDir, db, member(req), accept(email, req, v), signIn(email, req, v), landing(to), signinPath(to), defaultPath,
|
let C = null; // { self, peer, peerBase(), isProd, dataDir, db, member(req), accept(email, req, v), signIn(email, req, v), landing(to), signinPath(to), defaultPath,
|
||||||
@@ -160,20 +162,34 @@ async function handle(req, res, u) {
|
|||||||
const c = cookies(req);
|
const c = cookies(req);
|
||||||
if (mode === 'check' && (c['nsso.tried'] || c['nsso.off'])) return go(res, to);
|
if (mode === 'check' && (c['nsso.tried'] || c['nsso.off'])) return go(res, to);
|
||||||
const st = crypto.randomBytes(16).toString('hex');
|
const st = crypto.randomBytes(16).toString('hex');
|
||||||
const set = [ck('nsso.st', st, STATE_AGE, true), ck('nsso.tried', '1', TRIED_AGE, true)];
|
const set = [ck('nsso.st', st, mode === 'go' ? GO_STATE_AGE : STATE_AGE, true), ck('nsso.tried', '1', TRIED_AGE, true)];
|
||||||
if (mode === 'go' && c['nsso.off']) set.push(ck('nsso.off', '', 0, true));
|
if (mode === 'go' && c['nsso.off']) set.push(ck('nsso.off', '', 0, true));
|
||||||
return go(res, (from ? from() : C.peerBase()) + '/sso/check?st=' + st + (C.from ? '&r=' + C.self : '') + '&to=' + encodeURIComponent(to), set);
|
return go(res, (from ? from() : C.peerBase()) + '/sso/check?st=' + st + (C.from ? '&r=' + C.self : '') + '&to=' + encodeURIComponent(to) + (mode === 'go' ? '&m=go' : ''), set);
|
||||||
|
}
|
||||||
|
if (p === '/sso/resume') { // signed in on the provider after a deliberate tap: finish the check it was asked for (2026-11-14)
|
||||||
|
const q = new URLSearchParams(cookies(req)['nsso.back'] || '');
|
||||||
|
const clear = [ck('nsso.back', '', 0, true)];
|
||||||
|
if (!/^[a-f0-9]{32}$/.test(q.get('st') || '')) return go(res, C.defaultPath, clear);
|
||||||
|
return go(res, '/sso/check?st=' + q.get('st') + (q.get('r') ? '&r=' + encodeURIComponent(q.get('r')) : '') + '&to=' + encodeURIComponent(safePath(q.get('to'), '/')), clear);
|
||||||
}
|
}
|
||||||
if (p === '/sso/check') {
|
if (p === '/sso/check') {
|
||||||
const st = String(u.searchParams.get('st') || '');
|
const st = String(u.searchParams.get('st') || '');
|
||||||
const to = safePath(u.searchParams.get('to'), '/');
|
const to = safePath(u.searchParams.get('to'), '/');
|
||||||
const r = String(u.searchParams.get('r') || '');
|
const r = String(u.searchParams.get('r') || '');
|
||||||
const wb = r && r !== C.peer ? walletBase(r) : null; // a wallet site asking: the token carries the wallet
|
const wb = r && r !== C.peer ? walletBase(r) : null; // a wallet site asking: the token carries the wallet
|
||||||
|
if (r && r !== C.peer && !wb) { log('check: unknown site asking, nothing sent', null, r.slice(0, 20)); return go(res, C.defaultPath); } // never answer an unknown site as if the peer asked (2026-11-15: 5xYourTeam was sent to LinkSpin)
|
||||||
const base = wb ? wb() : C.peerBase(), aud = wb ? r : C.peer, forName = NAMES[aud] || aud;
|
const base = wb ? wb() : C.peerBase(), aud = wb ? r : C.peer, forName = NAMES[aud] || aud;
|
||||||
const none = base + '/sso/in?none=1&to=' + encodeURIComponent(to);
|
const none = base + '/sso/in?none=1&to=' + encodeURIComponent(to);
|
||||||
if (!enabled() || !/^[a-f0-9]{32}$/.test(st)) return go(res, none);
|
if (!enabled() || !/^[a-f0-9]{32}$/.test(st)) return go(res, none);
|
||||||
let s = null; try { s = await C.member(req); } catch (e) {}
|
let s = null; try { s = await C.member(req); } catch (e) {}
|
||||||
if (!s || !s.email) { log('check: not signed in here', null, 'for ' + forName); return go(res, none); }
|
if (!s || !s.email) {
|
||||||
|
if (u.searchParams.get('m') === 'go' && !isBot(req)) { // a deliberate tap: sign in here first, then /sso/resume finishes the trip
|
||||||
|
log('check: not signed in here, asking to sign in', null, 'for ' + forName);
|
||||||
|
const back = new URLSearchParams({ st, to }); if (r) back.set('r', r);
|
||||||
|
return go(res, C.signinPath(C.defaultPath), [ck('nsso.back', back.toString(), BACK_AGE, true)]);
|
||||||
|
}
|
||||||
|
log('check: not signed in here', null, 'for ' + forName); return go(res, none);
|
||||||
|
}
|
||||||
let w = null;
|
let w = null;
|
||||||
if (wb) { try { w = await C.wallet(s); } catch (e) {} if (!w || !WALLET_RE.test(String(w.address || '').toLowerCase())) { log('check: no wallet on the account', s.email, 'for ' + forName); return go(res, none); } }
|
if (wb) { try { w = await C.wallet(s); } catch (e) {} if (!w || !WALLET_RE.test(String(w.address || '').toLowerCase())) { log('check: no wallet on the account', s.email, 'for ' + forName); return go(res, none); } }
|
||||||
log('token issued', s.email, 'for ' + forName);
|
log('token issued', s.email, 'for ' + forName);
|
||||||
@@ -209,4 +225,7 @@ async function handle(req, res, u) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { init, handle, enabled, mint, verify, spend, safePath, isBot, offCookie, mask, TTL, NAMES };
|
// true when this browser came here from a deliberate network tap and still has to finish it after signing in
|
||||||
|
const pendingBack = req => !!cookies(req)['nsso.back'];
|
||||||
|
|
||||||
|
module.exports = { init, handle, enabled, pendingBack, mint, verify, spend, safePath, isBot, offCookie, mask, TTL, NAMES };
|
||||||
|
|||||||
Reference in New Issue
Block a user