Critical Variable Declared Public |
Weakness ID: 766 (Weakness Variant) | Status: Incomplete |
Description Summary
Scope | Effect |
---|---|
Integrity Confidentiality | Making a critical variable public allows anyone with access to the object in which the variable is contained to alter or read the value. |
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.
Instead, the critical data should be declared private.
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).
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.
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.
Phase: 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. |
Nature | Type | ID | Name | View(s) this relationship pertains to![]() |
---|---|---|---|---|
ChildOf | ![]() | 485 | Insufficient Encapsulation | Development Concepts (primary)699 Research Concepts1000 |
ChildOf | ![]() | 668 | Exposure of Resource to Wrong Sphere | Research Concepts (primary)1000 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
CLASP | Failure to protect stored data from modification |