CWE-767: Access to Critical Private Variable via Public Method
The product defines a public method that reads or modifies a private variable.
Last updated
Overview
If an attacker modifies the variable to contain unexpected values, this could violate assumptions from other parts of the code. Additionally, if an attacker can read the private variable, it may expose sensitive information or make it easier to launch further attacks.
Real-world CVEs
4 recorded CVEs are caused by CWE-767 (Access to Critical Private Variable via Public Method). The highest-severity and most recent are shown first.
Common consequences
What can happen when CWE-767 is exploited.
Modify Application Data, Other
Affects: Integrity, Other
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
Applies to
Languages
How to prevent it
Practical mitigations for CWE-767, grouped by where in the lifecycle they apply.
Use class accessor and mutator methods appropriately. Perform validation when accepting data from a public method that is intended to modify a critical private variable. Also be sure that appropriate access controls are being applied when a public method interfaces with critical data.
Code examples
MITRE examples of the weakness in code.
The following example declares a critical variable to be private, and then allows the variable to be modified by public methods.
Vulnerable example
private: float price;
price = newPrice;The following example could be used to implement a user forum where a single user (UID) can switch between multiple profiles (PID).
Vulnerable example
public class Client {
private int UID;
PID = getDefaultProfileID();
UID = ID;The programmer implemented setPID with the intention of modifying the PID variable, but due to a typo. accidentally specified the critical variable UID instead. If the program allows profile IDs to be between 1 and 10, but a UID of 1 means the user is treated as an admin, then a user could gain administrative privileges as a result of this typo.
Terminology & mappings
Mapped taxonomies
- CLASP: Failure to protect stored data from modification
- Software Fault Patterns: Exposed Data (SFP23)
- SEI CERT Perl Coding Standard: Do not access private variables or subroutines in other packages (OOP31-PL) — Imprecise fit
Frequently asked questions
Common questions about CWE-767.
- What is CWE-767?
- The product defines a public method that reads or modifies a private variable.
- What CVEs are caused by CWE-767?
- 4 recorded CVEs are attributed to CWE-767, including CVE-2024-36463, CVE-2020-26868 and CVE-2016-8380.
- How do you prevent CWE-767?
- Use class accessor and mutator methods appropriately. Perform validation when accepting data from a public method that is intended to modify a critical private variable. Also be sure that appropriate access controls are being applied when a public method interfaces with critical data.
- What are the consequences of CWE-767?
- Exploiting CWE-767 can lead to: Modify Application Data, Other.
- Is CWE-767 actively exploited?
- 4 recorded CVEs are caused by CWE-767; none are currently in CISA's KEV catalog of actively exploited flaws.
References
- MITRE CWE definition (CWE-767) (opens in a new tab)
- CWE-767 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Track CWE-767 CVEs
Get an alert when a new CWE-767 CVE affects your products, with AI-written analysis and remediation steps.