From b8b409910f71976959135b336b409c4923cf4c87 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 13 Nov 2026 16:11:02 -0700 Subject: lnurl: fetch user-supplied URLs through the SSRF guard, relay only protocol fields Lightning address sends (pay() and POST /send/) 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 --- lib/nostr.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/nostr.ts') diff --git a/lib/nostr.ts b/lib/nostr.ts index ed1b2f42..63199bf8 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -1,4 +1,5 @@ import config from "$config"; +import { safeRelayUrl } from "$lib/safe-fetch"; import { db, g, s } from "$lib/db"; import { l, warn } from "$lib/logging"; import { scan } from "$lib/strfry"; @@ -125,7 +126,14 @@ export async function handleZap(invoice, sender = undefined) { l("sending receipt"); - const relays = relays_tag.slice(1).filter((r) => r?.startsWith("ws")); + // Relay URLs come from the zap request, i.e. from whoever asked for the + // invoice; don't let them point our server at internal hosts. + const requested = relays_tag + .slice(1) + .filter((r) => typeof r === "string" && r.startsWith("ws")) + .slice(0, 10); + const relays = []; + for (const r of requested) if (await safeRelayUrl(r)) relays.push(r); relays.push(config.nostr); relays.map(async (url) => { try { -- cgit v1.2.3