Struts: Non-private Field in ActionForm Class

Draft Variant
Structure: Simple
Description

An ActionForm class contains a field that has not been declared private, which can be accessed without using a setter or getter.

Common Consequences 1
Scope: IntegrityConfidentiality

Impact: Modify Application DataRead Application Data

Potential Mitigations 1
Phase: Implementation
Make all fields private. Use getter to get the value of the field. Setter should be used only by the framework; setting an action form field from other actions is bad practice and should be avoided.
Demonstrative Examples 1
In the following Java example the class RegistrationForm is a Struts framework ActionForm Bean that will maintain user input data from a registration webpage for a online business site. The user will enter registration data and through the Struts framework the RegistrationForm bean will maintain the user data.

Code Example:

Bad
Java
java
However, within the RegistrationForm the member variables for the registration form input data are declared public not private. All member variables within a Struts framework ActionForm class must be declared private to prevent the member variables from being modified without using the getter and setter methods. The following example shows the member variables being declared private and getter and setter methods declared for accessing the member variables.

Code Example:

Good
Java
java
Applicable Platforms
Languages:
Java : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • Software Fault Patterns