fix(webhooks): refuse internal webhook targets and stop following redirects

Merchant-supplied webhook URLs were posted to without any host check,
redirects were followed, and the raw request error was stored and returned
to the caller. With open registration, anyone could make the service send
requests to the wallet RPC, the database, the daemon or a cloud metadata
address, and read back what the error revealed.

Every delivery path now goes through webhook_targets.post_webhook. It
accepts only http and https URLs without embedded credentials, requires
every resolved address to be public, and never follows redirects (a 3xx is
a failed delivery). WEBHOOK_ALLOWED_PRIVATE_HOSTS names exact hosts that may
resolve privately, for receivers reached over a LAN. Stored delivery errors
carry only the refusal reason or the exception class.
This commit is contained in:
2026-11-18 15:40:51 -05:00
parent b44181d8d9
commit 3764ffc4c2
8 changed files with 223 additions and 46 deletions
+4 -4
View File
@@ -8,7 +8,6 @@ import json
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response, status
from fastapi.responses import RedirectResponse, StreamingResponse
import requests
from requests import RequestException
from sqlalchemy import func, or_
from sqlalchemy.sql import cast
@@ -60,6 +59,7 @@ from .security import (
require_api_key,
)
from .webhooks import build_webhook_payload, dispatch_webhooks
from .webhook_targets import WebhookTargetRefused, delivery_error_message, post_webhook
from .qr_codes import ensure_invoice_qr_png, invoice_qr_url, resolve_qr_settings
router = APIRouter()
@@ -740,15 +740,15 @@ def redeliver_webhook_delivery(
status_code = None
error_message = None
try:
response = requests.post(
response = post_webhook(
delivery.url,
json=payload,
headers={"X-Webhook-Secret": webhook_secret},
timeout=5,
)
status_code = response.status_code
except RequestException as exc:
error_message = str(exc)
except (RequestException, WebhookTargetRefused) as exc:
error_message = delivery_error_message(exc)
redelivery = WebhookDelivery(
user_id=user.id,