aboutsummaryrefslogtreecommitdiffstats
path: root/routes/users.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-12-02 13:45:51 -0700
committerAdam Soltys <[email protected]>2026-12-02 13:45:51 -0700
commit74939c517b51a08e88106e10b93aafc9988cdb98 (patch)
tree35b2f26908d46ef057748537685d5a48e5e7cf9d /routes/users.ts
parent5b7881f3195d9c1479cfffc207014540a9db4d9a (diff)
downloadcoinos-server-74939c517b51a08e88106e10b93aafc9988cdb98.tar.gz
coinos-server-74939c517b51a08e88106e10b93aafc9988cdb98.zip
users: unlink an anon account's pubkey only after the signature checks out
Updating your pubkey to one held by an anonymous account deleted that account's user:<pubkey> pointer before the signed challenge was verified, so a request with a bad signature still detached the key from its account. Do the unlink after verification succeeds. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SSfVopM1ZzXKZmLYU
Diffstat (limited to 'routes/users.ts')
-rw-r--r--routes/users.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/routes/users.ts b/routes/users.ts
index cfa41b8b..51eb14be 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -412,10 +412,10 @@ export default {
const existingUsername = exists?.username
?.toLowerCase()
.replace(/\s/g, "");
+ const takeAnon = exists && un !== existingUsername && exists.anon;
if (exists && un !== existingUsername) {
warn("key in use", pubkey, username, existingUsername);
- if (exists.anon) await db.del(`user:${pubkey}`);
- else fail("Key in use by another account");
+ if (!exists.anon) fail("Key in use by another account");
}
const event = JSON.parse(body.event);
@@ -433,6 +433,9 @@ export default {
pubkey = pubkey.replace(/\s*/g, "");
if (pubkey.length !== 64) fail(`Invalid pubkey ${pubkey}`);
+ // Only unlink an anon account's key once the caller has proven they
+ // hold it (signed challenge above).
+ if (takeAnon) await db.del(`user:${pubkey}`);
await db.del(`user:${user.pubkey}`);
user.pubkey = pubkey;
user.nsec = undefined;