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.XSS.DB

This error is reported when cross-site scripting from the application database is detected. Cross-site scripting vulnerabilities occur when unchecked user input is reflected back to the web interface.

Vulnerability and risk

An XSS or cross-site scripting vulnerability results from using unchecked user input in information used in the web interface. This data can contain arbitrary content such as HTML and SCRIPT tags. If this information is displayed for other users of the system, these scripts can be used to manipulate the user's session, direct them to other web sites, perform "phishing" attacks or run other malicious script content. This vulnerability is common on message boards of web applications where users can post information back to other users. This content must be closely screened to prevent the injection of HTML or SCRIPT tags into the output seen by other users.

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

Cross-site scripting vulnerabilities, in general, can be prevented by validating any and all input from outside the application (user input, file input, system parameters, etc.). Validation should include length and content. Typically only alphanumeric characters are needed (i.e., A-Za-z, 0-9). Any other accepted characters should be escaped. In particular for XSS vulnerabilities, no tags should be allowed in the user input. This validation should be done at each source of data, such as when each parameter is read from the HTTP request. Validation should be done at the server side; client-side validation is not enough to protect against XSS, since users can send raw HTTP packets without the need of a client browser.

Example 1

15     protected void printComment(Connection conn, ServletOutputStream out, String user) throws SQLException, IOException {
16         PreparedStatement pr = conn.prepareStatement("SELECT * FROM comms WHERE user = ?");
17         pr.setString(0, user);
18         String comment = pr.executeQuery().getString("comment");
19         out.println("Comments: " + comment);
20     }

SV.XSS.DB is reported for line 19: 'comment' contains data coming from the database (line 18). On line 19 it is used to render a web page. This means that information previously stored in the database is used unchecked to render a web page; this information may contain arbitrary HTML and JavaScript content. To exploit this vulnerability, a database injection vulnerability must also exist.

Related checkers

Extension

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