All articles
securityssrfnetworking

SSRF-Safe Webhooks by Default: How KestrelMQ Blocks Internal Targets and DNS Rebinding

KestrelMQ rejects private, loopback and metadata webhook targets at save time and again at delivery time, pins the socket to the validated IP, and never follows redirects. See the exact CIDR list and test it with curl.

KestrelMQ Engineering6 min read

A webhook platform is a machine that makes HTTP requests to URLs strangers give it. If a worker can be told to POST to http://169.254.169.254/latest/meta-data/ or http://redis:6379, a free account is a foothold inside your network.

KestrelMQ closes that by default, with no setting to turn on. Custom webhook targets are checked twice: when you save the integration, and again on every delivery attempt, against the address the socket will actually use.

See it reject a metadata address

Create an integration that points at the cloud metadata IP (your JWT and workspace from the quickstart):

terminal
curl -s -X POST "$KMQ/v1/integrations" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Workspace-Id: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "ssrf probe",
    "channel": "WEBHOOK",
    "provider": "CUSTOM_WEBHOOK",
    "credentials": { "url": "http://169.254.169.254/latest/meta-data/" }
  }' | jq
response · 422 application/problem+json
{
  "type": "https://errors.kestrelmq.dev/unprocessable-content",
  "title": "Unprocessable Content",
  "status": 422,
  "detail": "Webhook URL rejected: Target host \"169.254.169.254\" resolves to a blocked (private, loopback, link-local or reserved) address",
  "instance": "/v1/integrations",
  "timestamp": "2026-12-01T10:15:00.000Z"
}

Repeat with each of these and you get the same 422:

terminal
for URL in \
  "http://127.0.0.1:6379/" \
  "http://[::1]/" \
  "http://[::ffff:7f00:1]/" \
  "http://10.0.0.5/" \
  "http://100.64.0.1/" \
  "http://user:pass@example.com/" \
  "file:///etc/passwd"; do
  printf '%-34s ' "$URL"
  curl -s -X POST "$KMQ/v1/integrations" \
    -H "Authorization: Bearer $ACCESS_TOKEN" -H "X-Workspace-Id: $WORKSPACE_ID" \
    -H 'Content-Type: application/json' \
    -d "$(jq -n --arg u "$URL" '{name:"probe",channel:"WEBHOOK",provider:"CUSTOM_WEBHOOK",credentials:{url:$u}}')" \
    | jq -r '.detail'
done

The last two fail on shape rather than address: Target URL must not contain embedded credentials and Target must use the http:// or https:// scheme.

What is blocked

Every address a hostname resolves to is checked, and one blocked answer rejects the target, so an attacker cannot hide a private record behind a public one. IPv4-mapped, NAT64 and 6to4 IPv6 addresses are unwrapped and the embedded IPv4 address is judged. Anything that does not parse is rejected (fail closed).

FamilyRangeWhy
IPv40.0.0.0/8"This network"
IPv410.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16RFC 1918 private
IPv4100.64.0.0/10Carrier-grade NAT
IPv4127.0.0.0/8Loopback
IPv4169.254.0.0/16Link-local, cloud metadata
IPv4192.0.0.0/24IETF protocol assignments
IPv4198.18.0.0/15Benchmarking
IPv4224.0.0.0/4, 240.0.0.0/4Multicast and reserved
IPv6::/96Unspecified, loopback ::1, IPv4-compatible
IPv6::ffff:0:0/96IPv4-mapped: embedded IPv4 is re-checked
IPv664:ff9b::/96NAT64: embedded IPv4 is re-checked
IPv62002::/166to4: embedded IPv4 is re-checked
IPv6fc00::/7Unique local
IPv6fe80::/10, fec0::/10Link-local and deprecated site-local
IPv6ff00::/8Multicast

The IPv4-mapped row is the classic bypass: ::ffff:127.0.0.1 is loopback, but a check that only looks at IPv6 ranges sees an address outside all of them.

Why checking once at save time is not enough

Validation at save time alone fails for three reasons: DNS answers change (public today, private tomorrow), redirects can point a public URL at http://10.0.0.5/, and a hostile DNS server can return a public IP for the validation lookup and an internal one, with a zero TTL, for the connection lookup. So KestrelMQ validates again in the worker, immediately before connecting, and then connects to exactly what it validated.

Pinning the socket to the validated IP

Checking the DNS answer is not enough if the HTTP client then performs its own lookup: that second lookup is the rebinding window. The worker resolves the hostname once, validates every address, and hands the socket a lookup function that can only answer with those addresses:

pinned lookup (the technique)
function createPinnedLookup(addresses: { address: string; family: 4 | 6 }[]) {
  return (_hostname, options, callback) => {
    const candidates =
      options.family === 4 || options.family === 6
        ? addresses.filter((a) => a.family === options.family)
        : addresses;
    if (candidates.length === 0) return callback(Object.assign(new Error("No pinned address"), { code: "ENOTFOUND" }), "", 0);
    if (options.all) return callback(null, candidates);
    callback(null, candidates[0].address, candidates[0].family);
  };
}

// https.request({ hostname, port, lookup: createPinnedLookup(validated), servername: hostname, ... })

The request keeps the original hostname, so TLS SNI, certificate verification and the Host header stay correct. That is why pinning at the socket layer beats rewriting the URL to a bare IP.

Redirects, schemes, ports, response size

  • Redirects are never followed. A 3xx is just a non-success response, so a public URL cannot bounce a delivery to http://169.254.169.254/.
  • http and https are accepted; every other scheme (file:, gopher:, ftp:) is rejected, and so is any URL with embedded user:pass@ credentials.
  • There is no port allow-list. Internal services often live on odd ports (6379, 5432, 9200), but the address block-list already covers where they live. Add egress rules if you also want to restrict ports.
  • Response capture is capped at 256 KiB (262,144 bytes) and each attempt times out after 10 seconds, which also limits slow-loris style abuse.
  • Credentials and PII in stored attempts are masked.

Local development: the one flag

Testing against localhost is legitimate in development. Self-hosted instances can set:

.env
ALLOW_PRIVATE_WEBHOOK_TARGETS=true

This skips the address block-list but still pins DNS, and the worker logs a warning when it is on. Production refuses to start with it: environment validation fails with ALLOW_PRIVATE_WEBHOOK_TARGETS=true is not permitted when NODE_ENV=production (SSRF protection).

Defense in depth

Application checks should not be the only wall. Run workers in a network segment whose egress rules deny RFC 1918 ranges and the metadata address, enforce IMDSv2 (or equivalent) on cloud hosts, and test with hostile fixtures: http://2130706433 style literals, a name returning one public and one private record, a name that flips between lookups, and a public URL that redirects to 169.254.169.254.

Next step

Run the curl probe loop above against your instance, then read how at-least-once delivery works to see where this worker sits in the pipeline and how outbound requests are signed. The deployment-level controls are in the security and RBAC docs and the security overview.

FAQ

Does KestrelMQ block webhook URLs that point at internal addresses?

Yes, by default. A custom webhook URL that resolves to a private, loopback, link-local or reserved address, such as 169.254.169.254, is rejected with 422 when you create the integration, and re-validated every time the worker delivers. Self-hosted dev setups can opt out with ALLOW_PRIVATE_WEBHOOK_TARGETS, which production startup refuses.

How does KestrelMQ stop DNS rebinding?

The worker resolves the hostname once, rejects the target if any returned address is blocked, then connects only to those validated addresses through a pinned socket lookup. The original hostname is kept for TLS SNI, certificate verification and the Host header, so there is no second DNS lookup to flip.

Does KestrelMQ follow redirects, restrict ports or require https?

It never follows HTTP redirects, so a public URL cannot bounce a delivery to an internal address. It accepts http and https, rejects other schemes and URLs with embedded credentials, and does not enforce a port allow-list. Use egress rules to restrict ports.

Is an egress firewall enough on its own?

No. A network egress policy is an excellent second layer, but application-level checks give clear errors at save time and protect deployments where the firewall is misconfigured. Use both.

Run guaranteed webhook delivery on your own infrastructure

KestrelMQ is MIT-licensed and boots with a single Docker Compose file. Follow the quickstart or start in the hosted dashboard.