CWE
Home > CWE List > CWE- Individual Dictionary Definition (1.1)  
Search by ID:

CWE-80: Failure to Sanitize Script-Related HTML Tags in a Web Page (Basic XSS)

Individual Definition in a New Window
Failure to Sanitize Script-Related HTML Tags in a Web Page (Basic XSS)
Status: Incomplete
Weakness ID: 80 (Weakness Variant)
Description
Summary

The web application fails to adequately filter user-controlled input and sanitize its own output for any special characters, such as "<", ">", and "&".

Extended Description

This may allow such characters to be treated as control characters, which are executed client-side in the context of the user's session. Although this can be classified as an injection problem, the more pertinent issue is the failure to convert such special characters to respective context-appropriate entities before displaying them to the user.

Likelihood of Exploit

High to Very High

Weakness Ordinalities
Primary (where the weakness exists independent of other weaknesses)
Causal Nature
Explicit (an explicit weakness resulting from behavior of the developer)
Potential Mitigations

Carefully check each input parameter against a rigorous positive specification (white list) defining the specific characters and format allowed. All input should be sanitized, not just parameters that the user is supposed to specify, but all data in the request, including hidden fields, cookies, headers, the URL itself, and so forth. A common mistake that leads to continuing XSS vulnerabilities is to validate only fields that are expected to be redisplayed by the site. We often encounter data from the request that is reflected by the application server or the application that the development team did not anticipate. Also, a field that is not currently reflected may be used by a future developer. Therefore, validating ALL parts of the HTTP request is recommended.

This involves "HTML Entity Encoding" all non-alphanumeric characters from data that was received from the user and is now being written to the request.

With Struts, you should write all data from form beans with the bean's filter attribute set to true.

Additionally, to help mitigate XSS attacks against the user's session cookie, set the session cookie to be HttpOnly. In browsers that support the HttpOnly feature (such as Internet Explorer), this attribute prevents the user's session cookie from being accessed by client-side scripts, including scripts inserted due to a XSS attack.

Demonstrative Examples

In the following example, a guestbook comment isn't properly sanitized for script-related tags before being displayed in a client browser.

Java Example:
<% for (Iterator i = guestbook.iterator(); i.hasNext(); ) {
Entry e = (Entry) i.next(); %>
<p>Entry #<%= e.getId() %></p>
<p><%= e.getText() %></p>
<%
} %>
Observed Examples
ReferenceDescription
XSS in parameter in a link.
XSS in web-based email product via attachment filenames.
HTML injection in posted message.
XSS not quoted in error page.
Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfWeakness BaseWeakness BaseWeakness Base79Failure to Sanitize Directives in a Web Page (aka 'Cross-site scripting' (XSS))
Development Concepts (primary)699
Research Concepts (primary)1000
MemberOfViewView630Weaknesses Examined by SAMATE
Weaknesses Examined by SAMATE (primary)630
Taxonomy Mappings
Mapped Taxonomy NameMapped Node Name
PLOVERBasic XSS
Applicable Platforms
Languages
All
Time of Introduction
* Implementation
Related Attack Patterns
CAPEC-ID(CAPEC Version 1.1)Attack Pattern Name
18Embedding Scripts in Nonscript Elements
White Box Definitions

A weakness where the code path has:

1. start statement that accepts input from HTML page

2. end statement that publishes a data item to HTML where

a. the input is part of the data item and

b. the input is undesirable

Where "input is undesirable" is defined through the following scenarios:

1. input not validated

2. input incorrectly validated

Content History
Submissions
PLOVER. (Externally Mined)
Modifications
Sean Eidemiller. Cigital. 2008-07-01. (External)
added/updated demonstrative examples
Eric Dalci. Cigital. 2008-07-01. (External)
updated Time_of_Introduction
KDM Analytics. 2008-08-01. (External)
added/updated white box definitions
CWE Content Team. MITRE. 2008-09-08. (Internal)
updated Relationships, Taxonomy_Mappings, Weakness_Ordinalities
CWE Content Team. MITRE. 2008-10-14. (Internal)
updated Description
Previous Entry Names
* Basic XSS (changed 2008-04-11)
Page Last Updated: November 24, 2008