Safeguard
Application Security•

CWE-599: Missing Validation of an OpenSSL Certificate

Trusting a certificate without calling SSL_get_verify_result lets a spoofed host pass as a trusted one. What to check in OpenSSL client code.

Safeguard Security Team
2 min read

CWE-599 is about code that uses OpenSSL and trusts a certificate without calling SSL_get_verify_result() to confirm it satisfies all necessary requirements.

A handshake that completes is not the same as a certificate that checked out.

How it happens

A developer wires up a TLS client, gets a connection, and moves on, because data flows. The step that asks "did the certificate actually verify?" is left out.

SSL *ssl = SSL_new(ctx);
SSL_set_fd(ssl, fd);
SSL_connect(ssl);                 /* connected... */
SSL_write(ssl, secret, secret_len);   /* ...but nothing checked the result */

What an attacker gains

The record lists several outcomes.

  • Data exposure: the data read may not be properly secured, and might be viewed by an attacker.
  • Spoofing or redirection: trust afforded to the system may allow a malicious host to be treated as a trusted one.
  • A subtle variant: a malicious host with a valid certificate, just not one for the host you meant to reach, may supply data under the guise of the trusted host.

How to find it

Search OpenSSL client code for connection setup and confirm that a verification result is read after each handshake. Static analysis can flag connections used without a following verify check. Test against a server presenting a self-signed or wrong-host certificate and confirm your code refuses to continue.

How to fix it

MITRE's guidance has two parts.

  • At design time, make sure proper authentication is part of the system design.
  • At implementation time, understand and implement all checks necessary to ensure the identity of the entities in encrypted communications.
if (SSL_connect(ssl) != 1) { /* handle failure */ }
if (SSL_get_verify_result(ssl) != X509_V_OK) {
    SSL_free(ssl);
    return -1;           /* refuse to talk to an unverified peer */
}

Also confirm the certificate matches the host you intended to reach, not just that it chains to a trusted authority.

Quick check

Can a certificate be valid and still be the wrong one? Yes. A malicious host can hold a valid certificate for its own name, so identity checks matter as well as chain validity.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.