diff options
| -rw-r--r-- | lib/payments.ts | 32 |
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( |
