diff options
| author | Adam Soltys <[email protected]> | 2026-11-13 16:11:02 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-13 16:11:02 -0700 |
| commit | b8b409910f71976959135b336b409c4923cf4c87 (patch) | |
| tree | 21115643c3bed3c967a9bdc2fe1c75fa9cdfa07d /routes | |
| parent | 589519f2556b2d434ed23f26c705df73b6149d7c (diff) | |
| download | coinos-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 'routes')
| -rw-r--r-- | routes/lnurl.ts | 10 | ||||
| -rw-r--r-- | routes/payments.ts | 11 |
2 files changed, 14 insertions, 7 deletions
diff --git a/routes/lnurl.ts b/routes/lnurl.ts index 7f04db5d..e28bb510 100644 --- a/routes/lnurl.ts +++ b/routes/lnurl.ts @@ -5,6 +5,7 @@ import { serverPubkey2 } from "$lib/nostr"; import { SATS, bail, fail, getInvoice, getUser } from "$lib/utils"; import { bech32 } from "bech32"; import { safeGot } from "$lib/safe-fetch"; +import { lnurlPayload } from "$lib/lnurl-payload"; import { verifyEvent } from "nostr-tools"; import { v4 } from "uuid"; @@ -99,7 +100,7 @@ export default { bech32.fromWords(bech32.decode(text, 20000).words), ).toString(); - const r = await safeGot(url); + const r = lnurlPayload(await safeGot(url)); res.send(r); } catch (e) { bail(res, e.message); @@ -240,11 +241,12 @@ export default { const { url } = req.query; if (!url) return bail(res, "url required"); try { - const r = await safeGot(url); + const r = lnurlPayload(await safeGot(url)); res.send(r); } catch (e) { - warn("lnurl proxy failed", url, e.message); - bail(res, e.message); + const n = quiet("lnurl-proxy-failure", 5 * 60 * 1000); + if (n !== null) warn("lnurl proxy failed", url, e.message, suppressed(n)); + bail(res, "Unable to resolve a valid LNURL response"); } }, diff --git a/routes/payments.ts b/routes/payments.ts index cfb34af7..9cc31434 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -32,6 +32,7 @@ import { } from "$lib/utils"; import rpc from "@coinos/rpc"; import got from "got"; +import { safeGot } from "$lib/safe-fetch"; import { v4 } from "uuid"; // Funds are closed. The mechanism let a caller pull unbacked balance out of a @@ -789,15 +790,19 @@ export default { await requirePin({ body, user }); const [username, domain] = lnaddress.split("@"); - const { minSendable, maxSendable, callback, metadata } = (await got( + // Coinos names are any letters/digits, so don't enforce LUD-16's + // charset; just refuse what could steer the URL we fetch. + if (!username || /[\/\\?#%@\s]|\.\./u.test(username) || !/^[a-z0-9.-]+(:\d+)?$/i.test(domain || "")) + fail("Invalid lightning address"); + const { minSendable, maxSendable, callback, metadata } = (await safeGot( `https://${domain}/.well-known/lnurlp/${username}`, - ).json()) as any; + )) as any; const memo = metadata["text/plain"] || ""; if (amount * 1000 < minSendable || amount * 1000 > maxSendable) fail("amount out of range"); - const r: any = await got(`${callback}?amount=${amount * 1000}`).json(); + const r: any = await safeGot(`${callback}?amount=${amount * 1000}`); if (r.reason) fail(r.reason); const { pr } = r; |
