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
+9
View File
@@ -47,3 +47,12 @@ FOUNDER_PAYMENT_ADDRESS = os.getenv("FOUNDER_PAYMENT_ADDRESS", "")
FOUNDER_VIEW_KEY = os.getenv("FOUNDER_VIEW_KEY", "")
QR_STORAGE_DIR = os.getenv("QR_STORAGE_DIR", "/qr")
ADMIN_API_KEY = os.getenv("ADMIN_API_KEY", "").strip()
# Webhook targets must resolve to public addresses. Hostnames listed here may
# resolve to private addresses, for a merchant receiver reached over a LAN.
# Exact hostnames, comma separated; empty refuses every private target.
WEBHOOK_ALLOWED_PRIVATE_HOSTS = frozenset(
host.strip().lower().rstrip(".")
for host in os.getenv("WEBHOOK_ALLOWED_PRIVATE_HOSTS", "").split(",")
if host.strip()
)