CVE-2026-141471 — Cesanta Mongoose — CWE-295
Mongoose is an embedded web server and network library. From 7.17 until 7.24, Mongoose's MG_TLS_BUILTIN client in src/tls_builtin.c can accept an attacker-controlled server certificate chain when configured with a single DER CA certificate and processing a peer-provided chain, because mg_tls_verify_cert_signature() can return a negative issuer-key parsing result that callers negate as though verification succeeded. A crafted issuer with the trusted CA subject and public-key bytes but an unparseable RSA encoding can pair with an attacker-self-signed leaf that is not signed by the trusted CA, allowing a redirected client connection to complete a TLS 1.3 handshake and exchange application data without the trusted CA private key. This issue is fixed in 7.24.
Mongoose is an embedded web server and network library. From 7.17 until 7.24, Mongoose's MG_TLS_BUILTIN client in src/tls_builtin.c can accept an attacker-controlled server certificate chain when configured with a single DER CA certificate and processing a peer-provided chain, because mg_tls_verify_cert_signature() can return a negative issuer-key parsing result that callers negate as though verification succeeded. A crafted issuer with the trusted CA subject and public-key bytes but an unparseable RSA encoding can pair with an attacker-self-signed leaf that is not signed by the trusted CA, allowing a redirected client connection to complete a TLS 1.3 handshake and exchange application data without the trusted CA private key. This issue is fixed in 7.24.
🎯 What is this vulnerability?
This vulnerability is a Critical TLS Certificate Verification Bypass in the Mongoose embedded web server library, specifically affecting the MG_TLS_BUILTIN client implementation.
The Technical Flaw:
The core issue lies in the error handling logic of the function mg_tls_verify_cert_signature() within src/tls_builtin.c. When Mongoose is configured to use a single DER-encoded CA certificate for peer verification, it attempts to parse the issuer's public key from the provided certificate chain.
1. Parsing Failure: If an attacker provides a certificate chain where the issuer certificate (which claims to be the trusted CA) contains an unparseable RSA public key encoding (e.g., malformed ASN.1 structure or invalid key bytes), the parsing routine fails.
2. Logic Error: The function mg_tls_verify_cert_signature() returns a negative value to indicate this parsing error.
3. Incorrect Negation: The calling code incorrectly interprets this negative return value. Instead of treating it as a fatal verification failure, the code negates the result (or checks for != 0 in a way that treats the error code as a success flag), effectively concluding that the signature verification succeeded.
4. Bypass: Consequently, the TLS handshake proceeds as if the peer's certificate chain was validly signed by the trusted CA, even though the cryptographic signature check was never actually performed or was impossible to perform due to the malformed key.
CWE-295 (Improper Certificate Validation): The system fails to properly validate the certificate chain, allowing an attacker to present a self-signed leaf certificate that is not signed by the trusted CA, paired with a crafted issuer certificate that triggers the parsing error.
⚡ Attack Chain
1. Discovery & Reconnaissance
- Fingerprinting: The attacker identifies targets running applications that embed Mongoose (common in IoT devices, embedded systems, and lightweight microservices).
- Version Enumeration: Using tools like
nmapwith SSL/TLS scripts or manual probing, the attacker determines the Mongoose version. The vulnerability affects versions 7.17 through 7.23. - Configuration Check: The attacker must confirm that the Mongoose client is configured with
MG_TLS_BUILTINand uses a single DER CA certificate for verification. This is a common configuration in embedded environments to minimize memory footprint. - Attacker has network position to intercept traffic (e.g., same LAN, compromised router, or ARP spoofing).
- Attacker has the public CA certificate (DER format) used by the Mongoose client.
- Attacker generates a malicious certificate chain:
2. Exploitation
The attacker performs a Man-in-the-Middle (MitM) attack. They intercept the TLS connection between the Mongoose client and the legitimate server.Prerequisites:
* Leaf Certificate: Self-signed by the attacker's private key. The Subject must match what the Mongoose client expects (or be ignored if hostname verification is weak/disabled).
* Issuer Certificate: A crafted certificate where:
* The Subject matches the Subject of the trusted CA.
* The Public Key field contains malformed/unparseable RSA key bytes (e.g., truncated ASN.1, invalid modulus length, or garbage data).
* The signature on this issuer certificate is irrelevant because the parser fails before signature verification.
Illustrative PoC Concept (Python/OpenSSL):
# Illustrative only - Actual crafting requires specific ASN.1 manipulation
# 1. Extract CA Subject from trusted_ca.der
# 2. Create a new X509 certificate:
# - Subject: <CA Subject>
# - Issuer: <CA Subject> (Self-signed issuer)
# - Public Key: b'\x00\x01\x02\x03' (Invalid RSA key bytes)
# 3. Sign this issuer cert with attacker's key (signature is ignored due to parse error)
# 4. Create Leaf Cert:
# - Subject: <Expected Hostname>
# - Issuer: <CA Subject>
# - Public Key: Attacker's valid RSA key
# - Signature: Attacker's private key
# 5. Present [Leaf, Issuer] chain to Mongoose clientExploitation Step:
1. Attacker intercepts the TCP connection.
2. Attacker presents the malicious certificate chain during the TLS 1.3 handshake.
3. Mongoose client attempts to verify the chain:
* Parses Issuer Cert → Fails to parse RSA key → mg_tls_verify_cert_signature() returns negative error code.
* Caller negates/checks error code incorrectly → Verification marked as SUCCESS.
4. TLS handshake completes.
5. Attacker and Mongoose client exchange application data over the encrypted channel.
3. Post-Exploitation
🌍 Real World Impact
CVSS 4.0 Vector Analysis:
Practical Consequences:
🛡️ Remediation & Mitigation
1. Upgrade
2. Workarounds (If Immediate Upgrade is Not Possible)
MG_TLS_BUILTIN: If possible, switch to a different TLS backend (e.g., OpenSSL, mbedTLS) that does not have this specific parsing bug.3. Detection
ModSecurity Rule (Illustrative - For Web Servers, Not Directly Applicable to Mongoose Client):
Since Mongoose is an embedded library, WAF rules are not directly applicable. However, if the Mongoose client is behind a reverse proxy, ensure the proxy enforces strict TLS verification.
⚠️ Urgency
Priority: CRITICAL
FOFA Query