aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webhooks.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-25 09:25:18 -0700
committerAdam Soltys <[email protected]>2026-11-25 09:25:18 -0700
commitcdd086afc3044d9c8beefb0cc1abc307d1e4557e (patch)
treeb0397b911bf34d4af2b0b68ff5bcd05a60f93cfe /lib/webhooks.ts
parent0f3cb69da812dc81b2a5d939b1eebf1146ee2369 (diff)
downloadcoinos-server-cdd086afc3044d9c8beefb0cc1abc307d1e4557e.tar.gz
coinos-server-cdd086afc3044d9c8beefb0cc1abc307d1e4557e.zip
webhooks, zaps: send user-supplied URLs through the SSRF guard
Invoice webhooks must be plain http(s) strings and are posted with safePost (checked, pinned address, no redirects). Zap requests resolve the recipient lud16/lud06 and callback through safeGot instead of fetching them as-is. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SEnsbshZrUDtTsxAX
Diffstat (limited to 'lib/webhooks.ts')
-rw-r--r--lib/webhooks.ts28
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/webhooks.ts b/lib/webhooks.ts
index d724ccdf..ef9b43b1 100644
--- a/lib/webhooks.ts
+++ b/lib/webhooks.ts
@@ -1,5 +1,5 @@
import config from "$config";
-import got from "got";
+import { safePost } from "$lib/safe-fetch";
import { l, err } from "$lib/logging";
export const callWebhook = async (invoice, payment) => {
@@ -8,7 +8,10 @@ export const callWebhook = async (invoice, payment) => {
const { address, received, text, webhook, secret } = invoice;
- if (webhook) {
+ // The webhook URL is whatever the invoice's creator typed, so it goes
+ // through the SSRF guard and must be a plain string: an object here would
+ // be read as a full set of request options (headers, credentials, ...).
+ if (typeof webhook === "string" && webhook) {
const { amount, confirmed, hash, memo } = payment;
l("calling webhook", webhook, amount, hash, address, text);
@@ -19,19 +22,16 @@ export const callWebhook = async (invoice, payment) => {
// "payment received" callbacks to that merchant. A merchant on a
// self-signed cert now fails here instead, which the catch below logs;
// the payment itself is unaffected.
- const res = await got.post(webhook, {
- json: {
- address,
- amount,
- confirmed,
- hash,
- memo,
- received,
- text,
- secret,
- },
+ return await safePost(webhook, {
+ address,
+ amount,
+ confirmed,
+ hash,
+ memo,
+ received,
+ text,
+ secret,
});
- return res;
}
} catch (e) {
err("problem calling webhook", e.message);