Mongoose TLS Client Accepts Forged Certificates (CVE-2026-141471)
Cesanta Mongoose 7.17 to 7.23 treats a failed issuer-key parse as success, so a crafted certificate chain can impersonate the server. Fixed in 7.24.
TL;DR
- Mongoose's built-in TLS client treated a negative result from the issuer-signature verifier as success. A crafted certificate chain could therefore pass verification. Cesanta fixed it in 7.24.
- Mongoose 7.17 through 7.23 is affected when built with the built-in TLS stack and configured with a single DER CA certificate. The client must also be reachable by an attacker who can redirect its connection.
- The CVE record rates it CVSS v4.0 9.1 Critical (CWE-295). The repository advisory labels it Moderate. No public exploit and no exploitation are reported, and it is not in CISA KEV as of 2026-12-02.
- Upgrade to 7.24 or later. If you cannot, switch the client to the mbedTLS or OpenSSL backend and pin the server certificate. See "How do I fix it?".
Am I affected?
You are exposed when all of these conditions hold:
- Mongoose 7.17 through 7.23 is in the build.
- The build uses the built-in TLS stack,
MG_TLS_BUILTIN. - The client verifies the server with a single DER CA certificate in
mg_tls_opts.ca. - The client accepts a peer-provided certificate chain.
- An attacker can redirect the client's connection, for example through DNS, ARP or a compromised router.
A client that uses a CA bundle, mbedTLS or OpenSSL does not run the vulnerable code path. A server that verifies client certificates is also outside this CVE, which the advisory scopes to the client role.
| Branch | Affected versions | Fixed version |
|---|---|---|
| 7.17 through 7.23 | 7.17, 7.18, 7.19, 7.20, 7.21, 7.22, 7.23 | 7.24 or later |
| 7.16 and earlier | None for this CVE | Not affected |
| 7.24 and later | None | Not affected |
Check the Mongoose version in the source tree:
grep -n "MONGOOSE_VERSION" mongoose.h
Check which TLS backend the build selects:
grep -n "MG_TLS" mongoose_config.h
MG_TLS_BUILTIN selects the vulnerable stack. MG_TLS_MBED and MG_TLS_OPENSSL select the alternative backends.
Check where the client sets its CA:
grep -R -n "\.ca[[:space:]]*=" src include examples
A single DER buffer assigned to ca with ca_len is the configuration the advisory describes. A CA bundle uses ca_bundle instead.
How do I fix it?
Upgrade to 7.24 or later and rebuild. The fix is in the library source, so a header-only update is not enough.
- Update the Mongoose source to 7.24:
git submodule update --remote
# or download the 7.24 release and replace the vendored copy
- Rebuild the application so the new
mongoose.candmongoose.hare compiled in. - Confirm the version with the command in "Am I affected?".
- Re-run the TLS connection test against a known server and confirm the handshake succeeds.
If you cannot upgrade, use one of these workarounds:
- Build with mbedTLS or OpenSSL instead of the built-in stack. Set
MG_TLS=MBEDTLSorMG_TLS=OPENSSLin the build configuration and rebuild. - Pin the server's certificate or public key in the application, and reject any chain whose leaf does not match the pinned value.
- Keep the client off untrusted networks until the upgrade is possible.
The backend switch removes the vulnerable verifier. Certificate pinning adds an independent check in front of it. Neither workaround repairs the return-value bug, so upgrade when you can.
What is the root cause?
mg_tls_verify_cert_signature() returns an int, and one failure path returns -1. The caller negates the result, so -1 becomes false and the caller treats the failed verification as a pass.
// src/tls_builtin.c, v7.23
static int mg_tls_verify_cert_signature(const struct mg_tls_cert *cert,
const struct mg_tls_cert *issuer) {
if (issuer->is_ec_pubkey) {
/* ... */
} else {
const uint8_t *n;
/* ... */
if (mg_der_next(&seq, &modulus) <= 0 || modulus.type != 2 ||
modulus.len == 0 || mg_der_next(&seq, &exponent) <= 0 ||
exponent.type != 2 || exponent.len == 0) {
return -1; // issuer key did not parse
}
/* ... */
}
}
The caller uses the result in a boolean condition:
// src/tls_builtin.c, v7.23
if (!ci->is_ca || !mg_tls_verify_cert_signature(ci - 1, ci)) {
mg_error(c, "failed to verify certificate chain %s", ci->is_ca ? "" : "(not a true CA)");
return -1;
}
!(-1) evaluates to 0, so the condition is false and the error branch is skipped. The chain is accepted. The same pattern appears at the two other call sites, including the single-CA path.
The verifier also returned the raw result of mg_p256_verify() and mg_p384_verify() in the elliptic-curve branch. Those functions can return a negative value, which the caller again treats as truthy. The fix makes every failure return false and every success require an exact 1.
How is it exploited?
- The attacker positions itself on the path between the Mongoose client and the server, or controls the name resolution the client uses.
- The attacker builds a fake issuer certificate. It copies the trusted CA's subject and public-key bytes, but its RSA encoding is malformed.
- The attacker self-signs a leaf certificate with its own key. The leaf is not signed by the trusted CA.
- The client receives the fake issuer and the leaf as the peer chain.
mg_tls_verify_cert_signature()fails to parse the issuer's RSA key and returns-1.- The caller negates
-1, skips the error, and completes the TLS 1.3 handshake. - The client sends its request to the attacker and accepts the attacker's response.
The repository advisory describes a loopback TLS 1.3 test that completed the handshake and exchanged a harmless HTTP request and response. No public exploit code is linked.
How does the attack flow?
A parse failure inside the verifier becomes a pass at the caller, so a chain the trusted CA never signed completes the handshake.
client connection"] --> B["Fake issuer copies the
trusted CA subject and key"] B --> C["Leaf is self-signed
by the attacker"] C --> D["Issuer RSA key
fails to parse"] D --> E["Verifier returns -1"] E --> F["Caller negates -1
and skips the error"] F --> G["TLS 1.3 handshake
completes with the attacker"]
What can an attacker do?
An attacker who completes the handshake can impersonate the server the client intended to reach. The client sends its requests to the attacker and accepts the attacker's responses.
The impact includes:
- Reading the application data the client sends, including credentials, commands and telemetry.
- Returning forged responses, including configuration, firmware metadata or command output.
- Redirecting the client's session to a host the attacker controls.
The conditions are:
- The client uses the built-in TLS stack.
- The client trusts a single DER CA certificate.
- The attacker can redirect the connection.
- The application exchanges data over the connection after the handshake.
The advisory does not show host compromise or code execution. The demonstrated payload was a harmless HTTP request and response. The exposure is the confidentiality and integrity of the TLS session, and what the application does with the attacker's responses.
Why does the fix work?
The patch changes the verifier's return type to bool and makes every error path return false. It also requires the elliptic-curve verify functions to return exactly 1.
--- a/src/tls_builtin.c
+++ b/src/tls_builtin.c
@@
-static int mg_tls_verify_cert_signature(const struct mg_tls_cert *cert,
+static bool mg_tls_verify_cert_signature(const struct mg_tls_cert *cert,
const struct mg_tls_cert *issuer) {
@@
if (issuer->pubkey.len == 64) {
unpadlen(sig, &a, &b, 32);
return mg_p256_verify((uint8_t *) issuer->pubkey.buf, cert->tbshash,
- cert->tbshashsz, sig);
+ cert->tbshashsz, sig) == 1;
@@
- return -1;
+ MG_ERROR(("failed to parse RSA issuer public key"));
+ return false;
@@
- return 0;
+ MG_ERROR(("failed to process RSA cert sig"));
+ return false;
A bool cannot carry -1, and the caller's negation now sees true only for an exact success. The patch changes both the amalgamated mongoose.c and src/tls_builtin.c, so a build that compiles either copy gets the fix. It covers the EC and RSA branches and all three call sites in the chain verification.
The fix is complete for this bug. It does not add hostname verification or a new trust model, so keep the application's own checks.
How do I check if I was compromised?
No indicators of compromise are published for this CVE. A successful bypass produces a normal-looking TLS session, so network logs may show only a connection to an unexpected address.
Look for connections to hosts the client does not normally use:
grep -R -n "mg_connect\|mg_http_connect\|mg_mqtt_connect" src
Review the destination addresses in the device's connection log or packet capture. A client that talks to a fixed server should not open a session to a new address after a DNS change.
Check the certificate chain the client accepted if the application logs it. A chain whose issuer has the trusted CA's subject but a different public key is a lead.
Check whether the build ever used the vulnerable backend and a single DER CA:
grep -R -n "MG_TLS_BUILTIN\|MG_TLS_MBED\|MG_TLS_OPENSSL" .
grep -R -n "\.ca[[:space:]]*=" src include
A failed attempt may leave no trace. Treat an unexpected destination or an unexpected certificate as a lead, not as proof.
Timeline
- 2026-11-09: The fix commit changes the verifier to a boolean and enforces consistent return values.
- 2026-11-18: Mongoose 7.24 is released with the fix.
- 2026-12-01: CVE-2026-141471 is published at 20:29 UTC.
FAQ
Does this affect the npm mongoose package?
No. This CVE is in Cesanta Mongoose, the embedded C networking library. The npm package named mongoose is a MongoDB object mapper and is a different product.
Is every Mongoose build affected? No. The bug is in the built-in TLS client. Builds with mbedTLS or OpenSSL, and builds that do not verify a server certificate, are outside this CVE.
Do I need a CA bundle to trigger it? No. The advisory describes a single DER CA certificate. A bundle takes a different code path, which the advisory does not list as affected.
Does the attacker need the CA private key? No. The fake issuer copies the CA's public key bytes but uses a malformed RSA encoding. The leaf is signed by the attacker's own key.
Is the latest release fixed? Yes. 7.24, released on 2026-11-18, contains the fix. Any later release includes it.
Can a server be attacked this way? The advisory scopes the issue to the client role. A server that verifies client certificates should still upgrade, but the demonstrated chain is a client accepting a server certificate.
References
- CVE-2026-141471 record, https://www.cve.org/CVERecord?id=CVE-2026-141471 (checked December 2, 2026)
- Mongoose security advisory, GHSA-wv74-vfp5-x4cp, https://github.com/cesanta/mongoose/security/advisories/GHSA-wv74-vfp5-x4cp (checked December 2, 2026)
- Mongoose fix commit, https://github.com/cesanta/mongoose/commit/ca5ca3403c08c93f71b833ee24985345aff58dfd (checked December 2, 2026)
- Mongoose 7.24 release, https://github.com/cesanta/mongoose/releases/tag/7.24 (checked December 2, 2026)
- Mongoose source at v7.23, TLS verifier, https://github.com/cesanta/mongoose/blob/7.23/src/tls_builtin.c (checked December 2, 2026)
- Mongoose source at 7.24, TLS verifier, https://github.com/cesanta/mongoose/blob/7.24/src/tls_builtin.c (checked December 2, 2026)
- Mongoose project site, https://mongoose.ws/ (checked December 2, 2026)
- Mongoose repository, https://github.com/cesanta/mongoose (checked December 2, 2026)
- CISA Known Exploited Vulnerabilities catalog, https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked December 2, 2026)
Keep reading
