diff options
Diffstat (limited to 'lib/payments.ts')
| -rw-r--r-- | lib/payments.ts | 7 |
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; |
