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
@@ -4,13 +4,13 @@ import logging
import uuid
from datetime import datetime
import requests
from requests import RequestException
from sqlalchemy.orm import Session
from .formatting import format_xmr_amount
from .models import Invoice, User, Webhook, WebhookDelivery
from .security import decrypt_secret, encrypt_secret, generate_webhook_secret
from .webhook_targets import WebhookTargetRefused, delivery_error_message, post_webhook
logger = logging.getLogger(__name__)
@@ -73,10 +73,10 @@ def dispatch_webhooks(
error_message = None
try:
headers = {"X-Webhook-Secret": webhook_secret} if webhook_secret else None
response = requests.post(target_url, json=payload, headers=headers, timeout=5)
response = post_webhook(target_url, json=payload, headers=headers, 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)
logger.warning(
"Webhook delivery failed",
extra={"webhook_id": str(hook.id), "event": event},