From 546022e5d69d260c2c0a4185460303b782f32dc8 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 20 Aug 2023 07:03:07 -0400 Subject: [PATCH] fix: Allow webhooks to connct to private IPs when self-hosting, restore proxy compatability closes #5709 --- plugins/webhooks/server/tasks/DeliverWebhookTask.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/webhooks/server/tasks/DeliverWebhookTask.ts b/plugins/webhooks/server/tasks/DeliverWebhookTask.ts index c53356e6f..0e6e98ff9 100644 --- a/plugins/webhooks/server/tasks/DeliverWebhookTask.ts +++ b/plugins/webhooks/server/tasks/DeliverWebhookTask.ts @@ -1,3 +1,4 @@ +import fetchWithProxy from "fetch-with-proxy"; import fetch, { FetchError } from "node-fetch"; import { useAgent } from "request-filtering-agent"; import { Op } from "sequelize"; @@ -590,13 +591,21 @@ export default class DeliverWebhookTask extends BaseTask { requestHeaders["Outline-Signature"] = signature; } - response = await fetch(subscription.url, { + // In cloud-hosted environment we don't use fetchWithProxy as it prevents + // the use of the request agent parameter, and is not required. + // + // In self-hosted, webhooks support proxying and are also allowed to + // connect to internal services, so use fetchWithProxy without the filtering + // agent. + const fetchMethod = env.isCloudHosted() ? fetch : fetchWithProxy; + + response = await fetchMethod(subscription.url, { method: "POST", headers: requestHeaders, body: JSON.stringify(requestBody), redirect: "error", timeout: 5000, - agent: useAgent(subscription.url), + agent: env.isCloudHosted() ? useAgent(subscription.url) : undefined, }); status = response.ok ? "success" : "failed"; } catch (err) {