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
commitb8b409910f71976959135b336b409c4923cf4c87 (patch)
tree21115643c3bed3c967a9bdc2fe1c75fa9cdfa07d /lib/payments.ts
parent589519f2556b2d434ed23f26c705df73b6149d7c (diff)
downloadcoinos-server-b8b409910f71976959135b336b409c4923cf4c87.tar.gz
coinos-server-b8b409910f71976959135b336b409c4923cf4c87.zip
lnurl: fetch user-supplied URLs through the SSRF guard, relay only protocol fields
Lightning address sends (pay() and POST /send/<lnaddr>) now validate the name and domain and fetch through safeGot instead of plain got. Zap receipt relays from the zap request must resolve to public hosts. The LNURL decode and proxy routes return only LNURL protocol fields instead of whatever JSON the upstream sent, and the proxy logs failures rate-limited with a generic error to the client. Also blocks the 172.42.0.0/16 docker range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 407e5eac..43070843 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -1,4 +1,5 @@
import config from "$config";
+import { safeGot } from "$lib/safe-fetch";
import { existsSync } from "fs";
import api from "$lib/api";
import { requireAccount } from "$lib/auth";
@@ -603,6 +604,8 @@ const pay = async ({ aid = undefined, amount, to, user }) => {
let pr;
if (to.includes("@") && to.includes(".")) {
const [name, domain] = to.split("@");
+ if (!name || /[\/\\?#%@\s]|\.\./u.test(name) || !/^[a-z0-9.-]+(:\d+)?$/i.test(domain || ""))
+ fail("Invalid lightning address");
if (URL.includes(domain)) to = name;
lnurl = `https://${domain}/.well-known/lnurlp/${name}`;
} else if (to.startsWith("lnurl")) {
@@ -631,8 +634,8 @@ const pay = async ({ aid = undefined, amount, to, user }) => {
const fee = Math.max(5, Math.round(amount * 0.02));
if (lnurl) {
amount -= fee;
- const { callback } = (await got(lnurl).json()) as any;
- ({ pr } = (await got(`${callback}?amount=${amount * 1000}`).json()) as any);
+ const { callback } = (await safeGot(lnurl)) as any;
+ ({ pr } = (await safeGot(`${callback}?amount=${amount * 1000}`)) as any);
} else if (to.startsWith("ln")) {
amount -= fee;
pr = to;