Skip to content

feat(webhooks): WEBHOOK_ALLOWED_CIDRS for operator-approved private receivers - #278

Open
dominik-myszkowski wants to merge 1 commit into
Calnode:mainfrom
dominik-myszkowski:feat/webhook-allowed-cidrs
Open

dominik-myszkowski wants to merge 1 commit into
Calnode:mainfrom
dominik-myszkowski:feat/webhook-allowed-cidrs

Conversation

@dominik-myszkowski

Copy link
Copy Markdown

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

  • New env var WEBHOOK_ALLOWED_CIDRS (comma-separated CIDRs, a bare address = one host; empty by default, so nothing changes). Parsed with the same rules as TRUSTED_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. ResolveSafe is now ResolveSafeAllowing(…, nil), so the default path is unchanged. It is used at save time (validateWebhookURL) and at dial time (netutil.SafeTransportAllowing via worker.WithWebhookAllowedCIDRs), so DNS rebinding between the two gains nothing.
  • Env only, never an in-app setting, for the reason you gave: workspace admins can create webhooks.

Your three conditions

  1. Metadata and link-local stay blocked whatever is listed. blockedWebhookIP refuses link-local (169.254.0.0/16, fe80::/10), AWS's IPv6 IMDS fd00:ec2::254 and the unspecified address before it looks at the list. The code comment says why the order matters. Listing a range that contains 169.254.169.254 also logs a warning at startup, since it reads as if it unblocked it.
  2. Save time and dial time: see above. The same function and the same list on both sides.
  3. DEPLOY.md: a row next to TRUSTED_PROXY_CIDRS with 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: TestResolveSafeAllowing uses a deliberately over-broad list (169.254.0.0/16, fd00::/8, 0.0.0.0/0) and asserts the metadata addresses, link-local and 0.0.0.0 are still refused. TestResolveSafeAllowing_emptyIsResolveSafe checks that an empty list gives the same verdict as ResolveSafe. TestSafeTransportAllowing checks the dial-time guard against a real local server.
  • handler: TestCreateWebhook_allowedCIDRs covers private refused by default, the listed network accepted, an unlisted private address still refused, and metadata refused even when listed.
  • worker: TestWorker_webhookAllowedCIDRs uses the production transport (no WithHTTPClient bypass). 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 ./... and go run ./cmd/i18n-coverage pass 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 to http://127.0.0.1:<port>/hook is accepted, 169.254.169.254 and 10.0.0.1 are refused with 400, and a real booking delivers booking.created to the local receiver. Without the variable, the same URL is refused as before and nothing extra is logged.

…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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) — blockedWebhookIP refuses link-local (including AWS's fd00:ec2::254) and the unspecified address before consulting the list; ResolveSafe now delegates with nil, so the default path is unchanged.
  • Dial-time transport — SafeTransportAllowing reuses dialGuardTransport, so the hostname is re-judged on the address actually dialled and redirects re-enter the guarded dialer.
  • Worker and server wiring — WithWebhookAllowedCIDRs swaps the transport only for a non-empty list; BuildHandler hands the same parsed slice to the handler and the worker.
  • Save-time check (internal/handler) — validateWebhookURL takes the list and CreateWebhook passes h.webhookAllowedCIDRs; PatchWebhook cannot change the URL, so there is no second save-time site to keep in step.
  • Env parsing — WEBHOOK_ALLOWED_CIDRS parsed at boot with ParseTrustedProxies semantics: 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 WithHTTPClient bypass), 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/worker/worker.go
Comment on lines +60 to +63
w.httpClient = &http.Client{
Timeout: w.httpClient.Timeout,
Transport: netutil.SafeTransportAllowing(w.logger, "worker: webhook SSRF block", allowed),
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.
Suggested change
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

Comment thread DEPLOY.md
| `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. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant