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.PATH.INJ

This error occurs when unvalidated user data is used as part of a file name which is created or written.

Vulnerability and risk

In conjunction with data injection, this situation can allow injection of data into arbitrary files, for example, /etc/passwd. On its own, file injection can be used to create files and directories with which the attacker's chosen names can be used in future attacks. For example, the attacker could force an application to create a file with sensitive information on a world-readable location.

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

Validate all user data for allowable lexical values and size. For example, if usernames have to be part of the directory structure, check them for size and content on alphanumeric characters.

Example 1

16     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
17         String name = req.getParameter("userName");
18         File userDir = new File("userFiles", name);
19         File profile = new File(userDir, "profile");
20         FileOutputStream stream = new FileOutputStream(profile);
21         try {
22             createFileWithSensitiveInformation(stream);
23         } finally {
24             stream.close();
25         }
26     }

SV.PATH.INJ is reported for line 20: 'name' contains data coming from an HTTP request parameter and might be tainted (line 17). This value is used to create file 'profile' on line 19 which is used on line 20 to create a FileOutputStream. This can be used to inject information into an arbitrary file in the server file system.

Extension

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