This error is reported when a class extends org.apache.struts.action.ActionForm and defines a static field which is not final.

Vulnerability and risk

Non-final static fields can create race-conditions, because can be changed by different instances of the form at the same time, or between time of check and time of use (TOCTOU).

Klocwork security vulnerability (SV) checkers identify calls that create potentially dangerous data; these calls are considered unsafe sources. An unsafe source can be any data provided by the user, since the user could be an attacker or has the potential for introducing human error.

Mitigation and prevention

Avoid using non-final static fields. Make fields final or non-static. If you make a field final, make sure the object it contains is immutable. If the value of this field depends on a request, it should not be static, because it will be possible to create some exposure by creating a malicious form. If it does not depend on a request, it should be made final.

Example 1

18 public class SV_STRUTS_STATIC_Sample_1 extends ActionForm {
20     private String birthdayString;
21     protected Date birthday;
22     private static SimpleDateFormat dateConvertor;
23     public ActionErrors validate(ActionMapping map,
24                                  HttpServletRequest req) {
25         ActionErrors errors = new ActionErrors();
26         if (dateConvertor == null) {
27             dateConvertor = new SimpleDateFormat(req
28                     .getParameter("date.format"));
29         }
30         try {
31             birthday = dateConvertor.parse(birthdayString);
32         } catch (ParseException e) {
33             errors.add(ActionErrors.GLOBAL_MESSAGE,
34                        new ActionMessage("Bad date"));
35         }
36         return super.validate(map, req);
37     }
38     public String getBirthday() {
39         return birthdayString;
40     }
41     public void setBirthday(String birthday) {
42         this.birthdayString = birthday;
43     }
44 }

SV.STRUTS.STATIC is reported for field declaration on line 22: Struts: Static form field variables 'dateConvertor' should be final