Summary
When SetHeaderAuthorizationKey() is used to configure a custom HTTP header name for authentication tokens (e.g., X-API-Key, X-Auth-Token), the credential is leaked to cross-domain redirect targets.
Go's net/http only strips standard sensitive headers (Authorization, Cookie, Proxy-Authorization) on cross-domain redirects. Custom header names configured via resty's SetHeaderAuthorizationKey() are NOT recognized as sensitive and are forwarded verbatim.
Root Cause
client.go:597 - SetHeaderAuthorizationKey() allows changing the header name
middleware.go:288 - addCredentials() places auth token in user-configurable header
redirect.go:97-105 - checkHostAndAddHeaders() copies ALL headers without credential check
- Go's
net/http/client.go:814-815 only strips hardcoded headers: Authorization, Cookie, etc.
PoC
Standard 'Authorization' at attacker after redirect: "" (SECURE - Go strips it)
Custom 'X-API-Key' at attacker after redirect: "Bearer SECRET" (LEAKED!)
Tested with Go test servers on 127.0.0.1 -> 127.0.0.2 cross-domain redirect. All four custom header names tested (X-API-Key, X-Auth-Token, X-Custom-Authorization, Api-Key) leak credentials.
Comparison
- Python
requests: Strips Authorization on domain change
- curl 7.58+: Strips credentials on cross-domain redirect
- Go net/http: Only strips standard headers (same limitation)
Suggested Fix
In SetRedirectPolicy or default CheckRedirect, strip the custom auth header when redirect crosses domain boundaries.
Severity
CWE-200/CWE-522 | CVSS 7.4 High
AI-assisted source code review, manually verified with working PoC.
Summary
When
SetHeaderAuthorizationKey()is used to configure a custom HTTP header name for authentication tokens (e.g.,X-API-Key,X-Auth-Token), the credential is leaked to cross-domain redirect targets.Go's
net/httponly strips standard sensitive headers (Authorization,Cookie,Proxy-Authorization) on cross-domain redirects. Custom header names configured via resty'sSetHeaderAuthorizationKey()are NOT recognized as sensitive and are forwarded verbatim.Root Cause
client.go:597-SetHeaderAuthorizationKey()allows changing the header namemiddleware.go:288-addCredentials()places auth token in user-configurable headerredirect.go:97-105-checkHostAndAddHeaders()copies ALL headers without credential checknet/http/client.go:814-815only strips hardcoded headers:Authorization,Cookie, etc.PoC
Tested with Go test servers on 127.0.0.1 -> 127.0.0.2 cross-domain redirect. All four custom header names tested (
X-API-Key,X-Auth-Token,X-Custom-Authorization,Api-Key) leak credentials.Comparison
requests: StripsAuthorizationon domain changeSuggested Fix
In
SetRedirectPolicyor defaultCheckRedirect, strip the custom auth header when redirect crosses domain boundaries.Severity
CWE-200/CWE-522 | CVSS 7.4 High
AI-assisted source code review, manually verified with working PoC.