Validate client-provided callback URLs against SSRF
A URL syntax check alone does not make a callback safe. Prefer an endpoint ID mapped to a verified destination; if arbitrary external URLs are required, validate parsed components, resolved IPs, the actual connection, redirects and network egress. Based on OWASP and RFC 3986 guidance reviewed 2026-11-20.
A URL syntax check alone does not make a callback safe. Prefer an endpoint ID mapped to a verified destination; if arbitrary external URLs are required, validate parsed components, resolved IPs, the actual connection, redirects and network egress. Based on OWASP and RFC 3986 guidance reviewed 2026-11-20.
Choose the destination model
Use an exact allowlist for known partners. For arbitrary public destinations, allow only HTTPS and define allowed ports and paths. Parse with a maintained URL parser; reject userinfo and ambiguous forms, compare the canonical host rather than a string prefix, and treat parser disagreement as invalid.
Bind DNS checks to the connection
Check every A and AAAA result against permitted networks immediately before connecting. Reject any address outside policy, including loopback, private, link-local, unspecified, multicast and internal ranges. Bind the HTTP client to an approved address while preserving the original hostname for Host, TLS SNI and certificate validation; otherwise a second DNS lookup can enable rebinding. Apply the same check to retries.
Control redirects and request scope
Disable redirects, or repeat the full validation for each Location. Restrict method/path; never forward API authorization, cookies or internal headers to the destination. Keep TLS verification on and bound connect/read time, response size, retries and concurrency. Add firewall or egress-proxy blocks as defense in depth.
Verification checklist
Test rejection of loopback and private IPv4/IPv6, userinfo, misleading hosts, disallowed schemes/ports, DNS changes between check and connect, and redirects to internal IPs. Test only policy-approved HTTPS destinations as allowed cases. No sender, DNS, HTTP client or firewall was run for this guide.
Official references
[OWASP SSRF Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html)
[OWASP Webhook Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Webhook_Security_Cheat_Sheet.html)
[RFC 3986: URI Generic Syntax](https://www.rfc-editor.org/rfc/rfc3986.html)
[OWASP Unvalidated Redirects and Forwards Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html)