aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nostr.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/nostr.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/nostr.ts')
-rw-r--r--lib/nostr.ts10
1 files changed, 9 insertions, 1 deletions
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 {