In-game sign-in: /signin runs the InstantAdPay kit (no trip to InstantAdPay), CSP admits instantadpay.com, dashboard and Level up links open InstantAdPay signed in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-03 10:02:47 -05:00
parent dd00cb1b57
commit 9c693fcf63
7 changed files with 95 additions and 10 deletions
+6 -4
View File
@@ -102,7 +102,8 @@ async function notify(kind, p) {
// ---- helpers ---------------------------------------------------------------------------------
const TYPES = { '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.js': 'application/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.json': 'application/json', '.webp': 'image/webp', '.mp4': 'video/mp4' };
const CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; form-action 'self'";
// instantadpay.com: the in-game sign-in kit (script), its API (connect) and the signed-in nudge form (form-action), 2026-10-03
const CSP = "default-src 'self'; script-src 'self' " + IAP + "; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self' " + IAP + "; frame-ancestors 'none'; form-action 'self' " + IAP;
const SEC = { 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'X-Frame-Options': 'DENY', 'Content-Security-Policy': CSP };
function json(res, code, body, extra) { res.writeHead(code, Object.assign({ 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }, SEC, extra || {})); res.end(JSON.stringify(body)); }
function sendFile(res, file, extra) {
@@ -173,7 +174,7 @@ const server = http.createServer(async (req, res) => {
// ---- sign-in by hand-off (passes the curtain: the member already came through IAP) ----
if (p === '/auth') {
const r = sso.verify(u.searchParams.get('t'));
if (r.error) return page(res, 400, 'Sign-in did not work', '<p>' + esc(r.error) + '</p><p><a class="btn" href="' + IAP + '/api/my/driprunner">Try again from InstantAdPay</a></p>');
if (r.error) return page(res, 400, 'Sign-in did not work', '<p>' + esc(r.error) + '</p><p><a class="btn" href="/signin">Try again</a></p>');
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 ? '<p>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) + '.</p>' : '<p>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.</p>'); }
const existing = sso.fromRequest(req);
@@ -220,6 +221,7 @@ const server = http.createServer(async (req, res) => {
if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html')); }
if (p === '/testers') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'testers.html')); } // the pre-launch briefing
if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html'));
if (p === '/signin') return sendFile(res, path.join(PUBLIC_DIR, 'signin.html')); // in-game sign-in (InstantAdPay kit)
if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); // the page asks for the key; every /api/admin call checks it
if (p === '/spawn.js') return sendFile(res, path.join(__dirname, 'lib', 'spawn.js'));
if (/^\/(badges\/)?[a-z0-9._-]+\.(css|js|png|jpg|svg|ico|webp|mp4)$/i.test(p) && !p.includes('..')) return sendFile(res, path.join(PUBLIC_DIR, p.slice(1)), p.startsWith('/badges/') ? { 'Cache-Control': 'public, max-age=86400', 'Access-Control-Allow-Origin': '*' } : undefined); // badge art is also shown on InstantAdPay and in link previews
@@ -290,7 +292,7 @@ const server = http.createServer(async (req, res) => {
const g = sso.startGuest(refCookie(req)); return json(res, 200, { ok: true }, { 'Set-Cookie': sso.guestCookie(g.gid) });
}
const who = me || sso.guestFrom(req);
if (!who) return json(res, 401, { error: 'Sign in through InstantAdPay first.', iap: IAP + '/api/my/driprunner', guestOk: !CURTAIN || hasPass(req), signin: signinUrl(req) });
if (!who) return json(res, 401, { error: 'Sign in with your InstantAdPay account first.', iap: '/signin', guestOk: !CURTAIN || hasPass(req), signin: signinUrl(req) });
return memberApi(req, res, u, p, who);
}
res.writeHead(404, Object.assign({ 'Content-Type': 'text/plain' }, SEC)); res.end('Not found');
@@ -301,7 +303,7 @@ const server = http.createServer(async (req, res) => {
});
function refCookie(req) { const m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(req.headers.cookie || ''); const r = m ? decodeURIComponent(m[1]) : ''; return /^[a-z0-9_.-]{1,40}$/.test(r) ? r : null; }
// where a guest signs in: through the sharer's InstantAdPay join link when they came from one (new people land under the sharer), else the plain hand-off
function signinUrl(req) { const r = refCookie(req); return r ? IAP + '/join/' + encodeURIComponent(r) + '?from=driprunner' : IAP + '/api/my/driprunner'; }
function signinUrl(req) { return '/signin'; } // in-game sign-in (2026-10-03); the kit carries the dr.ref sponsor itself
async function memberApi(req, res, u, p, me) {
try {
{