CWE-766 Base Incompleto

Critical Data Element Declared Public

This vulnerability occurs when a critical piece of data—like a variable, field, or class member—is mistakenly declared as public when it should be kept private according to the application's…

Definição

What is CWE-766?

This vulnerability occurs when a critical piece of data—like a variable, field, or class member—is mistakenly declared as public when it should be kept private according to the application's security design.
Declaring sensitive data as public breaks fundamental security principles like encapsulation and least privilege. It directly exposes critical information, such as internal state, configuration secrets, or authentication tokens, to any other part of the codebase or, in some languages and contexts, to external actors. This creates a clear and immediate attack surface, making it trivial for an attacker to read or modify data that should be strictly controlled. Beyond the direct security flaw, this practice severely damages code maintainability and security hygiene. It becomes difficult to track how and where this critical data is being used or altered, scattering logic that should be centralized. This "spaghetti code" effect makes identifying the root cause of bugs or vulnerabilities more time-consuming and increases the risk of introducing new security weaknesses during future development or refactoring.
Impacto no mundo real

Real-world CVEs caused by CWE-766

  • variables declared public allow remote read of system properties such as user name and home directory.

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    The following example declares a critical variable public, making it accessible to anyone with access to the object in which it is contained.

  2. 2

    Instead, the critical data should be declared private.

  3. 3

    Even though this example declares the password to be private, there are other possible issues with this implementation, such as the possibility of recovering the password from process memory (CWE-257).

  4. 4

    The following example shows a basic user account class that includes member variables for the username and password as well as a public constructor for the class and a public method to authorize access to the user account.

  5. 5

    However, the member variables username and password are declared public and therefore will allow access and changes to the member variables to anyone with access to the object. These member variables should be declared private as shown below to prevent unauthorized access and changes.

Exemplo de código vulnerável

Vulnerable C++

The following example declares a critical variable public, making it accessible to anyone with access to the object in which it is contained.

Vulnerável C++
public: char* password;
Exemplo de código seguro

Secure C++

Instead, the critical data should be declared private.

Seguro C++
private: char* password;
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-766

  • Implementation Data should be private, static, and final whenever possible. This will assure that your code is protected by instantiating early, preventing access, and preventing tampering.
Sinais de deteção

How to detect CWE-766

Automated Static Analysis High

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-766 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-766?

This vulnerability occurs when a critical piece of data—like a variable, field, or class member—is mistakenly declared as public when it should be kept private according to the application's security design.

Qual a gravidade do CWE-766?

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-766?

MITRE lists the following affected platforms: C++, C#, Java.

Como posso prevenir o CWE-766?

Data should be private, static, and final whenever possible. This will assure that your code is protected by instantiating early, preventing access, and preventing tampering.

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

O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-766 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-766?

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

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.