diff options
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; |
