aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-25 09:25:18 -0700
committerAdam Soltys <[email protected]>2026-11-25 09:25:18 -0700
commit43b6d2a4e16f1991a02a77f2198bc83bb71deb04 (patch)
tree78f9f0c59ccd83b5e3e797ef2a1bd082e982de47 /lib
parente0ac891b4c3275b5bb228fd53b507d1c61ff88ea (diff)
downloadcoinos-server-43b6d2a4e16f1991a02a77f2198bc83bb71deb04.tar.gz
coinos-server-43b6d2a4e16f1991a02a77f2198bc83bb71deb04.zip
names: ignore registrar records held by blocked keys
Names whose v3 record belongs to a key in names:blocked_holders are treated as unclaimed: lightning address, NIP-05 and legacy forwarding stay with the local account. Fails open if the registrar or db cannot answer. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SEnsbshZrUDtTsxAX
Diffstat (limited to 'lib')
-rw-r--r--lib/names.ts35
-rw-r--r--lib/v3forward.ts2
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/names.ts b/lib/names.ts
index 284c595d..e170b3ca 100644
--- a/lib/names.ts
+++ b/lib/names.ts
@@ -1,3 +1,4 @@
+import { db } from "$lib/db";
import { warn } from "$lib/logging";
import { fail } from "$lib/utils";
@@ -35,3 +36,37 @@ export const assertNameFree = async (username: string, ownPubkey?: string) => {
fail(`Username ${name} taken`);
}
};
+
+// Registrar holders we refuse to honour (valkey set `names:blocked_holders`,
+// full hex pubkeys). A name whose v3 record belongs to one of them is treated
+// as unclaimed: its lightning address, NIP-05 and legacy forwarding all stay
+// with the local account. This is the containment for a name hijack on the
+// registrar side; it needs no deploy there. Fails open: if the registrar or
+// the db can't answer, callers behave as they did before.
+const blockedCache = new Map<string, { at: number; blocked: boolean }>();
+export const holderBlocked = async (username: string): Promise<boolean> => {
+ const name = String(username || "").toLowerCase();
+ if (!name) return false;
+ const hit = blockedCache.get(name);
+ if (hit && Date.now() - hit.at < 60_000) return hit.blocked;
+ try {
+ if (!(await db.sCard("names:blocked_holders"))) return false;
+ const r = await fetch(
+ `${NAMES_URL}/name/${encodeURIComponent(name)}?domain=${DOMAIN}`,
+ { signal: AbortSignal.timeout(3000) },
+ );
+ if (!r.ok) return false;
+ const body: any = await r.json();
+ const pk = body?.taken && typeof body.pubkey === "string" ? body.pubkey : null;
+ const mgr = typeof body?.manager === "string" ? body.manager : null;
+ const blocked =
+ (!!pk && (await db.sIsMember("names:blocked_holders", pk))) ||
+ (!!mgr && (await db.sIsMember("names:blocked_holders", mgr)));
+ blockedCache.set(name, { at: Date.now(), blocked });
+ if (blocked) warn("registrar holder blocked, serving local account for", name);
+ return blocked;
+ } catch (e: any) {
+ warn("holderBlocked check failed for", name, e?.message);
+ return false;
+ }
+};
diff --git a/lib/v3forward.ts b/lib/v3forward.ts
index 34f634ef..525c1be1 100644
--- a/lib/v3forward.ts
+++ b/lib/v3forward.ts
@@ -19,6 +19,7 @@ import { PaymentType } from "$lib/types";
// account's own session named in a migration grant (`granted`). A name that
// merely exists on v3 is never forwarded to.
+import { holderBlocked } from "$lib/names";
const NAMES_URL = process.env.NAMES_URL || "https://names.coinos.io";
const DOMAIN = "coinos.io";
const TYPES = [PaymentType.lightning, PaymentType.bolt12, PaymentType.bitcoin, PaymentType.liquid];
@@ -53,6 +54,7 @@ async function v3Holder(username: string): Promise<{ pk: string | null; granted:
export async function v3Destination(user): Promise<string | null> {
if (!user?.username || !user?.pubkey || user.username.length > 64) return null;
const { pk, granted } = await v3Holder(user.username);
+ if (pk && (await holderBlocked(user.username))) return null;
return pk && (granted || pk === user.pubkey) ? user.username.toLowerCase() : null;
}