Code box survives a board reload: the board hands back the member's started mission, a second Start reuses the live token, and submit accepts the code of any live token of theirs for that mission (ticket IAP-1027, phones that open the site in the board's own window)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
+14
-4
@@ -49,6 +49,14 @@ function issue(memberId, missionId, extra) {
|
||||
return rec;
|
||||
}
|
||||
function token(t) { const rec = store.read('tokens', {})[String(t || '')]; return rec && rec.exp > Date.now() ? rec : null; }
|
||||
// a member's live Code Hunt tokens (no kind), newest first; missionId narrows it to one mission. The board uses the
|
||||
// newest to bring the code box back after a reload, and start reuses it so a code already on screen keeps matching
|
||||
// (2026-11-24: on phones the site opened in the board's own window, the reload lost the box, and a second Start
|
||||
// issued a new token whose code no longer matched the one on screen)
|
||||
function live(memberId, missionId) {
|
||||
const all = store.read('tokens', {}), now = Date.now();
|
||||
return Object.keys(all).map(k => all[k]).filter(r => r && !r.kind && r.exp > now && r.memberId === Number(memberId) && (missionId === undefined || r.missionId === missionId)).sort((x, y) => y.iat - x.iat);
|
||||
}
|
||||
|
||||
// the proof: six characters from HMAC(secret, token); shown by the embed, typed by the hunter
|
||||
function codeFor(rec) { return h('code:' + rec.t + ':' + rec.memberId + ':' + rec.missionId).toString('hex').slice(0, 6).toUpperCase(); }
|
||||
@@ -75,11 +83,13 @@ function check(t, memberId, typed) {
|
||||
const rec = token(t); if (!rec) return { error: 'That mission timed out. Start it again from your board.' };
|
||||
if (rec.memberId !== Number(memberId)) return { error: 'That mission belongs to a different account.' };
|
||||
if (rec.kind) return { error: 'That is an Ad Detective case. Answer its question on your board.' };
|
||||
const want = codeFor(rec);
|
||||
const got = String(typed || '').trim().toUpperCase();
|
||||
if (got.length !== 6) return { error: 'Codes are 6 characters and you typed ' + got.length + '. Look at the site again: the code sits in six boxes, and a tap on it copies all six.' };
|
||||
if (got !== want) return { error: 'That is not the code. It is on the site, and it is yours alone.' };
|
||||
return { ok: true, rec };
|
||||
if (got === codeFor(rec)) return { ok: true, rec };
|
||||
// pressed Start more than once: the code on screen may belong to another live token of theirs for this same mission
|
||||
const other = live(rec.memberId, rec.missionId).find(r => r.t !== rec.t && codeFor(r) === got);
|
||||
if (other) return { ok: true, rec: other };
|
||||
return { error: 'That is not the code. It is on the site, and it is yours alone.' };
|
||||
}
|
||||
|
||||
module.exports = { list, get, save, remove, forMember, issue, token, codeForEmbed, check, ctDay, onVisit: null };
|
||||
module.exports = { list, get, save, remove, forMember, issue, token, live, codeForEmbed, check, ctDay, onVisit: null };
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@
|
||||
<div class="modal" id="shareModal" hidden><div class="modal-card"><button class="modal-x" id="shareClose" type="button" aria-label="Close">×</button><div id="shareBody"></div></div></div>
|
||||
<script src="https://instantadpay.com/assets/game-strip.js?v=20261003a"></script>
|
||||
<script>if (window.IAPGames) IAPGames.strip(document.getElementById('moreGames'), { current: 'polhunter', title: ' ' }).then(function (n) { var m = document.getElementById('moreGames'), h = m.querySelector('.gs-h'); if (h) h.remove(); document.getElementById('moreGamesSec').hidden = !n; });</script>
|
||||
<script src="/app.js?v=23"></script>
|
||||
<script src="/app.js?v=24"></script>
|
||||
<script src="/nas.js?v=20261024" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+3
-2
@@ -257,11 +257,12 @@
|
||||
}
|
||||
}
|
||||
let explorer = 'https://polygonscan.com';
|
||||
async function load() { board = await api('/api/my/board'); render(); }
|
||||
// the server remembers a started mission, so its code box survives a reload (phones often open the site in this same window)
|
||||
async function load() { board = await api('/api/my/board'); if (board && board.open && (!open || open.token !== board.open.token || open.missionId !== board.open.missionId)) open = board.open; render(); }
|
||||
async function start(id) {
|
||||
const r = await api('/api/my/start', { missionId: id });
|
||||
if (r.error) { toast(esc(r.error), 'bad'); if (r.spent || r.dailyDone) await load(); return; }
|
||||
open = { missionId: id, token: r.token, url: r.url, dwell: r.dwell, started: Date.now(), expires: r.expires };
|
||||
open = { missionId: id, token: r.token, url: r.url, dwell: r.dwell, started: r.started || Date.now(), expires: r.expires };
|
||||
window.open(r.url, '_blank', 'noopener');
|
||||
render();
|
||||
}
|
||||
|
||||
@@ -184,6 +184,9 @@ function curtained(req, res, u) {
|
||||
res.writeHead(503, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex, nofollow' }); res.end(req.method === 'HEAD' ? '' : CURTAIN_PAGE); return true;
|
||||
}
|
||||
function admin(req) { const k = req.headers['x-admin-key'] || new URL(req.url, 'http://x').searchParams.get('key'); return !!(ADMIN_KEY && k && k.length === ADMIN_KEY.length && crypto.timingSafeEqual(Buffer.from(k), Buffer.from(ADMIN_KEY))); }
|
||||
// a mission URL may place the token itself with {token} (a Telegram Mini App takes it in ?startapp=, not as our own
|
||||
// query string); otherwise the token rides in the hash: a server never sees it, so no redirect or canonical rewrite can lose it
|
||||
const missionUrl = (m, t) => m.url.includes('{token}') ? m.url.replace('{token}', t) : m.url + '#ph=' + t;
|
||||
const pubMission = m => ({ id: m.id, site: m.site, name: m.name, brief: m.brief, dwell: m.dwell || 30, reward: rewards.settings() });
|
||||
|
||||
// ---- the server ------------------------------------------------------------------------------
|
||||
@@ -303,7 +306,9 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, missions: boardMissions, tour, drips: rewards.mine(me.memberId).slice(0, 20), faucet: { on: faucetOn }, pool: rewards.pool(), daily: rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fbank.bonus, passExtra(me), fullTier(me)), /* the tier, as start/submit pass it (the board showed a Pass holder 3, not 5) */ fridayBank: fbank, gamepass: gp.view(me.memberId, me.email),
|
||||
badges: social.badgesFor(me.memberId), badgeCards: (() => { const got = new Set(social.badgesFor(me.memberId).map(b => b.id)); const who = social.nameOf(me); return social.BADGES.map(b => ({ id: b.id, name: b.name, icon: b.icon, why: b.why, count: b.id === 'sweep' && rot.rounds > 1 ? rot.rounds : undefined, art: '/badges/badge-' + b.id + '.jpg', earned: got.has(b.id), page: got.has(b.id) ? SITE + '/b/' + who + '/' + b.id : null, image: got.has(b.id) ? SITE + '/badge-img/' + who + '/' + b.id + '.jpg' : null })); })(), rank: { week: social.rankOf(me.memberId, 'week'), month: social.rankOf(me.memberId, 'month'), all: social.rankOf(me.memberId, 'all') },
|
||||
share: { link: social.shareLink(SITE, me), joinUrl: 'https://instantadpay.com/join/' + encodeURIComponent(String(me.username || me.memberId)) + '?from=polhunter' },
|
||||
referral: referrals.state(me), box: detective.view(me, fullTier(me)) });
|
||||
referral: referrals.state(me), box: detective.view(me, fullTier(me)),
|
||||
// the mission they started and have not claimed yet: the board brings its code box back after a reload
|
||||
open: (() => { for (const r of missions.live(me.memberId)) { const m = missions.get(r.missionId); if (m && m.active && !done.has(m.id)) return { missionId: m.id, token: r.t, url: missionUrl(m, r.t), dwell: m.dwell || 30, started: r.iat, expires: r.exp }; } return null; })() });
|
||||
}
|
||||
if (p === '/api/my/start' && req.method === 'POST') {
|
||||
const b = await readBody(req); const m = missions.get(String(b.missionId || '')); if (!m || !m.active) return json(res, 404, { error: 'That mission is not open.' });
|
||||
@@ -313,12 +318,9 @@ const server = http.createServer(async (req, res) => {
|
||||
{ const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); }
|
||||
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
|
||||
if (limited('start:' + me.memberId, 20, 3600000)) return json(res, 429, { error: 'Easy. Twenty starts an hour is plenty.' });
|
||||
const t = missions.issue(me.memberId, m.id);
|
||||
// a mission URL may place the token itself with {token} (a Telegram Mini App takes it in
|
||||
// ?startapp=, not as our own query string); otherwise it is appended as ?ph=
|
||||
// the token rides in the hash: a server never sees it, so no redirect or canonical rewrite can lose it
|
||||
const url = m.url.includes('{token}') ? m.url.replace('{token}', t.t) : m.url + '#ph=' + t.t;
|
||||
return json(res, 200, { ok: true, token: t.t, url, dwell: m.dwell || 30, expires: t.exp });
|
||||
// a second Start on the same mission hands back the live token (3+ minutes left), so a code already on screen keeps matching
|
||||
const t = missions.live(me.memberId, m.id).find(r => r.exp - Date.now() > 180000) || missions.issue(me.memberId, m.id);
|
||||
return json(res, 200, { ok: true, token: t.t, url: missionUrl(m, t.t), dwell: m.dwell || 30, started: t.iat, expires: t.exp });
|
||||
}
|
||||
if (p === '/api/my/submit' && req.method === 'POST') {
|
||||
const b = await readBody(req);
|
||||
|
||||
@@ -47,6 +47,8 @@ const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
const st = await call('/api/my/start', { method: 'POST', body: JSON.stringify({ missionId: 'test-1' }) });
|
||||
eq([st.status, /#ph=[a-f0-9]{32}$/.test(st.body.url)], [200, true], 'start issues a token on the mission link');
|
||||
const t = st.body.token;
|
||||
{ const b2 = await call('/api/my/board'); eq([b2.body.open && b2.body.open.token, b2.body.open && b2.body.open.missionId], [t, 'test-1'], 'board hands back the started mission, so the code box survives a reload');
|
||||
const st2 = await call('/api/my/start', { method: 'POST', body: JSON.stringify({ missionId: 'test-1' }) }); eq([st2.status, st2.body.token === t, st2.body.started <= Date.now()], [200, true, true], 'a second Start reuses the live token (the code on screen keeps matching)'); }
|
||||
|
||||
// the embed's locks
|
||||
const wrongOrigin = await fetch(B + '/api/embed/code?t=' + t, { headers: { Origin: 'https://evil.example' } });
|
||||
|
||||
Reference in New Issue
Block a user