CWE-295 Base Rascunho

Improper Certificate Validation

This vulnerability occurs when an application fails to properly verify the authenticity of a digital certificate, or performs the verification incorrectly, allowing untrusted connections to appear…

Definição

What is CWE-295?

This vulnerability occurs when an application fails to properly verify the authenticity of a digital certificate, or performs the verification incorrectly, allowing untrusted connections to appear legitimate.
Digital certificates act like digital passports for servers and services, proving their identity. When an application doesn't rigorously check these certificates—for example, by accepting self-signed certificates, ignoring expiration dates, or not validating the certificate chain back to a trusted root—it can mistakenly connect to a malicious server impersonating a legitimate one. This creates a critical opening for man-in-the-middle (MitM) attacks where attackers can intercept, read, or modify sensitive data in transit. To prevent this, developers must ensure their code enforces strict certificate validation. This means always verifying the certificate's signature chain against a trusted root certificate authority (CA), checking the hostname matches, and ensuring the certificate is valid and not revoked. Relying on default settings is often insufficient; explicit configuration in libraries for TLS/SSL connections is typically required to reject invalid certificates and maintain a secure communication channel.
Vulnerability Diagram CWE-295
Improper Certificate Validation Client verify=false MITM attacker presents fake cert CN: bank.com (not signed) decrypts + relays traffic bank.com real server Disabled or weak cert validation lets an attacker terminate TLS.
Impacto no mundo real

Real-world CVEs caused by CWE-295

  • A Go framework for robotics, drones, and IoT devices skips verification of root CA certificates by default.

  • chain: incorrect "goto" in Apple SSL product bypasses certificate validation, allowing Adversary-in-the-Middle (AITM) attack (Apple "goto fail" bug). CWE-705 (Incorrect Control Flow Scoping) -> CWE-561 (Dead Code) -> CWE-295 (Improper Certificate Validation) -> CWE-393 (Return of Wrong Status Code) -> CWE-300 (Channel Accessible by Non-Endpoint).

  • Chain: router's firmware update procedure uses curl with "-k" (insecure) option that disables certificate validation (CWE-295), allowing adversary-in-the-middle (AITM) compromise with a malicious firmware image (CWE-494).

  • Verification function trusts certificate chains in which the last certificate is self-signed.

  • Web browser uses a TLS-related function incorrectly, preventing it from verifying that a server's certificate is signed by a trusted certification authority (CA)

  • Web browser does not check if any intermediate certificates are revoked.

  • Operating system does not check Certificate Revocation List (CRL) in some cases, allowing spoofing using a revoked certificate.

  • Mobile banking application does not verify hostname, leading to financial loss.

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    This code checks the certificate of a connected peer.

  2. 2

    In this case, because the certificate is self-signed, there was no external authority that could prove the identity of the host. The program could be communicating with a different system that is spoofing the host, e.g. by poisoning the DNS cache or using an Adversary-in-the-Middle (AITM) attack to modify the traffic from server to client.

  3. 3

    The following OpenSSL code obtains a certificate and verifies it.

  4. 4

    Even though the "verify" step returns X509_V_OK, this step does not include checking the Common Name against the name of the host. That is, there is no guarantee that the certificate is for the desired host. The SSL connection could have been established with a malicious host that provided a valid certificate.

  5. 5

    The following OpenSSL code ensures that there is a certificate and allows the use of expired certificates.

Exemplo de código vulnerável

Vulnerable C

This code checks the certificate of a connected peer.

Vulnerável C
if ((cert = SSL_get_peer_certificate(ssl)) && host)
  	foo=SSL_get_verify_result(ssl);
  if ((X509_V_OK==foo) || X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN==foo))
```
// certificate looks good, host can be trusted*
Exemplo de código seguro

Secure pseudo

Seguro pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de verificação de prevenção

How to prevent CWE-295

  • Architecture and Design / Implementation Certificates should be carefully managed and checked to assure that data are encrypted with the intended owner's public key.
  • Implementation If certificate pinning is being used, ensure that all relevant properties of the certificate are fully validated before the certificate is pinned, including the hostname.
Sinais de deteção

How to detect CWE-295

Automated Static Analysis - Binary or Bytecode SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Bytecode Weakness Analysis - including disassembler + source code weakness analysis Binary Weakness Analysis - including disassembler + source code weakness analysis

Manual Static Analysis - Binary or Bytecode SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Binary / Bytecode disassembler - then use manual analysis for vulnerabilities & anomalies

Dynamic Analysis with Automated Results Interpretation SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Web Application Scanner

Dynamic Analysis with Manual Results Interpretation High

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Man-in-the-middle attack tool

Manual Static Analysis - Source Code High

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Focused Manual Spotcheck - Focused manual analysis of source Manual Source Code Review (not inspections)

Automated Static Analysis - Source Code SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-295 e abre um PR de correção em menos de 60 segundos.

O Codex Remedium analisa cada commit, identifica esta fraqueza exata e entrega um pull request pronto para revisão com o patch. Sem tickets. Sem transferências.

Perguntas frequentes

Frequently asked questions

O que é o CWE-295?

This vulnerability occurs when an application fails to properly verify the authenticity of a digital certificate, or performs the verification incorrectly, allowing untrusted connections to appear legitimate.

Qual a gravidade do CWE-295?

A MITRE não publicou uma classificação de probabilidade de exploração para esta fraqueza. Trate-a como impacto médio até o seu modelo de ameaças provar o contrário.

Que linguagens ou plataformas são afetadas pelo CWE-295?

MITRE lists the following affected platforms: Mobile.

Como posso prevenir o CWE-295?

Certificates should be carefully managed and checked to assure that data are encrypted with the intended owner's public key. If certificate pinning is being used, ensure that all relevant properties of the certificate are fully validated before the certificate is pinned, including the hostname.

Como é que o Plexicus deteta e corrige o CWE-295?

O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-295 em cada commit. Quando é encontrada uma correspondência, o nosso agente Codex Remedium abre um PR de correção com o código corrigido, testes e um resumo de uma linha para o revisor.

Onde posso saber mais sobre o CWE-295?

A MITRE publica a definição canónica em https://cwe.mitre.org/data/definitions/295.html. Pode também consultar a documentação da OWASP e do NIST para orientações adjacentes.

Fraquezas relacionadas

Weaknesses related to CWE-295

CWE-287 Pai

Improper Authentication

Improper Authentication occurs when a system fails to properly verify a user's claimed identity, allowing access without sufficient proof…

CWE-1390 Irmão

Weak Authentication

This vulnerability occurs when a system's login or identity verification process is too easy to bypass or fool. While it attempts to check…

CWE-290 Irmão

Authentication Bypass by Spoofing

This weakness occurs when an application's authentication system can be tricked into accepting forged or manipulated credentials, allowing…

CWE-294 Irmão

Authentication Bypass by Capture-replay

This vulnerability occurs when an attacker can intercept and record legitimate authentication traffic, then replay it later to gain…

CWE-306 Irmão

Missing Authentication for Critical Function

This vulnerability occurs when a software feature that performs a sensitive action or uses significant system resources does not verify…

CWE-307 Irmão

Improper Restriction of Excessive Authentication Attempts

This vulnerability occurs when an application fails to properly limit how many times someone can attempt to log in or verify their…

CWE-521 Irmão

Weak Password Requirements

This vulnerability occurs when an application fails to enforce strong password policies, making user accounts easier to compromise through…

CWE-522 Irmão

Insufficiently Protected Credentials

This vulnerability occurs when an application handles sensitive credentials like passwords or API keys in an insecure way, making them…

CWE-640 Irmão

Weak Password Recovery Mechanism for Forgotten Password

This vulnerability occurs when an application's password reset or recovery feature is poorly designed or implemented, allowing attackers…

Pronto quando você estiver

Pare de pagar por desenvolvedor.
Comece a fechar o ciclo.

O Plexicus é o ASPM nativo de IA que verifica, filtra, corrige, pentesta e explica — de forma autónoma. Programadores ilimitados, repos ilimitados, ações de IA de utilização justa. Nível gratuito real, €269/mo anual quando estiver pronto.