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

This error is detected when unchecked user input is used as an XPath expression.

Mitigation and prevention

The prevention of XPath injection attacks can be achieved by validating any and all input from outside the application (user input, file input, system parameters, etc.). The best way to filter user data is with a blacklist regular expression that includes only the type of characters that are allowed; all other characters should be escaped.

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.

Example 1

24  protected void doGet(HttpServletRequest httpServletRequest,
25          HttpServletResponse httpServletResponse) throws ServletException, IOException {
26     super.doGet(httpServletRequest, httpServletResponse);
27     String userName = httpServletRequest.getParameter("user.name");
28     String userDescr = httpServletRequest.getParameter("user.descr");
29     CompiledExpression compiledExpression = JXPathContext.compile("string(//user[name/text()='" + userName + "']/account/text())");
30     compiledExpression.setValue(context, userDescr);
31     httpServletResponse.getOutputStream().println("User info updated");
32  }

SV.XPATH is reported for the snippet twice:

  • user data is stored in 'userName' on line 27 and later is used for the construction of an XPath expression on line 29
  • user data is stored in 'userDescr' on line 28 and later is passed to 'setValue(...)' on line 30

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.