Repository navigation
fix: harden dns lookups for webhooks - #3588
Conversation
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (11 lines, under the 30-line bar for Tier 4) Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
PR Review
2 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 2 minor 1 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines1 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. The SSRF/DNS-rebinding hardening is sound: 🟡 P2 — recommended
🔵 P3 nitpicks (6)
Reviewers (9): correctness, security, adversarial, reliability, testing, maintainability, kieran-typescript, project-standards, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 465 passed • 1 skipped • 1428s
Tests ran across 4 shards in parallel. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| // private IP (e.g. 127-0-0-1.nip.io) gets through it. Checking at connect time | ||
| // also covers DNS rebinding, since the checked address is the one dialed. | ||
| // Node skips lookup for IP literals; validateWebhookUrl covers those. | ||
| export const webhookLookup: LookupFunction = (hostname, options, callback) => { |
There was a problem hiding this comment.
🔵 minor — Save and /validate still accept hostnames that every delivery will now reject
The new resolved-address check runs only at send time, through the undici dispatcher in generic.ts. WEBHOOK_CONFIG_CHECKS (validators.ts:219), which create and POST /api/v2/webhooks/validate both use, checks only the hostname string. So a URL like http://127-0-0-1.nip.io/ or an internal name that isn't allowlisted saves without error, then every alert firing fails and the problem shows up only in logs and alert history. This also breaks the invariant stated in the comment above that list. Fix: add an async resolve-and-isPrivateIp check (the same logic as webhookLookup) to the create/validate path, so these configs are rejected with a 400 when saved. Keep the connect-time check as the rebinding guard.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
## Summary Generic and incident.io alert webhooks have sent `User-Agent: undici` since #3588 moved delivery to undici's `fetch` (for DNS-pinned SSRF checks). Node's built-in fetch sent `node`. Some receivers' WAFs block `undici`. They return an HTML `403 Forbidden` before the request reaches the receiving service, so every alert to them fails. Webhook delivery now sends `User-Agent: ClickStack-Alerts/<CODE_VERSION>`, or `ClickStack-Alerts` when no version is set. A User-Agent in the webhook's headers still wins. The check ignores case, so a user's `user-agent` is not sent next to the default. The webhook test route uses the same function, so test sends get the new header too. Slack does not use undici and is unaffected. Not changed here: a user's lowercase `content-type` is still sent next to the default `Content-Type`. That predates this PR. Unit tests in `transports/__tests__/generic.test.ts` cover the default, an override, and a lowercase override. I did not run the integration suite locally. The existing `checkAlerts.int.test.ts` header assertion uses `expect.objectContaining`, so the new header should not break it. ### How to reproduce **Starting point:** `yarn dev` (alerts and webhooks need the API). **On `main`:** 1. Create a Generic webhook pointing at a request inspector such as https://webhook.site. 2. Send a test notification from the webhook form. 3. The inspector shows `User-Agent: undici`. **On this branch:** 1. Repeat the steps above. The inspector shows `User-Agent: ClickStack-Alerts/<version>`. 2. Add `{"User-Agent": "custom"}` under the webhook's headers and send again. The inspector shows `custom`. ### How to test on Vercel preview N/A — non-UI change ### References - Linear Issue: https://linear.app/clickhouse/issue/HDX-6170 - Related PRs: #3588
Summary
Hardens the webhook logic by doing an actual lookup of the DNS record and determining whether to proceed/error.
References