Curl redirects need an explicit protocol ceiling
Server-side URL fetchers often restrict the first URL and then leave redirect handling to curl. A permitted HTTP endpoint can answer with a redirect to a scheme that the application never intended to expose. The result is a policy gap between the original validation and the request curl actually performs.
Curl provides --proto to limit protocols used for the initial request and --proto-redir to limit protocols accepted after a redirect. The project recommends using the options together so a script can depend on a known protocol set even when the local curl build enables other handlers.
Make the policy visible
A strict fetch can start with an explicit protocol set and a small redirect budget.
curl --proto '=http,https' \ --proto-redir '=http,https' \ --location \ --max-redirs 3 \ 'https://example.invalid/resource' Use the same options in every code path that follows redirects. A library wrapper that sets one option and leaves the other at its default has not expressed the application's complete policy.
The protocol check is only one layer. A fetcher also needs a destination policy. If the service should reach only approved DNS names, resolve the name, reject private or link-local targets under the service's network policy, and connect to the approved address. Redirect handling should run the destination check again because the host can change.
Credentials and request bodies
Redirects can also change where credentials and request bodies are sent. Do not attach an authorization header, cookie, or private request body by default. Configure the client to strip sensitive headers on cross-origin redirects and use a separate client for trusted upstreams when forwarding is required.
For a POST that redirects, review whether the method and body should be preserved. Some status codes allow a client to change POST to GET. A policy that assumes the body remains private after every redirect is incomplete.
Test the actual curl process
Record the exact curl version and compile-time protocols in deployment. Unit tests should include an HTTP response that redirects to a blocked scheme, a redirect to a private address, a chain longer than the configured maximum, and a redirect to a different hostname. Test with the same TLS, proxy, DNS, and header settings used in production.
The command's exit status should distinguish policy rejection from a failed remote request. Log the original host, redirect chain, final scheme, and policy reason without logging authorization values. A blocked scheme is an expected security decision, not a transport error that should trigger a fallback client.
Verify that every redirect path executes under the same protocol and destination policy. Curl's options make that policy expressible. The surrounding application still has to apply it consistently.
![UI Practice - Duolingo [1]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8uawvr6a0e07ilktpkk7.png)

