Skip to content

Security: Custom auth headers via SetHeaderAuthorizationKey leak on cross-domain redirect by the underlying Go net/http #1128

Description

@Den-Sec

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions