diff --git a/networksso.js b/networksso.js index a446dfa..f523b57 100644 --- a/networksso.js +++ b/networksso.js @@ -34,6 +34,8 @@ const enabled = () => SECRET().length >= 32; const TTL = 60 * 1000; // token life const SKEW = 30 * 1000; // clock skew allowed between the two servers const STATE_AGE = 300; // seconds: the state cookie +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 = 1800; // seconds: one silent check per browser per 30 minutes 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 @@ -160,9 +162,15 @@ async function handle(req, res, u) { const c = cookies(req); if (mode === 'check' && (c['nsso.tried'] || c['nsso.off'])) return go(res, to); 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)); - 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') { const st = String(u.searchParams.get('st') || ''); @@ -173,7 +181,14 @@ async function handle(req, res, u) { const none = base + '/sso/in?none=1&to=' + encodeURIComponent(to); if (!enabled() || !/^[a-f0-9]{32}$/.test(st)) return go(res, none); 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; 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); @@ -209,4 +224,7 @@ async function handle(req, res, u) { 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 }; diff --git a/public/assets/my.js b/public/assets/my.js index c96e182..ff76c59 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -989,6 +989,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str if (me.returnTo === 'gkshop' && !render.toGame) { render.toGame = true; location.href = '/gk/shop/resume'; return; } if (me.returnTo === 'spookydoors' && !render.toGame) { render.toGame = true; location.href = '/api/my/spookydoors'; return; } // Spooky Doors sent them here to sign in (2026-10-02) if (me.returnTo === 'polybreak' && !render.toGame) { render.toGame = true; location.href = '/api/my/polybreak'; return; } // PolyBreak sent them here to sign in (2026-10-13) + if (me.returnTo === 'nsso' && !render.toGame) { render.toGame = true; location.href = '/sso/resume'; return; } // tapped "Sign in with InstantAdPay" on another network site while signed out here (2026-11-14) if (me.returnTo === 'forum' && !render.toGame) { render.toGame = true; location.href = '/api/my/forum'; return; } // Earners Corner forum sign-in (2026-11-10) if (me.returnTo === 'polminer' && !render.toGame) { render.toGame = true; location.href = '/api/my/polminer'; return; } // POL Miner sent them here to sign in (2026-10-28) if (me.returnTo === 'warpwares' && !render.toGame) { render.toGame = true; location.href = '/api/my/warpwares'; return; } // Warp & Wares sent them here to sign in (2026-10-29) diff --git a/public/my.html b/public/my.html index a1ff820..b25f6bd 100644 --- a/public/my.html +++ b/public/my.html @@ -1311,7 +1311,7 @@ - + diff --git a/qa/networksso.e2e.mjs b/qa/networksso.e2e.mjs index 77e7f11..89c6836 100644 --- a/qa/networksso.e2e.mjs +++ b/qa/networksso.e2e.mjs @@ -142,7 +142,8 @@ try { // a session that expired on the provider: the check answers none ctx = await newCtx({ iap: 'f'.repeat(64) }); page = await ctx.newPage(); await page.goto(LS + '/sso/start?mode=go&to=%2Fads'); await page.waitForTimeout(1500); - ok(!(await meOf(ctx, LS)).signedIn && page.url() === LS + '/ads', 'an expired IAP session: the check answers none, normal sign-in'); + ok(!(await meOf(ctx, LS)).signedIn && page.url().startsWith(IAP + '/my'), 'an expired IAP session on a deliberate tap: IAP asks for its own sign-in first (2026-11-14)', page.url()); + ok((await ctx.cookies(IAP)).some(c => c.name === 'nsso.back'), 'IAP remembers the unfinished trip while the member signs in'); await ctx.close(); // 6. not on the receiving site yet: C (IAP only) going to LinkSpin, D (LinkSpin only) going to IAP diff --git a/qa/networksso.test.cjs b/qa/networksso.test.cjs index 1df0262..f5bbea6 100644 --- a/qa/networksso.test.cjs +++ b/qa/networksso.test.cjs @@ -82,7 +82,7 @@ const b64u = b => Buffer.from(b).toString('base64').replace(/=+$/, '').replace(/ r = await call(R('/sso/start?to=/my', 'nsso.off=1')); ok(r.loc === '/my', 'after a sign-out here: no silent check'); r = await call(R('/sso/start?mode=go&to=/my', 'nsso.off=1')); - ok(/^https:\/\/ls\.example\/sso\/check\?st=[a-f0-9]{32}&to=%2Fmy$/.test(r.loc) && r.set.some(c => /^nsso\.off=;/.test(c)), 'a deliberate link from the other site still signs in after a sign-out (and lifts the 12-hour pause)'); + ok(/^https:\/\/ls\.example\/sso\/check\?st=[a-f0-9]{32}&to=%2Fmy&m=go$/.test(r.loc) && r.set.some(c => /^nsso\.off=;/.test(c)), 'a deliberate link from the other site still signs in after a sign-out (and lifts the 12-hour pause)'); r = await call(R('/sso/start?to=https://evil.example')); const stc = (r.set.find(c => c.startsWith('nsso.st=')) || '').split(';')[0].split('=')[1]; ok(/^[a-f0-9]{32}$/.test(stc) && r.set.some(c => /^nsso\.tried=1;.*Max-Age=1800/.test(c)) && r.set.every(c => /HttpOnly/.test(c) && /Secure/.test(c)) && r.loc.endsWith('&to=%2Fmy'), '/sso/start: HttpOnly state + 30-minute guard, off-site path replaced', r.loc); diff --git a/server.js b/server.js index 152bcca..4849852 100644 --- a/server.js +++ b/server.js @@ -2859,7 +2859,7 @@ const server = http.createServer(async (req, res) => { let memberId = 0; if (r.account.address) { try { memberId = await chain.memberIdByAccount(r.account.address); } catch (err) {} } const token = await auth.mintSession({ email: r.account.email, address: r.account.address, memberId }); - return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ clutterhunt: '/api/my/clutterhunt', spellwheel: '/api/my/spellwheel', polybreak: '/api/my/polybreak', polminer: '/api/my/polminer', turkeydrop: '/api/my/turkeydrop', warpwares: '/api/my/warpwares', polywarriors: '/api/my/polywarriors', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30) + return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ clutterhunt: '/api/my/clutterhunt', spellwheel: '/api/my/spellwheel', polybreak: '/api/my/polybreak', polminer: '/api/my/polminer', turkeydrop: '/api/my/turkeydrop', warpwares: '/api/my/warpwares', polywarriors: '/api/my/polywarriors', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || (networksso.pendingBack(req) ? '/sso/resume' : null) }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30) } // -- in-game sign-in (2026-10-03): see GAME_AUTH. Mirrors /api/auth/email/start + verify, minus cookies. @@ -3062,7 +3062,7 @@ const server = http.createServer(async (req, res) => { if (tankHold) sponsorBlocked = 'tankHold'; else if (!sponsorId && memberId !== _defSpon) { sponsorId = _defSpon; sponsorFallback = true; } // orphan fallback → #1 (never self-sponsor) if (memberId && acct && acct.memberId !== memberId) accounts.setMemberId(acct.email, memberId).catch(() => {}); - const out = { signedIn: true, gkShop: !!parseCookies(req)['iap.gkshop'], sdShop: !!parseCookies(req)['iap.sdshop'], pwMint: !!parseCookies(req)['iap.pwmint'], returnTo: ['turkeydrop', 'polhunter', 'driprunner', 'passivedrip', 'gemkingdom', 'gkshop', 'spookydoors', 'sdshop', 'pwmint', 'polybreak', 'polminer', 'warpwares', 'shardsofvalor', 'forum'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null, + const out = { signedIn: true, gkShop: !!parseCookies(req)['iap.gkshop'], sdShop: !!parseCookies(req)['iap.sdshop'], pwMint: !!parseCookies(req)['iap.pwmint'], returnTo: ['turkeydrop', 'polhunter', 'driprunner', 'passivedrip', 'gemkingdom', 'gkshop', 'spookydoors', 'sdshop', 'pwmint', 'polybreak', 'polminer', 'warpwares', 'shardsofvalor', 'forum'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : (networksso.pendingBack(req) ? 'nsso' : null), sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null, address: s.address || (acct && acct.address) || null, memberId, username: (acct && acct.username) || null, theme: (acct && acct.theme) || null, inviteAsk: !memberId && acct ? tank.inviteAsk(acct) : null, // the Who invited you card (2026-11-07)