A feature that downloads a user-supplied URL gives the server a network action chosen partly by an untrusted caller. Without a destination policy, that action may reach services the caller cannot access directly. Validate the destination at the connection boundary, not only when a form accepts the URL.
This guide covers defensive design for URL imports, previews, and outbound integrations. Its examples are synthetic and contain no exploit payloads. The protected assets are internal services, server identity, network capacity, and any data an outbound request could disclose.
Decide whether arbitrary destinations are necessary
Start with the product requirement. If the feature only calls a known partner, accept a partner identifier and a constrained resource path rather than a complete URL. The server can select the approved origin from maintained configuration.
If users genuinely need arbitrary public destinations, document that broader boundary and isolate the fetching component accordingly. Do not pretend that the same simple host allowlist can serve both a fixed integration and an unrestricted import feature.
OWASP's SSRF prevention guidance distinguishes these cases and recommends complementary application and network controls. It also identifies redirects as a way an initially accepted destination can change.
For each feature, specify allowed schemes, ports, destinations, request methods, and response limits. A preview fetcher rarely needs to send application credentials or accept a caller-controlled authorization header. Give it only the network and identity capabilities its task requires.
Parse once and enforce a canonical destination policy
Use a maintained URL parser, then validate the parsed fields through explicit rules. Bound input length before parsing. Reject unsupported schemes, embedded credentials, unexpected ports, and malformed host representations. Avoid matching a raw URL with a loose substring test.
Normalize hostnames according to the parser's documented behavior and compare exact approved names when using a fixed destination set. A hostname that merely contains an approved string does not belong to that origin. Decide explicitly whether subdomains are allowed and who controls them.
Treat the URL path and query as separate inputs. Validate required path structure and encode values when assembling an outbound request. Avoid letting a caller change the authority through string concatenation or parser differences between validation and the HTTP client.
In a synthetic partner integration, accept a bounded document identifier and construct the path under the fixed partner origin. That removes unnecessary caller control while preserving the useful feature. Test the complete construction process rather than validating one string and later sending a different one.
Bind address validation to the actual connection
Resolving an allowed hostname and then letting the HTTP client resolve it again creates two potentially different decisions. A destination policy must cover the address the connection actually uses, including IPv4 and IPv6 behavior and any fallback path.
For public-only fetching, classify every candidate address against the approved network policy. Deny internal and otherwise disallowed ranges through a maintained implementation. Do not rely on a short hand-written list of familiar address prefixes.
Use a transport or egress component that connects through the validated destination without silently performing a new unchecked resolution. Preserve hostname-based TLS verification when connecting to a selected address. Changing the connection address must not become an excuse to disable certificate checks.
Apply network enforcement independently so that an application mistake still has a bounded reach. Inspect proxy configuration and service-mesh behavior: an egress proxy may resolve the destination itself, changing which component must enforce the rule. Record that ownership in the deployment design.
Constrain redirects, response processing, and retries
Disable automatic redirect following when the feature does not require it. If redirects are necessary, validate every new destination through the same policy and impose a small documented hop limit. Never treat approval of the first URL as approval of its entire redirect chain.
Bound connection time, total request time, response bytes, decompressed bytes, and concurrent fetches. Enforce limits while reading rather than buffering an unlimited response and checking afterward. A publicly reachable destination can still consume excessive memory or keep a worker occupied.
Do not forward cookies, application credentials, or caller-supplied sensitive headers to the destination. Choose outbound headers from a server-controlled set. If a partner needs credentials, bind those credentials to that exact integration and origin rather than attaching them to a general fetcher.
Retry only within the total work budget and for outcomes the operation can safely repeat. A fetcher outage should not amplify traffic through several retrying layers. Use the guide to bounded retry policies for that separate reliability decision.
Verify denied paths and define containment
Create an isolated test harness with controlled public-policy and internal-policy destinations. Verify exact allowlist matching, alternate address families, changed resolution results, redirects, proxy routing, oversized bodies, slow responses, and exhausted concurrency. Assert that denial occurs before the prohibited connection is made.
Record a sanitized reason code and request identifier for failures. Avoid logging complete URLs when queries may contain private data. Client errors should describe the rejected operation without exposing internal hostnames, network topology, or resolver diagnostics.
If unexpected outbound access is detected, disable the affected fetch capability or restrict its egress while investigating. Revoke any integration credentials that may have been exposed, then review destination records and server-side effects. Fixing the parser alone does not reverse requests already sent.
Review residual access deliberately. Approved external services may be compromised, and a response from an allowed destination is still untrusted content. Keep output handling, file validation, and authorization separate. The design is useful when the caller's influence ends at a documented, enforced destination and resource budget rather than at the server's full network reach.
Was this guide useful?
Your rating helps us prioritize clearer, more practical technical content.
Review diffs, run checks, and prepare the release in Arezgit.
Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.
Explore Arezgit