Repository navigation
feat(webhooks): WEBHOOK_ALLOWED_CIDRS for operator-approved private receivers - #278
dominik-myszkowski wants to merge 1 commit into
Conversation
…eceivers (Calnode#261) Webhook targets go through the SSRF guard, which refuses every private, loopback, CGNAT and ULA address, so a receiver in a sibling container (http://sms-sender:8080/hook) was unreachable without a hairpin through the public proxy. WEBHOOK_ALLOWED_CIDRS (env only, empty by default) lists private networks that are exempt. netutil.ResolveSafeAllowing applies one rule at save time (validateWebhookURL) and at dial time (SafeTransportAllowing), so DNS rebinding between the two gains nothing. Link-local / cloud metadata and the unspecified address are refused before the list is consulted, so listing 169.254.0.0/16 or 0.0.0.0/0 cannot reach 169.254.169.254. It is deliberately not an in-app setting: workspace admins create webhooks and must not be able to widen where they can reach. Documented in DEPLOY.md beside TRUSTED_PROXY_CIDRS, including that listing a range extends the trust boundary for attendee data to that network.
There was a problem hiding this comment.
ℹ️ No blocking issues — a couple of rough edges worth a look.
Approach: sound. One shared rule (ResolveSafeAllowing) governs both the save-time check and the dial-time transport, and the link-local/metadata refusal happens before the allowlist is consulted, so listing a range cannot unblock IMDS. Making it env-only is the right home given workspace admins create webhooks.
Reviewed changes
- Allowlist core (
internal/netutil) —blockedWebhookIPrefuses link-local (including AWS'sfd00:ec2::254) and the unspecified address before consulting the list;ResolveSafenow delegates withnil, so the default path is unchanged. - Dial-time transport —
SafeTransportAllowingreusesdialGuardTransport, so the hostname is re-judged on the address actually dialled and redirects re-enter the guarded dialer. - Worker and server wiring —
WithWebhookAllowedCIDRsswaps the transport only for a non-empty list;BuildHandlerhands the same parsed slice to the handler and the worker. - Save-time check (
internal/handler) —validateWebhookURLtakes the list andCreateWebhookpassesh.webhookAllowedCIDRs;PatchWebhookcannot change the URL, so there is no second save-time site to keep in step. - Env parsing —
WEBHOOK_ALLOWED_CIDRSparsed at boot withParseTrustedProxiessemantics: each bad entry dropped (fail closed), the parsed list logged, and a metadata-covering entry warned about. - Tests and docs — netutil/handler/worker/server coverage (the worker test uses the production transport, not the
WithHTTPClientbypass), plus the DEPLOY row and ARCHITECTURE §13.
ℹ️ The new env var never reaches the release notes
docker-publish.yml cuts each release body from CHANGELOG.md, and the [Unreleased] section is actively maintained. Without an Added entry, operators reading the release notes on upgrade will not learn WEBHOOK_ALLOWED_CIDRS exists — which is how they would otherwise discover the fix for a private receiver.
Technical details
# CHANGELOG entry for WEBHOOK_ALLOWED_CIDRS
## Affected sites
- `CHANGELOG.md:33` — `[Unreleased] ### Added` holds the operator-facing additions; this PR adds none.
## Required outcome
- An `Added` bullet naming the env var, its default (off), the sibling-container use case, and that link-local/metadata stays blocked whatever is listed.
## Suggested approach (optional)
- Match the DEPLOY row's wording and caveats so the two do not drift.deepseek-v4.1-flash | 𝕏
| w.httpClient = &http.Client{ | ||
| Timeout: w.httpClient.Timeout, | ||
| Transport: netutil.SafeTransportAllowing(w.logger, "worker: webhook SSRF block", allowed), | ||
| } |
There was a problem hiding this comment.
This builds a fresh client and copies only Timeout, so any client installed through WithHTTPClient loses its Transport, CheckRedirect, Jar, … — and ordering this option after WithHTTPClient silently drops the allowlist. A shallow copy that replaces only Transport keeps both the caller's client and the guard, which is what the comment above claims.
Technical details
# Preserve the injected client's fields
## Affected sites
- `internal/worker/worker.go:60-63` — `w.httpClient = &http.Client{Timeout: w.httpClient.Timeout, Transport: ...}` discards every other field of `w.httpClient`.
## Required outcome
- `WithWebhookAllowedCIDRs` changes only the transport; all other fields of an existing client survive.
## Suggested approach (optional)
- `cp := *w.httpClient; cp.Transport = netutil.SafeTransportAllowing(...); w.httpClient = &cp`.| w.httpClient = &http.Client{ | |
| Timeout: w.httpClient.Timeout, | |
| Transport: netutil.SafeTransportAllowing(w.logger, "worker: webhook SSRF block", allowed), | |
| } | |
| cp := *w.httpClient | |
| cp.Transport = netutil.SafeTransportAllowing(w.logger, "worker: webhook SSRF block", allowed) | |
| w.httpClient = &cp |
| | `LITESTREAM_REPLICA_URL` | recommended | — | Enables continuous SQLite backup (see §6). | | ||
| | `COOKIE_SECURE` | no | https→true | Override cookie Secure flag; defaults from `BASE_URL` scheme. | | ||
| | `TRUSTED_PROXY_CIDRS` | no | — | Comma-separated CIDRs (a bare address = one host) whose `X-Forwarded-For` is believed when keying per-IP rate limits, e.g. `10.0.0.0/8`. Include a fronting CDN's own ranges so the walk steps over its edge and lands on the visitor. Unset ⇒ the header is ignored and the limit keys on the TCP peer, so behind a CDN every visitor shares one bucket. **Only list networks you control**: anything in the list can name any client IP it likes. Single-value vendor headers (`CF-Connecting-IP`, `X-Real-IP`) are never read, from any peer. | | ||
| | `WEBHOOK_ALLOWED_CIDRS` | no | — | Comma-separated CIDRs (a bare address = one host) of **private** networks webhooks may be delivered to, e.g. `172.20.0.0/16` for a receiver in a sibling container (`http://sms-sender:8080/hook`). Unset ⇒ every private, loopback, CGNAT and ULA target is refused, both when the URL is saved and when it is dialled. Operator-only on purpose: workspace admins can create webhooks, so this is not an in-app setting. Link-local / cloud metadata (`169.254.0.0/16`, `fe80::/10`, `fd00:ec2::254`) **stays blocked whatever is listed**. **Only list networks you control**, and note what you are trusting: webhook payloads carry attendee details (names, emails, intake answers), so listing a range extends the trust boundary for that data to everything on that network, not just reachability. On Docker, give the network a fixed `--subnet` so the range can't change under you. | |
There was a problem hiding this comment.
The example receiver here is http://, but the admin webhooks page rejects any URL that does not start with https:// (frontend/src/routes/webhooks/+page.svelte:108), so this exact setup can only be created through POST /v1/webhooks with an API key. Either say that in this row or relax the UI check for receivers the operator has allowlisted.
Technical details
# Private HTTP receivers are API-only today
## Affected sites
- `DEPLOY.md:80` — example uses `http://sms-sender:8080/hook`.
- `frontend/src/routes/webhooks/+page.svelte:108` — `!form.url.startsWith('https://')` blocks creation in the admin UI, while `CreateWebhook` accepts `http`.
## Required outcome
- An operator following this row can actually create the receiver it describes.
## Suggested approach (optional)
- The UI cannot know `WEBHOOK_ALLOWED_CIDRS` (env-only, and it should stay that way), so documenting the API path is the low-risk fix.
## Open questions for the human
- Was the UI's `https://` rule meant to be absolute for all webhooks, or should it be narrowed when private receivers are allowlisted?
Implements #261: an operator-level escape hatch from the webhook SSRF guard for receivers on the operator's own network (e.g. a sibling container).
What it does
WEBHOOK_ALLOWED_CIDRS(comma-separated CIDRs, a bare address = one host; empty by default, so nothing changes). Parsed with the same rules asTRUSTED_PROXY_CIDRS. A bad entry is logged and dropped, which fails closed: that network just stays blocked.netutil.ResolveSafeAllowing(ctx, host, allowed)is the single rule.ResolveSafeis nowResolveSafeAllowing(…, nil), so the default path is unchanged. It is used at save time (validateWebhookURL) and at dial time (netutil.SafeTransportAllowingviaworker.WithWebhookAllowedCIDRs), so DNS rebinding between the two gains nothing.Your three conditions
blockedWebhookIPrefuses link-local (169.254.0.0/16,fe80::/10), AWS's IPv6 IMDSfd00:ec2::254and the unspecified address before it looks at the list. The code comment says why the order matters. Listing a range that contains169.254.169.254also logs a warning at startup, since it reads as if it unblocked it.TRUSTED_PROXY_CIDRSwith the same "only list networks you control" warning, plus the trust-boundary line: webhook payloads carry attendee details, so listing a range extends trust for that data to the whole network. ARCHITECTURE §13 has a short paragraph too.Tests
netutil:TestResolveSafeAllowinguses a deliberately over-broad list (169.254.0.0/16,fd00::/8,0.0.0.0/0) and asserts the metadata addresses, link-local and0.0.0.0are still refused.TestResolveSafeAllowing_emptyIsResolveSafechecks that an empty list gives the same verdict asResolveSafe.TestSafeTransportAllowingchecks the dial-time guard against a real local server.handler:TestCreateWebhook_allowedCIDRscovers private refused by default, the listed network accepted, an unlisted private address still refused, and metadata refused even when listed.worker:TestWorker_webhookAllowedCIDRsuses the production transport (noWithHTTPClientbypass). Delivery is refused before connecting by default and when another network is listed, and succeeds when the receiver's network is listed.server: parsing, a bad entry dropped, a bare address as a single host, and the metadata warning.gofmt,go vet ./...,go build ./...,go test ./...andgo run ./cmd/i18n-coveragepass locally. No UI or i18n changes, and no migration.I also checked it on a running binary. With
WEBHOOK_ALLOWED_CIDRS=127.0.0.0/8, a webhook tohttp://127.0.0.1:<port>/hookis accepted,169.254.169.254and10.0.0.1are refused with 400, and a real booking deliversbooking.createdto the local receiver. Without the variable, the same URL is refused as before and nothing extra is logged.