From fd1617ea66e01557e71debc7e45ca08cfe01bf70 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 30 Jul 2026 10:28:23 -0700 Subject: mint/lightning: refuse caller-supplied invoices, tiered fees, log hygiene - invoices: reject caller-supplied bolt11/bolt12; the server always mints its own. Closes the invoice-registration path behind the shared-node credit and payment-hijack vectors. - lightning: skip mint-owned invoices (lbl* label) in the paid-invoice listener. - payments: lightning free-tier fee credit, withheld for flagged high-throughput (ln:nofree) accounts which pay an elevated rate; the failed-send reversal restores credit at the same rate. freezeCheck made crash-resilient. Lightning and bolt12 sends stay pending until the preimage settles. - payments (route): validate payment-request / invoice input types. - logging: collapse repeated xpay failure lines into one. Co-Authored-By: Claude Opus 4.8 --- lib/invoices.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/invoices.ts') diff --git a/lib/invoices.ts b/lib/invoices.ts index d11073c2..9661bbc7 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -90,14 +90,14 @@ export const generate = async ({ invoice, user }) => { let paymentHash; if (type === PaymentType.lightning) { + // SECURITY: never accept a caller-supplied bolt11. It let anyone register any + // node-payable invoice (incl. a nutshell mint quote) as their own coinos + // deposit — which both double-credited (coinos balance + mint ecash) and let + // an attacker hijack another user's incoming payment (there was no ownership + // guard, so it overwrote invoice:). Always mint the invoice here. + if (bolt11) fail("Cannot provide your own Lightning invoice"); let r; - if (bolt11) { - const { id: nodeid } = await ln.getinfo(); - r = await ln.decode(bolt11); - if (r.payee !== nodeid) fail("invalid invoice"); - amount = Math.round(r.amount_msat / 1000); - r.bolt11 = bolt11; - } else { + { expiry ||= 60 * 60 * 24 * 30; const args = { @@ -174,14 +174,11 @@ export const generate = async ({ invoice, user }) => { text = r.bolt11; paymentHash = r.payment_hash; } else if (type === PaymentType.bolt12) { + // SECURITY: same as bolt11 — never accept a caller-supplied bolt12. Always + // mint the offer server-side. + if (bolt12) fail("Cannot provide your own bolt12 invoice"); let r; - if (bolt12) { - const { id: nodeid } = await ln.getinfo(); - r = await ln.decode(bolt12); - if (r.invoice_node_id !== nodeid) fail("invalid invoice"); - amount = Math.round(r.invoice_amount_msat / 1000); - r.bolt12 = bolt12; - } else { + { r = await ln.offer({ amount: amount ? `${amount + tip}sat` : "any", label: `${id} ${user.username} ${new Date()}`, -- cgit v1.2.3