aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-29 08:37:39 -0700
committerAdam Soltys <[email protected]>2026-09-29 08:37:47 -0700
commit4900ecb19ab9c6d279c8771b834fcb29e526a1e0 (patch)
treea8e1067d3cadbd8eacc9d111da2507d7babadfbd /lib/payments.ts
parente96ad1cea4192a608a7f15896e4b690b57bf8fc9 (diff)
downloadcoinos-server-4900ecb19ab9c6d279c8771b834fcb29e526a1e0.tar.gz
coinos-server-4900ecb19ab9c6d279c8771b834fcb29e526a1e0.zip
logging: throttle log lines that clients can trigger at will
Evicted-JWT replays, blocked sends from frozen or limited accounts and failed payment retries each logged one line per request, so a looping client could flood the log, and an evicted token replayed across a proxy pool made atk-autoban.sh block every IP it saw. Add quiet()/suppressed() in lib/logging.ts: the first occurrence per key logs as before, repeats within the window are counted and reported on the next line that gets through. The evicted-auth summary line is worded so the auto-banner ignores it. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 2c18f399..f2a05d50 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -21,7 +21,7 @@ const isWithdrawLocked = (type: string): string | null => {
import { generate } from "$lib/invoices";
import ln from "$lib/ln";
import { quoteRoutingFee, xpayLayers } from "$lib/lnquote";
-import { err, l, shortError, warn } from "$lib/logging";
+import { err, l, quiet, shortError, suppressed, warn } from "$lib/logging";
import { handleZap } from "$lib/nostr";
import { notify, nwcNotify } from "$lib/notifications";
import { squarePayment } from "$lib/square";
@@ -143,13 +143,19 @@ export const debit = async ({
if (type !== PaymentType.internal) {
const lockedKind = isWithdrawLocked(type);
if (lockedKind) {
- warn("Blocking", user.username, amount, hash, user.id, type, "withdraw-lock", lockedKind);
+ const n = quiet(`block:${user.id}:lock`, 5 * 60 * 1000);
+ if (n !== null)
+ warn("Blocking", user.username, amount, hash, user.id, type, "withdraw-lock", lockedKind, suppressed(n));
fail("External withdrawals temporarily disabled");
}
}
if (frozen || (amount > userLimit && !whitelisted)) {
- warn("Blocking", user.username, amount, hash, user.id, type, frozen, userLimit);
+ // Per-account throttle: a frozen throwaway retrying sends every few
+ // seconds is expected noise, one line per 5 min keeps the tripwire.
+ const n = quiet(`block:${user.id}:frozen`, 5 * 60 * 1000);
+ if (n !== null)
+ warn("Blocking", user.username, amount, hash, user.id, type, frozen, userLimit, suppressed(n));
fail("Problem sending payment");
}
@@ -166,7 +172,9 @@ export const debit = async ({
await withLimitLock(type, async () => {
const serverLimit = Number.parseInt((await g(`${type}:limit`)) ?? "0", 10) || 0;
if (amount > serverLimit) {
- warn("Blocking", user.username, amount, hash, user.id, type, "serverLimit", serverLimit);
+ const n = quiet(`block:${user.id}:server`, 5 * 60 * 1000);
+ if (n !== null)
+ warn("Blocking", user.username, amount, hash, user.id, type, "serverLimit", serverLimit, suppressed(n));
fail("Problem sending payment");
}
await db.decrBy(`${type}:limit`, amount);