import config from "$config"; import { safePost } from "$lib/safe-fetch"; import { l, err } from "$lib/logging"; export const callWebhook = async (invoice, payment) => { try { if (!invoice || !payment) return; const { address, received, text, webhook, secret } = invoice; // 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); // TLS verification stays ON. This body carries `secret` — the shared // value the merchant uses to authenticate the notification — so with // rejectUnauthorized:false any party able to intercept the connection // could present its own certificate, harvest the secret, and then forge // "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. return await safePost(webhook, { address, amount, confirmed, hash, memo, received, text, secret, }); } } catch (e) { err("problem calling webhook", e.message); } };