From ecfe97b90a428bc5ee9470fbd86fd0c9b8f15a2a Mon Sep 17 00:00:00 2001 From: martbost Date: Wed, 30 Sep 2026 14:31:19 -0500 Subject: [PATCH] Sign-in mode 'key': anyone whose browser holds the curtain pass (opened the key link) may play; tester list still honoured Co-Authored-By: Claude Fable 5.1 --- lib/ledger.js | 2 +- public/admin.html | 2 +- server.js | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ledger.js b/lib/ledger.js index 77d5183..8747beb 100644 --- a/lib/ledger.js +++ b/lib/ledger.js @@ -25,7 +25,7 @@ const DEFAULTS = { itemPol: { shield: 0.05, slow: 0.03 }, // hangar items paid from the POL balance (the sink) itemDrips: { magnet: 250, ship: 600 }, // hangar items paid in drips (never money) testers: [], // emails or member ids allowed through the hand-off while signups = 'testers' - signups: 'testers' // 'testers' | 'open' | 'closed' + signups: 'testers' // 'testers' | 'key' (tester list or the curtain pass) | 'open' | 'closed' }; function settings() { return Object.assign({}, DEFAULTS, store.read('settings', {})); } function setSettings(patch) { return store.update('settings', {}, s => Object.assign(s, patch)); } diff --git a/public/admin.html b/public/admin.html index 7a4bb3c..1f07446 100644 --- a/public/admin.html +++ b/public/admin.html @@ -31,7 +31,7 @@
-
+
diff --git a/server.js b/server.js index 094b5bf..4e253c9 100644 --- a/server.js +++ b/server.js @@ -86,11 +86,15 @@ function curtained(req, res, u) { } function admin(req, u) { const k = req.headers['x-admin-key'] || u.searchParams.get('key'); return !!(ADMIN_KEY && k && k.length === ADMIN_KEY.length && crypto.timingSafeEqual(Buffer.from(k), Buffer.from(ADMIN_KEY))); } // who may come through the hand-off -function allowed(claims) { +// 'key' (Marty, 2026-09-30: "let anyone I send the link to with the key test"): the hand-off is accepted when the +// browser carries the curtain pass, i.e. the person opened the tester link with the key first. The list still works too. +function hasPass(req) { const m = /(?:^|;\s*)dr\.pass=([^;]+)/.exec(req.headers.cookie || ''); return !!(CURTAIN && m && decodeURIComponent(m[1]) === CURTAIN); } +function allowed(claims, req) { const s = ledger.settings(); const mode = String(process.env.DR_SIGNUPS || s.signups || 'testers'); if (mode === 'open') return true; if (mode === 'closed') return false; const list = (s.testers || []).map(x => String(x).trim().toLowerCase()).filter(Boolean); - return list.includes(String(claims.email || '').toLowerCase()) || list.includes(String(claims.memberId)); + if (list.includes(String(claims.email || '').toLowerCase()) || list.includes(String(claims.memberId))) return true; + return mode === 'key' && req && hasPass(req); } // the IAP -> game callback is signed over the timestamp and the raw body with the shared secret function callbackOk(req, raw) { @@ -119,8 +123,8 @@ const server = http.createServer(async (req, res) => { if (p === '/auth') { const r = sso.verify(u.searchParams.get('t')); if (r.error) return page(res, 400, 'Sign-in did not work', '

' + esc(r.error) + '

Try again from InstantAdPay

'); - if (!allowed(r.claims)) { console.log('hand-off refused: not a tester', r.claims.memberId, r.claims.username || '', String(r.claims.email || '').replace(/^(.).*(@.*)$/, '$1***$2')); notify('refused', { memberId: r.claims.memberId, username: r.claims.username, email: r.claims.email }).catch(() => {}); } - if (!allowed(r.claims)) return page(res, 403, 'Not on the tester list yet', '

Drip Runner is in a closed trial. Your InstantAdPay account (' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + ') is not on the tester list. Ask Marty to add you.

'); + if (!allowed(r.claims, req)) { console.log('hand-off refused: not a tester', r.claims.memberId, r.claims.username || '', String(r.claims.email || '').replace(/^(.).*(@.*)$/, '$1***$2')); notify('refused', { memberId: r.claims.memberId, username: r.claims.username, email: r.claims.email }).catch(() => {}); } + if (!allowed(r.claims, req)) { const keyMode = String(process.env.DR_SIGNUPS || ledger.settings().signups) === 'key'; return page(res, 403, keyMode ? 'Open the tester link first' : 'Not on the tester list yet', keyMode ? '

Drip Runner is in a closed trial. Open the tester link Marty sent you (the one with the key) in this same browser, then tap Open Drip Runner again. Your InstantAdPay account is ' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + '.

' : '

Drip Runner is in a closed trial. Your InstantAdPay account (' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + ') is not on the tester list. Ask Marty to add you.

'); } const existing = sso.fromRequest(req); let sid; if (existing && existing.memberId === Number(r.claims.memberId)) { sso.refresh(existing.sid, r.claims); sid = existing.sid; } @@ -164,7 +168,7 @@ const server = http.createServer(async (req, res) => { if (p === '/api/admin/settings' && req.method === 'POST') { const { body } = await readBody(req); const patch = {}; for (const k of ['usdPerCredit', 'creditsPerVisit', 'poolSharePct', 'usdPerPolFallback', 'dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'lowBalancePol']) if (body[k] != null && body[k] !== '') patch[k] = Number(body[k]); - if (body.signups && ['testers', 'open', 'closed'].includes(body.signups)) patch.signups = body.signups; + if (body.signups && ['testers', 'key', 'open', 'closed'].includes(body.signups)) patch.signups = body.signups; if (Array.isArray(body.testers)) patch.testers = body.testers.map(x => String(x).trim().toLowerCase()).filter(Boolean).slice(0, 500); if (body.itemPol && typeof body.itemPol === 'object') patch.itemPol = Object.assign({}, ledger.settings().itemPol, body.itemPol); if (body.itemDrips && typeof body.itemDrips === 'object') patch.itemDrips = Object.assign({}, ledger.settings().itemDrips, body.itemDrips);