Summary
cpp-httplib's HTTP client reused stored Basic, Bearer, and Digest authentication credentials across cross-origin redirects, sending them to arbitrary hosts in the Authorization header.
When a malicious or compromised server issues a redirect to an attacker-controlled domain, that domain can receive these plaintext credentials and potentially reuse them against the original service or other systems.
Affected context
This vulnerability affects applications that use cpp-httplib's HTTP client (prior to 0.39.0) and enable automatic redirect following.
It is relevant when:
- The client stores or sets Basic Auth, Bearer Token, or Digest Auth credentials for a given host, and
- The contacted server can return 301/302/307/308 redirects to a different origin (different host, scheme, or port).
In such cases, the client may automatically include the original Authorization header on requests to the redirected, cross-origin destination.
Exploit preconditions
- Attack surface: Outbound HTTP/HTTPS requests made by cpp-httplib clients that:
- Use automatic redirect handling, and
- Carry
Authorizationheaders (Basic, Bearer, or Digest). - Required access: Ability for an attacker to:
- Control or compromise an HTTP(S) endpoint that the client talks to, or
- Influence DNS or routing so that a client connects to an attacker-controlled server that can issue redirects.
- Trigger point: The attacker-controlled or compromised server responds with a 301/302/307/308 redirect to a different origin under the attacker's control.
- Why exploitation is possible: The HTTP client did not properly scope or filter
Authorizationheaders on cross-origin redirects, so credentials bound to one origin were forwarded to another, unauthorized origin.
Why this happens
The underlying issue is improper scoping of sensitive headers during HTTP redirect handling.
cpp-httplib's client logic reused existing authentication headers for redirected requests without validating that the target origin matched the original authenticated origin.
This maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, since authentication tokens and passwords were disclosed to hosts that were not intended recipients.
At a design level, redirect handling failed to enforce the principle that credentials and other sensitive headers should not be automatically propagated across origins unless explicitly re-authorized.
Potential impact
- Attackers may obtain plaintext Basic Auth credentials (username and password) for services the client accesses.
- Attackers may capture Bearer tokens or API keys and reuse them to impersonate the client or user.
- Attackers can harvest Digest Auth material and attempt offline cracking or replay where applicable.
- Compromised credentials can be used to access protected APIs, exfiltrate data, or modify resources on the original service.
- Collected tokens may enable further lateral movement into internal systems or cloud environments that trust those tokens.
General mitigation guidance
Effective mitigation focuses on tightening redirect and credential handling behavior:
- Ensure that authentication headers are not automatically forwarded across origin boundaries during redirects; credentials should be scoped to their original host/realm.
- Apply explicit checks in client code so that on redirect, any
Authorizationheader is dropped unless the new origin is trusted and matches expected criteria (e.g., same host or preconfigured allowlist). - Where possible, separate tokens per domain or service, avoiding reuse of a single bearer token across multiple unrelated endpoints.
- Favor short-lived, least-privilege tokens so that any exposed token has limited utility and lifetime.
- Restrict which redirects are followed by default; for security-sensitive flows, require explicit approval or custom handling of redirects.
- Apply defense-in-depth at the server side by limiting the privileges of tokens and enforcing strict audience/issuer checks for bearer-style authentication.
How teams detect issues like this
Detecting and preventing similar issues can involve:
- Code review patterns:
- Look for HTTP client logic that automatically follows redirects while carrying over all headers, especially
Authorization,Cookie, or custom auth headers. - Verify that redirect handlers compare original and new origins, and strip sensitive headers on cross-origin changes.
- Static analysis and linters:
- Use rules that flag propagation of authentication headers across requests when the target host or scheme changes.
- Enforce policies that disallow blind
header_copybehavior for security-sensitive fields. - Runtime and logging analysis:
- Enable logging of outbound requests at a sanitized level to detect when credentials appear in requests to unexpected domains (take care to avoid logging full secrets).
- Monitor network egress patterns (e.g., via proxies or gateways) for
Authorizationheaders being sent to untrusted or unknown hosts. - Security testing:
- In integration testing, stand up controlled endpoints that issue cross-origin redirects and verify that clients do not forward sensitive headers to the redirected destination.

