diff options
Diffstat (limited to 'names/server.js')
| -rw-r--r-- | names/server.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/names/server.js b/names/server.js index 600b12a..553377e 100644 --- a/names/server.js +++ b/names/server.js @@ -2136,6 +2136,34 @@ Bun.serve({ return json({ error: 'action is deliver or writeoff' }, 400); } + // Remove everything a key holds here, as "Delete my account" does for its + // own signer, for a key an operator names: the 528 @coinos.io names an + // attacker took through the old site's /migrate hole on 2026-11-24 (the + // grant trusted the form's username), all held by one key. The names go + // back to unclaimed, their grants and DNS records with them. Refused + // while sats are owed to the key's names (blockers), as for a user. + // { pubkey, dryRun } → the records removed, for the operator's file. + if (url.pathname === '/admin/forget-key' && req.method === 'POST') { + if (!CFG.adminToken || req.headers.get('x-admin-token') !== CFG.adminToken) return json({ error: 'unauthorized' }, 401); + let b; try { b = await req.json(); } catch { return json({ error: 'bad body' }, 400); } + const pubkey = String(b.pubkey || '').toLowerCase(); + if (!/^[0-9a-f]{64}$/.test(pubkey)) return json({ error: 'pubkey is 64 hex' }, 400); + const acct = accountOf(state, pubkey); + const hold = accountBlockers(state, acct); + const grants = Object.entries(state.migrations || {}).filter(([k, g]) => acct.names.includes(k) || g?.pubkey === pubkey || g?.manager === pubkey); + const snapshot = { names: Object.fromEntries(acct.names.map((k) => [k, state.names[k]])), migrations: Object.fromEntries(grants) }; + if (b.dryRun || hold.any) { + return json({ dryRun: !!b.dryRun, names: acct.names.length, grants: grants.length, keys: [...acct.keys], blockers: hold, snapshot }, hold.any && !b.dryRun ? 409 : 200); + } + const out = forgetAccount(state, acct); + persist(); + let dnsFailed = 0; + for (const d of out.dns) await cfDelete(d.domain, d.recordId, d.name).catch((e) => { dnsFailed++; log(`forget-key: dns record for ${d.name} stayed: ${e.message}`); }); + if (ln) for (const id of out.offers) await ln.call('disableoffer', { offer_id: id }).catch(() => {}); + log(`forget-key ${pubkey.slice(0, 12)}…: ${acct.names.length} names released ${JSON.stringify(out.removed)}${dnsFailed ? `, ${dnsFailed} dns records stayed` : ''}${b.note ? ` — ${String(b.note).slice(0, 200)}` : ''}`); + return json({ ok: true, removed: out.removed, dnsRecords: out.dns.length, dnsFailed, snapshot }); + } + if (url.pathname === '/admin/topup' && req.method === 'POST') { if (!CFG.adminToken || req.headers.get('x-admin-token') !== CFG.adminToken) { return json({ error: 'unauthorized' }, 401); |
