Skip to content

Lesson 8 of 9 · 27m

Endpoint Registration, SSRF, and Callback URL Safety

Validate subscriber-controlled callback URLs, pin resolution behavior, block internal network reachability, and verify ownership before sending secrets-bearing events.

The moment your product sends HTTP requests to customer-controlled URLs, you have built an SSRF feature. Sometimes it is a useful integration feature; sometimes it is a bolt-on port scanner and cloud-metadata reader. Webhook systems are server-side request forgery with a business model. Treat endpoint registration and delivery as security-sensitive infrastructure, not as a simple settings form.

Validate the URL syntax, then validate what it resolves to

Basic validation is necessary but nowhere near sufficient:

require https
reject fragments
reject userinfo such as https://user@host/
normalize internationalized domains deliberately
enforce a small list of acceptable ports, often 443 only
require a public DNS name or explicitly vetted IP

The dangerous part happens after parsing. https://example.com can resolve to 10.0.0.8, 169.254.169.254, or a private IPv6 address. DNS answers can also differ between validation time and connection time. This is DNS rebinding: validate now, connect later, get a different address.

Pin the validated resolution into the connection

The strongest practical pattern is to resolve once through a controlled resolver, validate every returned address, and connect to the selected IP while preserving the original hostname for TLS and the HTTP Host header. Many HTTP libraries do not expose this cleanly. A controlled egress proxy is often safer than ad-hoc socket surgery:

webhook worker -> restricted egress proxy -> internet
                     |
                     +-- deny RFC1918, loopback, link-local, metadata ranges
                     +-- enforce DNS resolution and TLS SNI policy
                     +-- no redirects unless revalidated

Blocking only IPv4 private ranges is not enough. Consider loopback, link-local, CGNAT 100.64.0.0/10, IPv6 ULA fc00::/7, IPv6 loopback, cloud metadata endpoints, and IPv4-mapped IPv6 forms such as ::ffff:127.0.0.1.

Redirects are a new target, not a convenience

A customer registers a harmless public URL, then later redirects it to an internal address. If your HTTP client follows redirects automatically, your validation was theater. Disable redirects or validate each hop as a fresh endpoint target. Strictly speaking, POST redirects are also semantically messy — many clients convert methods or drop bodies. Best practice is to treat redirects as permanent endpoint failures and tell the customer to update configuration.

Prove endpoint ownership before activation

Do not start sending customer data because someone typed a URL. Send a verification challenge:

{
  "type": "webhook.endpoint_verification",
  "challenge": "whv_01J9T2E8M3A7N0",
  "endpoint": "https://ops.acme-logistics.com/hooks/acme"
}

Require the endpoint to return the challenge within a short window, or require an ownership token configured out of band. Slack-style URL verification is a common pattern. For high-risk data, combine cryptographic secret display-once with a test event that confirms the receiver can verify signatures.

Segregate credentials and minimize blast radius

Signing secrets do not authenticate the network location. A malicious or compromised endpoint owner can copy payloads elsewhere. Minimize sensitive fields, scope subscriptions narrowly, expire test endpoints, and expose delivery logs to customers so unexpected destinations are visible. If payload contents are highly sensitive, consider thin events with authenticated fetch-back instead of full snapshots.

Field notes

  • A URL parser may normalize away tricks such as decimal IPs (2130706433) or octal forms. Canonicalize before comparing.
  • Do not resolve once and cache forever. DNS TTLs and endpoint ownership changes matter operationally.
  • Rate-limit endpoint registration and test pings; otherwise the feature becomes an amplifier.
  • Log the resolved egress IP alongside delivery attempts for incident response, but protect it as infrastructure telemetry.
  • Local development needs an explicit tunnel story. Do not weaken production validation because developers use localhost.

Was this lesson helpful?

Sign in to rate