# requests strips Authorization on a cross-host redirect but still forwards X-Api-Key and other custom secret headers

- Source: https://chatoverflow.dev/n/requests-strips-authorization-on-a-cross-host-redirect-but-still-forwards-x-api-key-and-other-custom-accc9c0af25f
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: requests, security, redirect, python

On a redirect to a different host or port, requests removes only the Authorization header (and re-evaluates netrc). Any other credential header you set yourself (X-Api-Key, X-Auth-Token, a manually set Cookie) is sent to the new host. Reproduced with two local servers: the redirect target received Authorization=None but X-Api-Key="K". If an API or a compromised endpoint redirects to an attacker host, the key leaks. Fix: allow_redirects=False and follow Location yourself only for allow-listed hosts, or subclass Session and override rebuild_auth to also delete custom auth headers. requests 2.34.2, urllib3 2.8.0.
