Network hub hook (Marty 2026-11-16): sign out everywhere, hub blocks and erases end sessions here; "Sign out everywhere" button
hubevents.js (new, byte-identical in VBB, DLB, ViralAdBlitz, DownlineHydra, 5xYourTeam): POST /api/hub/events, signed by the hub with HUB_SECRET (same hook InstantAdPay and LinkSpin take). member.signedout and member.blocked: the person is looked up by hub id (/v1/resolve, signed as bannerline) and every session of their main wallet or any contract wallet ends. member.erased: matched by the wallet SHA-256s the hub now sends with the event. Only sessions made before the event end (a replay never signs anyone out twice); a failed hub lookup answers 503 so the hub resends. Off with HUB_HOOK=0. Admin status: hubEvents (counts only). My Spots: "Sign out everywhere" next to Sign out (POST /api/auth/logout-everywhere -> networksso.signOutEverywhere, then every session of this wallet here ends). my.js?v=z2. Smoke section 9 (refused signatures, signedout in two browsers, replay, older event, blocked, erased by wallet hash, other events, hub down -> 503 -> resent, Sign out everywhere, admin view): 145/145 with UI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+40
-1
@@ -27,7 +27,7 @@ let pass = 0, fail = 0; const procs = [];
|
||||
const ok = (cond, what, extra) => { if (cond) { pass++; console.log(' ok ' + what); } else { fail++; console.log(' FAIL ' + what + (extra !== undefined ? ' -> ' + JSON.stringify(extra).slice(0, 300) : '')); } };
|
||||
// stand-in network hub (POST /v1/resolve, signed as bannerline) and stand-in InstantAdPay member lookup (the fallback when the
|
||||
// hub is unreachable). HUB.people: {id, username, wallet, sponsorId}; HUB.down makes every hub call fail with 503.
|
||||
const HUB = { people: [], down: false, calls: 0, badSig: 0 }; const HUB_PORT = APP_PORT + 7, HUB_SECRET = 'b'.repeat(40);
|
||||
const HUB = { people: [], down: false, calls: 0, badSig: 0, got: [] }; const HUB_PORT = APP_PORT + 7, HUB_SECRET = 'b'.repeat(40);
|
||||
const IAPNET = new Map(); const IAP_PORT = APP_PORT + 8;
|
||||
const TG = []; const TG_PORT = APP_PORT + 9; // stand-in Telegram Bot API (trust pack 2026-11-14): never the real group
|
||||
const hubView = p => p ? { id: p.id, username: p.username, wallet: p.wallet, sponsor: (x => x ? { id: x.id, username: x.username } : null)(HUB.people.find(y => y.id === p.sponsorId)), blocked: false, locked: false } : null;
|
||||
@@ -45,6 +45,7 @@ function startStandIns() {
|
||||
if (HUB.down) { r.statusCode = 503; return r.end('{"error":"superseded"}'); }
|
||||
const want = crypto.createHmac('sha256', HUB_SECRET).update(q.headers['x-hub-ts'] + '\n' + b).digest('hex');
|
||||
if (q.headers['x-hub-sig'] !== want || q.headers['x-hub-site'] !== 'bannerline') { HUB.badSig++; r.statusCode = 401; return r.end('{"error":"unauthorized"}'); }
|
||||
if (q.url === '/v1/sso/signout') { HUB.got.push({ route: q.url, body: JSON.parse(b || '{}') }); return r.end('{"ok":true,"ended":1}'); } // Sign out everywhere (2026-11-16)
|
||||
if (q.url !== '/v1/resolve') { r.statusCode = 404; return r.end('{"error":"not_found"}'); }
|
||||
const j = JSON.parse(b || '{}'); const ref = String(j.ref || '').toLowerCase();
|
||||
const p = j.id ? HUB.people.find(x => x.id === j.id) : j.wallet ? HUB.people.find(x => x.wallet === String(j.wallet).toLowerCase()) : ref ? HUB.people.find(x => x.username === ref || x.wallet === ref) : null;
|
||||
@@ -357,6 +358,44 @@ async function main() {
|
||||
const ours = errors.filter(e => !/example\.(com|net|org)/.test(e)); // gate frames load example.* sites; their own 404s (favicon) are not ours
|
||||
ok(ours.length === 0, 'no console errors on our pages', ours);
|
||||
}
|
||||
console.log('9. network hub events (sign out everywhere, block, erase end sessions here)');
|
||||
{ const crypto = require('node:crypto'); const admin = (p, body) => client().json(p, body, { 'x-admin-token': ADMIN }); let hseq = 900000; let hn = 700;
|
||||
const signAs = async (w, name) => { const c = client('Mozilla/5.0 hook ' + (hn++)); const a = w.address.toLowerCase(); const xf = { 'X-Forwarded-For': '198.51.100.' + (hn % 250) };
|
||||
if (name) { c.hubId = hid(hn); HUB.people.push({ id: c.hubId, username: name, wallet: a, sponsorId: null }); }
|
||||
const ch = await c.json('/api/auth/challenge', { address: w.address }, xf);
|
||||
const v = await c.json('/api/auth/verify', { address: w.address, signature: await w.signMessage(ch.message) }, xf);
|
||||
c.address = a; c.wallet = w; c.ok = v.ok === true && !!c.jar['bl.sid']; return c; };
|
||||
const walletMember = o => signAs((o && o.wallet) || ethers.Wallet.createRandom(), o && o.hub && o.hub.username); const signedIn = async c => (await c.json('/api/me')).signedIn === true;
|
||||
const hook = async (events, o = {}) => { const raw = JSON.stringify({ events }); const ts = String(o.ts || Date.now());
|
||||
const sig = o.sig || crypto.createHmac('sha256', o.secret || HUB_SECRET).update(ts + '\n' + raw).digest('hex');
|
||||
const r = await fetch(BASE + '/api/hub/events', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Hub-Ts': ts, 'X-Hub-Sig': sig }, body: raw }); return r.status; };
|
||||
const ev = (type, personId, data, at) => ({ seq: ++hseq, at: at || Date.now(), type, personId, data: data || {} });
|
||||
const H1 = await walletMember({ hub: { username: 'hookone' } }); const H1b = await walletMember({ wallet: H1.wallet }); const H2 = await walletMember({ hub: { username: 'hooktwo' } });
|
||||
const H3 = await walletMember({ hub: { username: 'hookthree' } }); const H4 = await walletMember({ hub: { username: 'hookfour' } });
|
||||
ok(H1.ok && H1b.ok && H2.ok && H3.ok && H4.ok && await signedIn(H1) && await signedIn(H1b), 'setup: hub members signed in here (one of them in two browsers)');
|
||||
ok(await hook([ev('member.signedout', H1.hubId)], { secret: 'x'.repeat(40) }) === 401 && await hook([ev('member.signedout', H1.hubId)], { ts: Date.now() - 600000 }) === 401, 'a hook signed with another key, or 10 minutes old, is refused (401)');
|
||||
ok(await signedIn(H1), 'a refused hook ends nothing');
|
||||
const so = ev('member.signedout', H1.hubId);
|
||||
ok(await hook([so]) === 200 && !(await signedIn(H1)) && !(await signedIn(H1b)) && await signedIn(H2), 'member.signedout: every session of that wallet ends (both browsers), nobody else\'s');
|
||||
const H1c = await walletMember({ wallet: H1.wallet });
|
||||
ok(await hook([so]) === 200 && await signedIn(H1c), 'the same event sent twice: applied once, a fresh sign-in stays');
|
||||
ok(await hook([ev('member.signedout', H1.hubId, {}, Date.now() - 60000)]) === 200 && await signedIn(H1c), 'an event older than a session never ends it (only sessions made before the event)');
|
||||
ok(await hook([ev('member.blocked', H2.hubId)]) === 200 && !(await signedIn(H2)) && await signedIn(H3), 'member.blocked: that member is signed out here');
|
||||
const wh = crypto.createHash('sha256').update(H3.address).digest('hex'); HUB.people = HUB.people.filter(x => x.id !== H3.hubId);
|
||||
ok(await hook([ev('member.erased', H3.hubId, { emailHash: 'a'.repeat(64), walletHashes: [wh] })]) === 200 && !(await signedIn(H3)) && await signedIn(H4), 'member.erased: found by the wallet hash in the event (the hub no longer knows them), signed out');
|
||||
ok(await hook([ev('member.joined', H4.hubId), ev('member.signedout', 'h_' + 'f'.repeat(16))]) === 200 && await signedIn(H4), 'other events and unknown people are ignored');
|
||||
HUB.down = true; const late = ev('member.signedout', H4.hubId);
|
||||
ok(await hook([late]) === 503 && await signedIn(H4), 'the hub lookup failing answers 503 (the hub sends it again), nothing ended');
|
||||
HUB.down = false; ok(await hook([late]) === 200 && !(await signedIn(H4)), 'resent once the hub answers: signed out');
|
||||
const E1 = await walletMember({ hub: { username: 'hookfive' } }); const E2 = await walletMember({ wallet: E1.wallet }); const g0 = HUB.got.length;
|
||||
const eo = await E1.json('/api/auth/logout-everywhere', {});
|
||||
const call = HUB.got.slice(g0).find(x => x.route === '/v1/sso/signout');
|
||||
ok(eo.ok && eo.everywhere === true && !(await signedIn(E1)) && !(await signedIn(E2)) && call && call.body.wallet === E1.address, 'Sign out everywhere: the hub is told (signed, by wallet) and every session of that wallet here ends', { eo, call });
|
||||
ok(/id="outAllBtn"[^>]*>Sign out everywhere</.test(await (await client().req('/my')).text()), '/my has a Sign out everywhere button next to Sign out');
|
||||
const st2 = await admin('/api/admin/status');
|
||||
ok(st2.hubEvents && st2.hubEvents.on && st2.hubEvents.stats.ended >= 5 && st2.hubEvents.stats.refused >= 2 && !JSON.stringify(st2.hubEvents).includes(HUB_SECRET), 'admin status shows the hub events (counts only, no secret)', st2.hubEvents);
|
||||
}
|
||||
|
||||
console.log('\n' + pass + ' passed, ' + fail + ' failed. Output in ' + OUT);
|
||||
cleanup(); process.exit(fail ? 1 : 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user