aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-13 16:11:02 -0700
committerAdam Soltys <[email protected]>2026-11-13 16:11:02 -0700
commit00799bb5ed16d3f2514ba68938e479110a1412a9 (patch)
treeca6d2c72a50d55cf40ffa9159d29c73d0fdfbca4 /lib/payments.ts
parent74b7dece26e21cb67325b9b0d4880fb91e059a20 (diff)
downloadcoinos-server-00799bb5ed16d3f2514ba68938e479110a1412a9.tar.gz
coinos-server-00799bb5ed16d3f2514ba68938e479110a1412a9.zip
sendOnchain: grow the blocked-address list from mule accounts only
An account caught sending to a blocked address is frozen and added to a `mules` set, and a mule's withdrawal destinations are blocked too, so a drain operator's fresh accounts are stopped on their first sweep. A plain blacklist freeze doesn't feed the list: frozen accounts are often takeover victims, and blocking their owner's own address locks the owner out after the account is recovered. Wallet-owned outputs (change) are never matched. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 43070843..a745b7b3 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -740,10 +740,40 @@ export const sendOnchain = async (params) => {
// fund fresh throwaway accounts and sweep each one on-chain to the same
// address, so freezing accounts is a treadmill while the destination is
// constant.
+ //
+ // The list feeds itself through the `mules` set: an account caught
+ // sending to a marked address is frozen and recorded as a mule, and a
+ // mule's withdrawal attempts mark their destinations (mules are funded
+ // fresh and sweep to the same exit, so this catches each one on its first
+ // withdrawal instead of hours later). A plain `blacklist` freeze does NOT
+ // feed the list: those are often takeover victims, and their real owner's
+ // own withdrawal address must not get blocked. Add a
+ // uid to `mules` by hand to mark a known drain account.
+ const uname = user?.username?.toLowerCase().trim();
+ const exempt = !!uname && (await db.sIsMember("whitelist", uname));
+ const dests: string[] = [];
for (const {
scriptPubKey: { address },
} of tx.vout) {
- if (address && (await db.sIsMember("blocked_addresses", address))) {
+ if (!address || (await node.getAddressInfo(address)).ismine) continue;
+ dests.push(address);
+ }
+ const markDests = async (why: string) => {
+ for (const address of dests)
+ if (await db.sAdd("blocked_addresses", address)) {
+ await db.hSet("blocked_addresses:source", address, JSON.stringify({ uid: user.id, username: user.username, at: Date.now() }));
+ err(`SECURITY: ${why} ${user.username} ${user.id} sent to ${address}, address blocked`);
+ }
+ };
+ if (!exempt && user?.id && (await db.sIsMember("mules", user.id)))
+ await markDests("mule");
+ for (const address of dests) {
+ if (await db.sIsMember("blocked_addresses", address)) {
+ if (!exempt && user?.id) {
+ if (await db.sAdd("blacklist", user.id))
+ err(`SECURITY: froze ${user.username} ${user.id} for sending to blocked address ${address}`);
+ if (await db.sAdd("mules", user.id)) await markDests("mule");
+ }
const n = quiet(`blockedaddr:${user.id}`, 5 * 60 * 1000);
if (n !== null)
err(