---
title: "CWE-766: Critical Data Element Declared Public"
url: https://radicalnotion.ai/cwe/cwe-766
type: cwe
description: "The product declares a critical variable, field, or member to be public when intended security policy requires it to be private."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-766: Critical Data Element Declared Public

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

The product declares a critical variable, field, or member to be public when intended security policy requires it to be private.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** C++ (Undetermined), C# (Undetermined), Java (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality | Read Application Data, Modify Application Data | Making a critical variable public allows anyone with access to the object in which the variable is contained to alter or read the value. |
| Other | Reduce Maintainability | This issue makes it more difficult to maintain the product, which indirectly affects security by making it more difficult or time-consuming to find and/or fix vulnerabilities. |

## Potential mitigations

### 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.

## Detection methods

### Automated Static Analysis

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.)

Effectiveness: High

## Demonstrative examples

### Example 1

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

Bad code:

```c++
public: char* password;
```

Good code:

```c++
private: char* password;
```

### Example 2

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.

Bad code:

```c++
#define MAX_PASSWORD_LENGTH 15
#define MAX_USERNAME_LENGTH 15

class UserAccount
{
    public:
        UserAccount(char *username, char *password)
        {
            if ((strlen(username) > MAX_USERNAME_LENGTH) ||
            (strlen(password) > MAX_PASSWORD_LENGTH)) {
                ExitError("Invalid username or password");
            }
            strcpy(this->username, username);
            strcpy(this->password, password);
        }

    int authorizeAccess(char *username, char *password)
    {
        if ((strlen(username) > MAX_USERNAME_LENGTH) ||
        (strlen(password) > MAX_PASSWORD_LENGTH)) {
            ExitError("Invalid username or password");
        }
        // if the username and password in the input parameters are equal to

        // the username and password of this account class then authorize access
        if (strcmp(this->username, username) ||
        strcmp(this->password, password))
            return 0;

        // otherwise do not authorize access
        else
            return 1;
    }

    char username[MAX_USERNAME_LENGTH+1];
    char password[MAX_PASSWORD_LENGTH+1];
};
```

Good code:

```c++
class UserAccount
{
public:
    ...

private:
    char username[MAX_USERNAME_LENGTH+1];
    char password[MAX_PASSWORD_LENGTH+1];
};
```

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.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2010-3860 | variables declared public allow remote read of system properties such as user name and home directory. |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-732](https://radicalnotion.ai/cwe/cwe-732) | Incorrect Permission Assignment for Critical Resource |
| Parent | [CWE-1061](https://radicalnotion.ai/cwe/cwe-1061) | Insufficient Encapsulation |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Failure to protect stored data from modification | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Declare data members as private and provide accessible wrapper methods | OBJ01-J | - |
| Software Fault Patterns | Unexpected access points | SFP28 | - |
| OMG ASCMM | - | ASCMM-MNT-15 | - |

## Frequently asked questions

### What is CWE-766?

The product declares a critical variable, field, or member to be public when intended security policy requires it to be private.

### How do you prevent 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.

### How is CWE-766 detected?

Automated Static Analysis: 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.)

### What are the consequences of CWE-766?

Exploiting CWE-766 can lead to: Read Application Data, Modify Application Data, Reduce Maintainability.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/766.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-766). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
