diff options
| author | Adam Soltys <[email protected]> | 2026-12-02 10:41:29 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-12-02 10:41:29 -0700 |
| commit | 8076d1323566fe90a43f857384e5e46c257c692a (patch) | |
| tree | 16282510dc94a9f1e238e60e8be9fc9ede2f9663 /names/migrate-check.js | |
| parent | c851718782ec8c26d8fd32372ec50a9f7e9efd23 (diff) | |
| download | coinosv3-server-8076d1323566fe90a43f857384e5e46c257c692a.tar.gz coinosv3-server-8076d1323566fe90a43f857384e5e46c257c692a.zip | |
names: /migrate-grant needs a fresh v3 hand-off stamp from coinos.io.
"Fix the gap" (Adam, 2026-12-02). The reverted check keyed on `migrated`, which coinos.io has set on every new account since 2023, so it stopped nothing (c851718). coinos-server 796999cb now records `v3migrated`, a timestamp set only when an account's own session posts the hand-off, and shows it on /api/users/<name>. The grant follows within seconds, so it goes ahead only when that stamp is under 5 minutes old. That is the same proof as carrying the old account's session to /api/me, without sending coinos.io JWTs (no expiry, no revocation) to this host. A name handed over earlier can't be re-granted to a different key unless its owner hands it over again. Refused: stale, future-dated or missing stamp (409); no such account (404); coinos.io unreachable (502, the caller retries). migrate-check.test.js runs in `bun run test` (18 pass).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6SSfVopM1ZzXKZmLYU
Diffstat (limited to 'names/migrate-check.js')
| -rw-r--r-- | names/migrate-check.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/names/migrate-check.js b/names/migrate-check.js new file mode 100644 index 0000000..d4995f4 --- /dev/null +++ b/names/migrate-check.js @@ -0,0 +1,28 @@ +// /migrate-grant's second check. The bearer token proves the caller is +// coinos.io, not that the name's own account asked. So the old account must +// have just handed itself over: coinos.io stamps `v3migrated` (a timestamp) +// only when the account's own session posts the hand-off, and the grant +// follows within seconds. A bug upstream then can't give someone else's name +// to a stranger, and a name handed over long ago can't be quietly re-granted. +// +// Not `migrated`: coinos.io has set that on every new account since 2023, so +// nearly every name passes it. +// Returns null when the grant may go ahead, else [status, error]. +export const FRESH_MS = 5 * 60_000; + +export async function migrateGrantRefusal(name, fetchFn = fetch, now = Date.now()) { + let u; + try { + const r = await fetchFn(`https://coinos.io/api/users/${encodeURIComponent(name)}`, { signal: AbortSignal.timeout(8000) }); + if (r.status === 404) return [404, 'no such coinos.io account']; + if (r.status !== 200) throw new Error(`coinos.io said ${r.status}`); + u = await r.json(); + } catch { + return [502, "couldn't check the coinos.io account, try again"]; + } + if (!u || String(u.username || '').toLowerCase() !== String(name).toLowerCase()) return [404, 'no such coinos.io account']; + const at = Number(u.v3migrated); + if (!Number.isFinite(at) || at > now + 60_000 || now - at > FRESH_MS) + return [409, 'that coinos.io account has not just migrated']; + return null; +} |
