Summary
A TLS certificate validation flaw in cpp-httplib's Mbed TLS and wolfSSL backends causes HTTPS and WebSocket clients to skip proper certificate chain checks when connecting to IP-literal hosts.
In this configuration, a man-in-the-middle attacker who can intercept traffic may present a crafted certificate and read or modify supposedly secure HTTPS or WebSocket communications.
Affected context
The vulnerability appears in applications that embed cpp-httplib as an HTTPS or WebSocket client and compile it with Mbed TLS or wolfSSL support enabled.
It specifically affects scenarios where the client connects directly to an IP address (an IP-literal host) rather than a DNS hostname while server certificate verification is turned on.
In this context, SSLClient and HTTPS Client instances skip certificate chain validation, and WebSocketClient with Mbed TLS may skip verification entirely, weakening expected TLS protections.
Exploit preconditions
- Attack surface: Network traffic between cpp-httplib-based HTTPS/WebSocket clients and their servers
- Required access: Ability to intercept or influence network traffic (e.g., same network segment, rogue access point, compromised router, or upstream proxy control)
- Trigger point: Client connections made over HTTPS or secure WebSocket (wss) to IP-literal hosts with server certificate verification enabled
- Why exploitation is possible: The TLS backend fails to properly validate or enforce the certificate chain and hostname for IP-literal connections, allowing a crafted certificate to be accepted without the expected checks
Why this happens
At the core, this is a TLS certificate validation logic error mapped to CWE-295: Improper Certificate Validation.
The HTTPS and WebSocket client implementations for the Mbed TLS and wolfSSL backends treat IP-literal hosts as verified without performing full certificate chain and hostname validation.
This insecure pattern effectively trusts any acceptable-looking certificate in these conditions, breaking the assurance that the remote endpoint is the intended server and not an intermediary.
Potential impact
- An attacker positioned on the network may intercept and decrypt HTTPS traffic.
- An attacker could modify requests or responses in transit, enabling content injection or data manipulation.
- Confidential information (such as authentication tokens, API keys, or user data) can be exposed.
- Application-level security assumptions about TLS-protected channels may no longer hold, enabling follow-on attacks.
General mitigation guidance
Effective mitigation focuses on hardening TLS validation behavior and reducing reliance on IP-literal endpoints for secure connections.
Common defensive patterns include:
- Ensuring TLS client code performs strict certificate chain and hostname verification for all connections, including IP-literal targets.
- Preferring DNS hostnames with certificates bound to those names instead of direct IP addresses for production HTTPS endpoints.
- Centralizing TLS configuration and verification logic so that backend-specific behavior does not silently bypass checks.
- Applying least-privilege principles around network routing and limiting untrusted network paths where sensitive traffic flows.
- Introducing defense-in-depth measures such as application-layer integrity checks for critical messages, so tampering becomes easier to detect.
How teams detect issues like this
Detection strategies typically combine code-level inspection with runtime verification:
- Static analysis and code review: Look for TLS client instantiations using Mbed TLS or wolfSSL backends, especially where verification flags depend on host type or where certificate validation callbacks are incomplete for IP addresses.
- Configuration and policy checks: Enforce coding standards that disallow disabling or conditionally weakening certificate verification, particularly for non-DNS hosts.
- Runtime security testing: Use test environments and proxies to present invalid or mismatched certificates to cpp-httplib clients and confirm that connections fail as expected.
- Automated tooling: Integrate security scanners or linters that flag improper TLS verification patterns or direct IP use on supposedly secure channels.

