Summary
cpp-httplib clients configured with an HTTP/HTTPS proxy and set_follow_location(true) may silently disable TLS certificate and hostname verification when following HTTPS redirects.
Under these conditions, the client will trust any certificate presented by the redirect target, allowing an on-path attacker who can inject or modify redirect responses to intercept or tamper with the supposedly secure follow-up HTTPS connection.
Affected context
This vulnerability affects applications using cpp-httplib (prior to 0.37.2) as an HTTP/HTTPS client when:
- A proxy is configured for outbound connections, and
set_follow_location(true)is enabled so that redirects are automatically followed, and- The server responds with an HTTPS redirect while the client is using the proxy.
In this scenario, the new HTTPS connection created for the redirected URL may have certificate and hostname verification silently disabled, even if the original connection enforced TLS validation.
Exploit preconditions
- Attack surface: Network path between the client and the configured proxy or origin server, including any infrastructure capable of injecting or modifying HTTP responses.
- Required access: Ability to act as a man-in-the-middle or otherwise send crafted redirect responses to the cpp-httplib client.
- Trigger point: The client receives an HTTP redirect (e.g., 301, 302, 307, 308) to an HTTPS URL while using a proxy with
set_follow_location(true)enabled. - Why exploitation is possible: The library mishandles TLS verification state during redirected requests through a proxy, causing certificate and hostname checks to be disabled on the new connection without notifying the application.
Why this happens
The underlying issue is an improper certificate validation logic path (CWE-295) tied to redirect handling in the presence of a proxy.
When cpp-httplib follows an HTTPS redirect via a proxy, it establishes a new TLS connection but fails to consistently apply the configured certificate verification and hostname checking behavior.
Instead, the follow-up connection implicitly trusts any server certificate, breaking the security guarantees of TLS and allowing attackers to impersonate the redirect target without detection.
Conceptually, this is an insecure pattern where security-critical connection parameters are not preserved across request redirections, leading to downgraded security on subsequent hops.
Potential impact
- Attackers may intercept and read sensitive HTTPS traffic (credentials, session tokens, API keys, personal data) sent on the redirected request.
- Attackers could tamper with responses on the redirected connection, injecting or modifying data returned to the client.
- Session hijacking and account takeover may occur if authentication cookies or bearer tokens are exposed.
- Integrity of API interactions can be undermined, enabling data corruption or unauthorized operations through forged responses.
- The apparent security of HTTPS connections can be misleading to application developers and users, masking active man-in-the-middle attacks.
General mitigation guidance
Mitigation focuses on ensuring consistent, strict TLS validation across all connection paths, including redirects through proxies:
- Treat TLS verification settings (certificate and hostname checks) as immutable security invariants that must apply to every HTTPS connection, including follow-up requests after redirects.
- When designing HTTP clients, explicitly propagate TLS configuration (CA trust store, verification flags, hostname rules) to all new connections created as part of redirect handling, proxy tunneling, or connection reuse.
- Prefer a "fail closed" behavior: if certificate or hostname validation cannot be performed under redirect/proxy conditions, surface an error rather than silently degrading verification.
- Allow applications to explicitly control redirect behavior, including the option to limit or disable automatic redirects for sensitive operations or when proxies are involved.
- Encourage separation of security configuration from application logic so that default client behavior is secure, and weakening TLS checks requires explicit, conscious opt-in by the caller.
- Apply least-privilege to exposed secrets: avoid sending long-lived credentials or broadly scoped tokens on automatically followed redirects when not strictly necessary.
How teams detect issues like this
Detection typically involves combining code-centric and behavior-centric approaches:
- Code review: Examine HTTP client redirect implementations to ensure TLS verification flags and hostname checks are preserved across redirects, especially when proxies or CONNECT tunnels are used.
- Static analysis: Use rules or patterns that flag code paths where:
- TLS verification configuration is conditionally disabled,
- Redirect-handling logic creates new connections without reapplying security settings, or
- Different code paths for "initial" and "redirected" HTTPS requests exist with inconsistent verification.
- Dynamic testing: Perform controlled man-in-the-middle tests against applications using cpp-httplib:
- Return redirects to HTTPS endpoints with invalid, self-signed, or mismatched certificates and confirm that the client rejects them.
- Security policy enforcement: Define internal guidelines stating that TLS certificate and hostname verification must never be silently disabled for production traffic, and integrate checks into CI pipelines to catch configuration regressions.
- Library usage audits: Inventory and review all uses of cpp-httplib in the codebase, focusing on call sites that enable automatic redirects and proxies, verifying that they align with secure usage recommendations.

