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.NOTVALID

This error occurs when a class extends org.apache.struts.action.ActionForm and has a validate method, but does not validate some fields.

Vulnerability and risk

Unvalidated fields is a number-one security issue for web applications. Unvalidated fields can lead to many security vulnerabilities, such as SQL Injections, Cross-Site scripting, and so on.

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

Define the validate method and validate ALL form fields. Integer fields can be checked by size, negativity and being non-zero, for example. String fields need more complicated checks based on the type of information.

Example 1

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

SV.STRUTS.NOTVALID for field declaration on line 19: Struts: Form field 'SV_STRUTS_NOTVALID_Sample_1' 'name' is not validated by 'validate' method.