Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

SV.STRUTS.STATIC

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 {
19 
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