This vulnerability occurs when a public method directly returns a reference to a private, internal data structure. Because the reference is live, external callers can bypass intended controls and modify the data unexpectedly, corrupting the application's state.
This flaw breaks a core principle of encapsulation in object-oriented design. The private data structure—like an array, collection, or object—is meant to be managed solely by the class's own methods. By handing out a direct reference, you allow external code to add, remove, or alter elements without validation, leading to data corruption, security bypasses, or crashes that are difficult to debug. The fix is to return either a copy of the data (defensive copying) or an immutable view, ensuring the internal state remains protected. Identifying every instance of this pattern across a large codebase can be tedious. While SAST tools can flag the risky return statements, Plexicus uses AI to analyze the context and automatically suggest the correct remediation—such as implementing `Collections.unmodifiableList()` in Java or a slice copy in Go—saving developers hours of manual refactoring and ensuring consistent fixes.
Impact: Modify Application Data
The contents of the data structure can be modified from outside the intended scope.
javac++
// return reference to private array* int & fv () { return colorValue; } // return reference to private integer };
c++
c++