Struts: Non-private Field in ActionForm Class

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


Demonstrations

The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

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.

public class RegistrationForm extends org.apache.struts.validator.ValidatorForm {


  // variables for registration form
  public String name;
  public String email;
  ...

  public RegistrationForm() {
    super();
  }
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {...}
  ...

}

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.

public class RegistrationForm extends org.apache.struts.validator.ValidatorForm {


  // private variables for registration form
  private String name;
  private String email;
  ...

  public RegistrationForm() {
    super();
  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {...}




  // getter and setter methods for private variables
  ...
}

See Also

Comprehensive Categorization: Exposed Resource

Weaknesses in this category are related to exposed resource.

SFP Secondary Cluster: Unexpected Entry Points

This category identifies Software Fault Patterns (SFPs) within the Unexpected Entry Points cluster.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Weaknesses Introduced During Implementation

This view (slice) lists weaknesses that can be introduced during implementation.

Weaknesses in Software Written in Java

This view (slice) covers issues that are found in Java programs that are not common to all languages.


Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.