aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/payments.ts9
-rw-r--r--routes/lnurl.ts5
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 2fb891a2..960ff705 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -354,7 +354,14 @@ export const credit = async ({
tip = tip !== undefined ? Number.parseInt(tip) || 0 : Number.parseInt(inv.tip) || 0;
if (!memo) ({ memo } = inv);
- if (memo && memo.length > 5000) fail("memo too long");
+ // Truncate rather than throw: credit() runs AFTER the payment has settled (an
+ // incoming lightning/bolt12 deposit already advanced pay_index; an internal
+ // send already debited the sender). Throwing here left the sats in the house
+ // wallet with no retry path — the payer saw a completed payment and the
+ // recipient was never credited. An oversized memo (attacker-controllable via
+ // the lnurl comment or a bolt12 payer_note) must never destroy a settled
+ // payment; a clipped note is harmless.
+ if (memo && memo.length > 5000) memo = memo.slice(0, 5000);
if (amount < 0 || tip < 0) fail("Invalid amount");
// For a NON-internal receipt the tip is only a cosmetic split of the real
// settled `amount` — there is no paired coinos debit carrying it — so it can
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index 1acc4d76..1b3f84c1 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -188,7 +188,10 @@ export default {
});
if (comment) {
- invoice.memo = comment;
+ // Enforce the commentAllowed:512 we advertise in the lnurlp response.
+ // This overwrite happens after generate()'s own memo validation, so an
+ // uncapped comment would otherwise reach credit() at settlement time.
+ invoice.memo = String(comment).slice(0, 512);
await s(`invoice:${invoice.id}`, invoice);
}