CWE-495: Private Data Structure Returned From A Public Method
The product has a method that is declared public, but returns a reference to a private data structure, which could then be modified in unexpected ways.
Last updated
Overview
CWE-495 (Private Data Structure Returned From A Public Method) is a variant-level software weakness catalogued by MITRE in the Common Weakness Enumeration (CWE). It describes a recurring type of mistake that can lead to exploitable security vulnerabilities.
Real-world CVEs
1 recorded CVEs are caused by CWE-495 (Private Data Structure Returned From A Public Method). The highest-severity and most recent are shown first. 0 new CWE-495 CVEs have been recorded so far in 2026 (1 in 2025).
Common consequences
What can happen when CWE-495 is exploited.
Modify Application Data
Affects: Integrity
The contents of the data structure can be modified from outside the intended scope.
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-495, grouped by where in the lifecycle they apply.
Declare the method private.
Clone the member data and keep an unmodified version of the data private to the object.
Use public setter methods that govern how a private member can be modified.
How to detect it
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
Code examples
Illustrative examples from MITRE showing how the weakness appears in code.
Here, a public method in a Java class returns a reference to a private array. Given that arrays in Java are mutable, any modifications made to the returned reference would be reflected in the original private array.
Vulnerable example
private String[] colors;In this example, the Color class defines functions that return non-const references to private members (an array type and an integer type), which are then arbitrarily altered from outside the control of the class.
Vulnerable example
class ColorTerminology & mappings
Mapped taxonomies
- 7 Pernicious Kingdoms: Private Array-Typed Field Returned From A Public Method
- Software Fault Patterns: Exposed Data (SFP23)
Frequently asked questions
Common questions about CWE-495.
- What is CWE-495?
- The product has a method that is declared public, but returns a reference to a private data structure, which could then be modified in unexpected ways.
- What CVEs are caused by CWE-495?
- 1 recorded CVEs are attributed to CWE-495, including CVE-2025-29868.
- How do you prevent CWE-495?
- Declare the method private.
- How is CWE-495 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-495?
- Exploiting CWE-495 can lead to: Modify Application Data.
- Is CWE-495 actively exploited?
- 1 recorded CVEs are caused by CWE-495; none are currently in CISA's KEV catalog of actively exploited flaws.
References
- MITRE CWE definition (CWE-495) (opens in a new tab)
- CWE-495 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.
Stay ahead of CWE-495
Get alerted the moment a new CWE-495 vulnerability affects your stack, with AI-written analysis, severity context, and remediation guidance.