CWE
Home > CWE List > VIEW SLICE: CWE-635: Weaknesses Used by NVD (Draft 9)   View the CWE List

VIEW SLICE: CWE-635: Weaknesses Used by NVD (Draft 9)

Weaknesses Used by NVD
View ID
Status: Draft

635 (View)

ObjectiveCWE nodes in this view (slice) are used by NIST to categorize vulnerabilities within NVD.
View Data
CWEs in this viewTotal CWEs
Total19out of695
Views0out of14
Categories6out of64
Weaknesses12out of605
Compound_Elements1out of12
View Components
View Components
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
Code Injection
Weakness ID
Status: Draft

94 (Weakness Class)

Description

Summary

The product does not sufficiently filter code (control-plane) syntax from user-controlled input (data plane) when that input is used within code that the product generates.

Potential Mitigations

Implementation: Utilize an appropriate mix of whitelist and blacklist parsing to filter non-relevant code syntax from all input that should not contain code.

Run time: Run time policy enforcement may be used in a whitelist fashion to prevent execution of any non-sanctioned code.

Assign permissions to the software system that prevent the user from accessing/opening privileged files.

Research Gaps

Many of these weaknesses are under-studied, and terminology is not sufficiently precise.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class74Failure to Sanitize Data into a Different Plane (aka 'Injection')
ChildOfWeakness ClassWeakness ClassWeakness Class691Insufficient Control Flow Management
ChildOfViewView635
ParentOfWeakness BaseWeakness BaseWeakness Base621Variable Extraction Error
ParentOfWeakness BaseWeakness BaseWeakness Base627Dynamic Variable Evaluation
ParentOfWeakness BaseWeakness BaseWeakness Base95Insufficient Control of Directives in Dynamically Evaluated Code (aka 'Eval Injection')
ParentOfWeakness BaseWeakness BaseWeakness Base96Insufficient Control of Directives in Statically Saved Code (Static Code Injection)
ParentOfCompound Element: CompositeCompound Element: Composite98Insufficient Control of Filename for Include/Require Statement in PHP Program (aka 'PHP File Inclusion')
Source Taxonomies

PLOVER - (CODE) Code Evaluation and Injection

Applicable Platforms

All

Related Attack Patterns
CAPEC-IDAttack Pattern Name
35Leverage Executable Code in Nonexecutable Files
77Manipulating User-Controlled Variables
Configuration
Category ID
Status: Draft

16 (Category)

Description

Summary

Weaknesses in this category are typically introduced during the configuration of the software.

Relationships
NatureTypeIDName
ChildOfCategoryCategory1Location
ChildOfViewView635
Credentials Management
Category ID
Status: Draft

255 (Category)

Description

Summary

Weaknesses in this category are related to the management of credentials.

Relationships
NatureTypeIDName
ChildOfCategoryCategory254Security Features
ChildOfViewView635
ParentOfWeakness VariantWeakness VariantWeakness Variant258Empty Password in Configuration File
ParentOfWeakness BaseWeakness BaseWeakness Base259Hard-Coded Password
ParentOfWeakness VariantWeakness VariantWeakness Variant261Weak Cryptography for Passwords
ParentOfWeakness VariantWeakness VariantWeakness Variant262Not Using Password Aging
ParentOfWeakness BaseWeakness BaseWeakness Base263Password Aging with Long Expiration
ParentOfWeakness BaseWeakness BaseWeakness Base521Weak Password Requirements
ParentOfWeakness BaseWeakness BaseWeakness Base522Insufficiently Protected Credentials
ParentOfWeakness VariantWeakness VariantWeakness Variant549Missing Password Field Masking
ParentOfWeakness VariantWeakness VariantWeakness Variant620Unverified Password Change
ParentOfWeakness BaseWeakness BaseWeakness Base640Weak Password Recovery Mechanism
Applicable Platforms

All

Cross-Site Request Forgery (CSRF)
Compound Element ID
Status: Incomplete

352 (Compound Element Variant: Composite)

Description

Summary

The web product does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request. Note: CSRF is multi-channel: 1. Attacker-to-victim (injection; external or internal channel) 2. Victim-to-server (activation; internal channel)

Alternate Terms

Session Riding

Cross Site Reference Forgery

XSRF

Observed Examples
ReferenceDescription
CVE-2004-1703
CVE-2004-1995
CVE-2004-1967
CVE-2004-1842
CVE-2005-1947
CVE-2005-2059
CVE-2005-1674CSRF
Context Notes

Could be resultant from XSS, although XSS is not necessarily required.

References

Peter W. "Cross-Site Request Forgeries (Re: The Dangers of Allowing Users to Post Images)". Bugtraq. <http://marc.info/?l=bugtraq&m=99263135911884&w=2>.

Robert Auger. "CSRF - The Cross-Site Request Forgery (CSRF/XSRF) FAQ". <http://www.cgisecurity.com/articles/csrf-faq.shtml>.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class345Insufficient Verification of Data Authenticity
RequiresWeakness BaseWeakness BaseWeakness Base346Origin Validation Error
RequiresWeakness BaseWeakness BaseWeakness Base441Unintended Proxy/Intermediary
RequiresWeakness BaseWeakness BaseWeakness Base642External Control of User State Data
RequiresWeakness BaseWeakness BaseWeakness Base613Insufficient Session Expiration
ChildOfViewView629
ChildOfViewView635
PeerOfWeakness BaseWeakness BaseWeakness Base79Failure to Sanitize Directives in a Web Page (aka 'Cross-site scripting' (XSS))
Source Taxonomies

PLOVER - Cross-Site Request Forgery (CSRF)

Applicable Platforms

All

Time of Introduction

Architecture and Design

Related Attack Patterns
CAPEC-IDAttack Pattern Name
62Cross Site Request Forgery (aka Session Riding)
Cryptographic Issues
Category ID
Status: Draft

310 (Category)

Description

Summary

Weaknesses in this category are related to the use of cryptography.

Functional Area

Cryptography

Context Notes

This category is incomplete and needs refinement, as there is good documentation of cryptographic flaws and related attacks.

Note: some of these can be resultant.

Relationships
NatureTypeIDName
ChildOfCategoryCategory254Security Features
ChildOfViewView635
ParentOfCategoryCategory320Key Management Errors
CanAlsoBeWeakness BaseWeakness BaseWeakness Base208Timing Discrepancy Information Leak
CanAlsoBeWeakness BaseWeakness BaseWeakness Base226Sensitive Information Uncleared Before Release
ParentOfWeakness BaseWeakness BaseWeakness Base311Failure to Encrypt Sensitive Data
ParentOfWeakness BaseWeakness BaseWeakness Base325Missing Required Cryptographic Step
ParentOfWeakness ClassWeakness ClassWeakness Class326Weak Encryption
ParentOfWeakness BaseWeakness BaseWeakness Base328Reversible One-Way Hash
ParentOfWeakness VariantWeakness VariantWeakness Variant329Not Using a Random IV with CBC Mode
Source Taxonomies

PLOVER - Cryptographic Issues

Applicable Platforms

All

Failure to Constrain Operations within the Bounds of an Allocated Memory Buffer
Weakness ID
Status: Draft

119 (Weakness Class)

Description

Summary

The software may potentially allow operations, such as reading or writing, to be performed at addresses not intended by the developer.

Extended Description

When software permits read or write operations on memory located outside of an allocated range, an attacker may be able to access/modify sensitive information, cause the system to crash, alter the intended control flow, or execute arbitrary code.

Affected Resource

Memory

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class118Range Errors
ChildOfViewView635
ChildOfCategoryCategory633Weaknesses that Affect Memory
ParentOfCategoryCategory133String Errors
ParentOfWeakness BaseWeakness BaseWeakness Base123Write-what-where Condition
ParentOfWeakness BaseWeakness BaseWeakness Base124Boundary Beginning Violation ('Buffer Underwrite')
ParentOfWeakness BaseWeakness BaseWeakness Base125Out-of-bounds Read
ParentOfWeakness BaseWeakness BaseWeakness Base128Wrap-around Error
ParentOfWeakness BaseWeakness BaseWeakness Base129Unchecked Array Indexing
ParentOfWeakness ClassWeakness ClassWeakness Class131Incorrect Calculation of Buffer Size
ParentOfWeakness BaseWeakness BaseWeakness Base132Miscalculated Null Termination
ParentOfWeakness BaseWeakness BaseWeakness Base466Return of Pointer Value Outside of Expected Range
ParentOfCompound Element: CompositeCompound Element: Composite120Unbounded Transfer ('Classic Buffer Overflow')
Related Attack Patterns
CAPEC-IDAttack Pattern Name
100Overflow Buffers
10Buffer Overflow via Environment Variables
14Client-side Injection-induced Buffer Overflow
42MIME Conversion
24Filter Failure through Buffer Overflow
8Buffer Overflow in an API Call
44Overflow Binary Resource File
9Buffer Overflow in Local Command-Line Utilities
45Buffer Overflow via Symbolic Links
46Overflow Variables and Tags
47Buffer Overflow via Parameter Expansion
Failure to Resolve Links Before File Access (aka 'Link Following')
Weakness ID
Status: Draft

59 (Weakness Base)

Description

Summary

Link following weaknesses involve insufficient protection against links or shortcuts that can resolve to a file other than the one that was intended.

Alternate Terms

Some people use the phrase "insecure temporary file" when referring to a link following weakness, but other weaknesses can produce insecure temporary files without any symlink involvement at all.

Functional Area

File processing, temporary files

Likelihood of Exploit

Low to Medium

Weakness Ordinality

Resultant (Weakness is typically related to the presence of some other weaknesses)

Causal Nature

Explicit (This is an explicit weakness resulting from behavior of the developer)

Affected Resource

File/Directory

Potential Mitigations

Follow the principle of least privilege when assigning access rights to files. Denying access to a file can prevent an attacker from replacing that file with a link to a sensitive file. Ensure good compartmentalization in the system to provide protected areas that can be trusted.

Context Notes

Link following vulnerabilities are Multi-factor Vulnerabilities (MFV). They are the combination of multiple elements: file or directory permissions, filename predictability, race conditions, and in some cases, a design limitation in which there is no mechanism for performing atomic file creation operations.

Some potentials factors are race conditions, permissions, predictability.

This is not OS specific.

Windows soft links can be exploited remotely since a ".LNK" file can be uploaded like a normal file.

Research Gaps

UNIX hard links, and Windows hard/soft links are under-studied and under-reported.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class21Pathname Traversal and Equivalence Errors
ChildOfCategoryCategory632Weaknesses that Affect Files or Directories
ChildOfViewView635
ParentOfCategoryCategory60UNIX Path Link Problems
ParentOfCategoryCategory63Windows Path Link Problems
CanAlsoBeWeakness BaseWeakness BaseWeakness Base363Race Condition Enabling Link Following
Source Taxonomies

PLOVER - Link Following

Applicable Platforms

All

Related Attack Patterns
CAPEC-IDAttack Pattern Name
35Leverage Executable Code in Nonexecutable Files
17Accessing, Modifying or Executing Executable Files
76Manipulating Input to File System Calls
Failure to Sanitize Data into an OS Command (aka 'OS Command Injection')
Weakness ID
Status: Incomplete

78 (Weakness Base)

Description

Summary

The software fails to adequately filter OS command syntax from user-controlled input and then allows potentially injected commands to execute within its context. A software system that accepts and executes input in the form of operating system commands (e.g. system(), exec(), open()) could allow an attacker with lesser privileges than the target software to execute commands with the elevated privileges of the executing process. The problem is exacerbated if the compromised process fails to follow the principle of least privilege.

Alternate Terms

Shell injection, shell metacharacters

Functional Area

Program invocation

Affected Resource

System Process

Potential Mitigations

Design: If at all possible, use library calls rather than external processes to recreate the desired functionality

Implementation: Utilize black-list parsing to filter non-relevant OS command syntax from all input.

Implementation: Ensure that all external commands called from the program are statically created, or -- if they must take input from a user -- that the input and final line generated are vigorously white-list checked.

Run time: Run time policy enforcement may be used in a white-list fashion to prevent use of any non-sanctioned commands.

Assign permissions to the software system that prevents the user from accessing/opening privileged files.

Observed Examples
ReferenceDescription
CVE-1999-0067
CVE-2001-1246
CVE-2002-0061
CVE-2003-0041
CVE-2002-1898Shell metacharacters in a telnet:// link (this is a multi-factor vulnerability,
CVE-2007-3572Chain: incomplete blacklist for OS command injection
Context Notes

Fault: unquoted special characters, input restriction error

References

G. Hoglund and G. McGraw. "Exploiting Software: How to Break Code". Addison-Wesley. February 2004.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class77Failure to Sanitize Data into a Control Plane (aka 'Command Injection')
CanAlsoBeWeakness BaseWeakness BaseWeakness Base88Argument Injection or Modification
ChildOfViewView629
ChildOfViewView630
ChildOfCategoryCategory634Weaknesses that Affect System Processes
ChildOfViewView635
CanFollowWeakness BaseWeakness BaseWeakness Base184Incomplete Blacklist
Source Taxonomies

PLOVER - OS Command Injection

Applicable Platforms

All

Related Attack Patterns
CAPEC-IDAttack Pattern Name
88OS Command Injection
15Command Delimiters
6Argument Injection
43Exploiting Multiple Input Interpretation Layers
White Box Definition


A weakness where the code path has:
1.        start statement that accepts input
2.        end statement that executes an operating system command where
          a.        the input is used as a part of the operating system command
          b.        the privilege of the operating system command is higher than privilege of the input and
          c.        the operating system command is undesirable

Where “undesirable” is defined through the following scenarios:
1.        not validated
2.        incorrectly validated

Failure to Sanitize Data into SQL Queries (aka 'SQL Injection')
Weakness ID
Status: Incomplete

89 (Weakness Base)

Description

Summary

The application fails to adequately filter SQL syntax from user-controllable input. This can lead to such input being interpreted as SQL rather than ordinary user data and be executed as part of a dynamically generated SQL query. This is a specific form of an injection problem, one that explicitly affects SQL databases, in which SQL commands are injected into data-plane input in order to effect the execution of dynamically generated SQL statements.

Likelihood of Exploit

Very High

Common Consequences

Confidentiality: Since SQL databases generally hold sensitive data, loss of confidentiality is a frequent problem with SQL injection vulnerabilities.

Authentication: If poor SQL commands are used to check user names and passwords, it may be possible to connect to a system as another user with no previous knowledge of the password.

Authorization: If authorization information is held in a SQL database, it may be possible to change this information through the successful exploitation of a SQL injection vulnerability.

Integrity: Just as it may be possible to read sensitive information, it is also possible to make changes or even delete this information with a SQL injection attack.

Potential Mitigations

Requirements specification: A non-SQL style database which is not subject to this flaw may be chosen.

Design: Follow the principle of least privilege when creating user accounts to a SQL database. Users should only have the minimum privileges necessary to use their account. If the requirements of the system indicate that a user can read and modify their own data, then limit their privileges so they cannot read/write others' data.

Design: Duplicate any filtering done on the client-side on the server side.

Implementation: Implement SQL strings using prepared statements that bind variables. Prepared statements that do not bind variables can be vulnerable to attack.

Implementation: Use vigorous white-list style checking on any user input that may be used in a SQL command. Rather than escape meta-characters, it is safest to disallow them entirely. Reason: Later use of data that have been entered in the database may neglect to escape meta-characters before use. Narrowly define the set of safe characters based on the expected value of the parameter in the request.

Demonstrative
Examples

The following code dynamically constructs and executes a SQL query that searches for items matching a specified name. The query restricts the items displayed to those where owner matches the user name of the currently-authenticated user.

C# Example:

...
string userName = ctx.getAuthenticatedUserName();
string query = "SELECT * FROM items WHERE owner = '" + userName + "' AND itemname = '" + ItemName.Text + "'";
sda = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
...

The query that this code intends to execute follows: SELECT * FROM items WHERE owner = <userName> AND itemname = <itemName>; However, because the query is constructed dynamically by concatenating a constant base query string and a user input string, the query only behaves correctly if itemName does not contain a single-quote character. If an attacker with the user name wiley enters the string "name' OR 'a'='a" for itemName, then the query becomes the following: SELECT * FROM items WHERE owner = 'wiley' AND itemname = 'name' OR 'a'='a'; The addition of the OR 'a'='a' condition causes the where clause to always evaluate to true, so the query becomes logically equivalent to the much simpler query: SELECT * FROM items; This simplification of the query allows the attacker to bypass the requirement that the query only return items owned by the authenticated user; the query now returns all entries stored in the items table, regardless of their specified owner.


This example examines the effects of a different malicious value passed to the query constructed and executed in the above example. If an attacker with the user name hacker enters the string "hacker'); DELETE FROM items; --" for itemName, then the query becomes the following two queries:

SQL Example:

SELECT * FROM items WHERE owner = 'wiley' AND itemname = 'name';
DELETE FROM items;
--'

Many database servers, including Microsoft(R) SQL Server 2000, allow multiple SQL statements separated by semicolons to be executed at once. While this attack string results in an error on Oracle and other database servers that do not allow the batch-execution of statements separated by semicolons, on databases that do allow batch execution, this type of attack allows the attacker to execute arbitrary commands against the database. Notice the trailing pair of hyphens (--), which specifies to most database servers that the remainder of the statement is to be treated as a comment and not executed [19]. In this case the comment character serves to remove the trailing single-quote left over from the modified query. On a database where comments are not allowed to be used in this way, the general attack could still be made effective using a trick similar to the one shown in Example 1. If an attacker enters the string "name'); DELETE FROM items; SELECT * FROM items WHERE owner = 'wiley' AND itemname = 'name'; DELETE FROM items; SELECT * FROM items WHERE 'a'='a'; One traditional approach to preventing SQL injection attacks is to handle them as an input validation problem and either accept only characters from a whitelist of safe values or identify and escape a blacklist of potentially malicious values. Whitelisting can be a very effective means of enforcing strict input validation rules, but parameterized SQL statements require less maintenance and can offer more guarantees with respect to security. As is almost always the case, blacklisting is riddled with loopholes that make it ineffective at preventing SQL injection attacks. For example, attackers can: - Target fields that are not quoted - Find ways to bypass the need for certain escaped meta-characters - Use stored procedures to hide the injected meta-characters Manually escaping characters in input to SQL queries can help, but it will not make your application secure from SQL injection attacks. Another solution commonly proposed for dealing with SQL injection attacks is to use stored procedures. Although stored procedures prevent some types of SQL injection attacks, they fail to protect against many others. For example, the following PL/SQL procedure is vulnerable to the same SQL injection attack shown in the first example. procedure get_item ( itm_cv IN OUT ItmCurTyp, usr in varchar2, itm in varchar2) is open itm_cv for ' SELECT * FROM items WHERE ' || 'owner = '|| usr || ' AND itemname = ' || itm || '; end get_item; Stored procedures typically help prevent SQL injection attacks by limiting the types of statements that can be passed to their parameters. However, there are many ways around the limitations and many interesting statements that can still be passed to stored procedures. Again, stored procedures can prevent some exploits, but they will not make your application secure against SQL injection attacks.


MS SQL has a built in function that enables shell command execution. An SQL injection in such a context could be disastrous. For example, a query of the form:

SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='$user_input' ORDER BY PRICE

Where $user_input is taken from the user and unfiltered.

If the user provides the string:

' exec master..xp_cmdshell 'vol' --

The query will take the following form: "

SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='' exec master..xp_cmdshell 'vol' --' ORDER BY PRICE

Now, this query can be broken down into: [1] a first SQL query: SELECT ITEM,PRICE FROM PRODUCT WHERE ITEM_CATEGORY='' [2] a second SQL query, which executes a shell command: exec master..xp_cmdshell 'vol' [3] an MS SQL comment: --' ORDER BY PRICE As can be seen, the malicious input changes the semantics of the query into a query, a shell command execution and a comment.

Observed Examples
ReferenceDescription
CVE-2004-0366
CVE-2004-0343
CVE-2003-0779
CVE-2003-0500
CVE-2003-0377
Context Notes

SQL injection has become a common issue with database-driven web sites. The flaw is easily detected, and easily exploited, and as such, any site or software package with even a minimal user base is likely to be subject to an attempted attack of this kind. Essentially, the attack is accomplished by placing a meta character into data input to then place SQL commands in the control plane, which did not exist there before. This flaw depends on the fact that SQL makes no real distinction between the control and data planes.

If successful, SQL Injection attacks can give an attacker access to backend database contents, the ability to remotely execute system commands, or in some circumstances the means to take control of the Windows server hosting the database.

Dynamically generating queries that include user input can lead to SQL injection attacks. An attacker can insert SQL commands or modifiers in the user input that can cause the query to behave in an unsafe manner.

Constructing a dynamic SQL statement with user input may allow an attacker to modify the statement's meaning or to execute arbitrary SQL commands.

Factors: resultant to special character mismanagement, MAID, or blacklist/whitelist problems. Can be primary to authentication errors.

References

M. Howard and D. LeBlanc. "Writing Secure Code". 2nd Edition. Microsoft. 2003.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class74Failure to Sanitize Data into a Different Plane (aka 'Injection')
ChildOfViewView629
ChildOfViewView630
ChildOfViewView635
CanFollowWeakness BaseWeakness BaseWeakness Base456Missing Initialization
ParentOfWeakness VariantWeakness VariantWeakness Variant564SQL Injection: Hibernate
Source Taxonomies

PLOVER - SQL injection

7 Pernicious Kingdoms - SQL Injection

CLASP - SQL injection

Applicable Platforms

All

Related Attack Patterns
CAPEC-IDAttack Pattern Name
66SQL Injection
7Blind SQL Injection
White Box Definition


A weakness where the code path has:
1.        start statement that accepts input
2.        end statement that performs an SQL command where
          a.        the input is part of the SQL command and
          b.        the SQL command is undesirable

Where “undesirable” is defined through the following scenarios:
1.        not validated
2.        incorrectly validated

Failure to Sanitize Directives in a Web Page (aka 'Cross-site scripting' (XSS))
Weakness ID
Status: Draft

79 (Weakness Base)

Description

Summary

The software does not sufficiently sanitize user-controllable input for content before it is prepared in output that is used as a web page.

Extended Description

Unsanitized special elements that have control implications in web pages, such as HTML tags or mouse events, are interpreted as control characters that execute in violation of the client's trust in the application or system. This weakness usually enables cross-site scripting attacks in web applications.

Alternate Terms

"CSS" was once used as the acronym for this problem, but this can cause confusion with the "Cascading Style Sheets," so this acronym has declined significantly. Its use is discouraged by CWE.

Likelihood of Exploit

High to Very High

Weakness Ordinality

Resultant (Weakness is typically related to the presence of some other weaknesses)

Causal Nature

Explicit (This is an explicit weakness resulting from behavior of the developer)

Common Consequences

Confidentiality: The most common attack performed with cross-site scripting involves the disclosure of information stored in user cookies.

Access control: In some circumstances it may be possible to run arbitrary code on a victim's computer when cross-site scripting is combined with other flaws.

If successful, cross-site scripting vulnerabilities can be exploited to manipulate or steal cookies, create requests that can be mistaken for those of a valid user, compromise confidential information, or execute malicious code on the end user systems for a variety of nefarious purposes.

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.

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

The following JSP code segment reads an employee ID, eid, from an HTTP request and displays it to the user.

JSP Example:

<% String eid = request.getParameter("eid"); %>
...
Employee ID: <%= eid %>

The following ASP.NET code segment reads an employee ID number from an HTTP request and displays it to the user.

ASP.NET Example:

protected System.Web.UI.WebControls.TextBox Login;
protected System.Web.UI.WebControls.Label EmployeeID;
  ...
EmployeeID.Text = Login.Text;

The code in this example operates correctly if eid contains only standard alphanumeric text. If eid has a value that includes meta-characters or source code, then the code will be executed by the web browser as it displays the HTTP response. Initially this might not appear to be much of a vulnerability. After all, why would someone enter a URL that causes malicious code to run on their own computer? The real danger is that an attacker will create the malicious URL, then use e-mail or social engineering tricks to lure victims into visiting a link to the URL. When victims click the link, they unwittingly reflect the malicious content through the vulnerable web application back to their own computers. This mechanism of exploiting vulnerable web applications is known as Reflected XSS.


The following JSP code segment queries a database for an employee with a given ID and prints the corresponding employee's name.

JSP Example:

<%...
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp where id="+eid);
if (rs != null) {
rs.next();
String name = rs.getString("name");
%>

Employee Name: <%= name %>

The following ASP.NET code segment queries a database for an employee with a given employee ID and prints the name corresponding with the ID.

ASP.NET Example:

protected System.Web.UI.WebControls.Label EmployeeName;
  ...
string query = "select * from emp where id=" + eid;
sda = new SqlDataAdapter(query, conn);
sda.Fill(dt);
string name = dt.Rows[0]["Name"];
  ...
EmployeeName.Text = name;

This code functions correctly when the values of name are well-behaved, but it does nothing to prevent exploits if they are not. Again, this code can appear less dangerous because the value of name is read from a database, whose contents are apparently managed by the application. However, if the value of name originates from user-supplied data, then the database can be a conduit for malicious content. Without proper input validation on all data stored in the database, an attacker can execute malicious commands in the user's web browser. This type of exploit, known as Stored XSS, is particularly insidious because the indirection caused by the data store makes it more difficult to identify the threat and increases the possibility that the attack will affect multiple users. XSS got its start in this form with web sites that offered a "guestbook" to visitors. Attackers would include JavaScript in their guestbook entries, and all subsequent visitors to the guestbook page would execute the malicious code. As the examples demonstrate, XSS vulnerabilities are caused by code that includes unvalidated data in an HTTP response. There are three vectors by which an XSS attack can reach a victim: * As in the previous example, data is read directly from the HTTP request and reflected back in the HTTP response. Reflected XSS exploits occur when an attacker causes a user to supply dangerous content to a vulnerable web application, which is then reflected back to the user and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to victims. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces victims to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the user, the content is executed and proceeds to transfer private information, such as cookies that may include session information, from the user's machine to the attacker or perform other nefarious activities. * As in this example, the application stores dangerous data in a database or other trusted data store. The dangerous data is subsequently read back into the application and included in dynamic content. Stored XSS exploits occur when an attacker injects dangerous content into a data store that is later read and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. * A source outside the application stores dangerous data in a database or other data store, and the dangerous data is subsequently read back into the application as trusted data and included in dynamic content.

Observed Examples
ReferenceDescription
CVE-2007-5727Chain: only removes SCRIPT tags, enabling XSS
CVE-2006-4308Chain: only checks "javascript:" tag
Context Notes

Cross-site scripting weakness occurs when dynamically generated web pages display input, such as login information, that is not properly validated, allowing an attacker to embed malicious scripts into the generated page and then execute the script on the machine of any user that views the site. If successful, Cross-site scripting vulnerabilities can be exploited to manipulate or steal cookies, create requests that can be mistaken for those of a valid user, compromise confidential information, or execute malicious code on the end user systems for a variety of nefarious purposes.

Cross-site scripting (XSS) vulnerabilities occur when an attacker uses a web application to send malicious code, generally JavaScript, to a different end user. When a web application uses input from a user in the output it generates without filtering it, an attacker can insert an attack in that input and the web application sends the attack to other users. The end user trusts the web application, and the attacks exploit that trust to do things that would not normally be allowed. Attackers frequently use a variety of methods to encode the malicious portion of the tag, such as using Unicode, so the request looks less suspicious to the user. XSS attacks can generally be categorized into two categories: stored and reflected. Stored attacks are those where the injected code is permanently stored on the target servers in a database, message forum, visitor log, and so forth. Reflected attacks are those where the injected code takes another route to the victim, such as in an email message, or on some other server. When a user is tricked into clicking a link or submitting a form, the injected code travels to the vulnerable web server, which reflects the attack back to the user's browser. The browser then executes the code because it came from a 'trusted' server. For a reflected XSS attack to work, the victim must submit the attack to the server. This is still a very dangerous attack given the number of possible ways to trick a victim into submitting such a malicious request, including clicking a link on a malicious Web site, in an email, or in an inner-office posting. XSS flaws are very likely in web applications, as they require a great deal of developer discipline to avoid them in most applications. It is relatively easy for an attacker to find XSS vulnerabilities. Some of these vulnerabilities can be found using scanners, and some exist in older web application servers. The consequence of an XSS attack is the same regardless of whether it is stored or reflected. The difference is in how the payload arrives at the server. XSS can cause a variety of problems for the end user that range in severity from an annoyance to complete account compromise. The most severe XSS attacks involve disclosure of the user's session cookie, which allows an attacker to hijack the user's session and take over their account. Other damaging attacks include the disclosure of end user files, installation of Trojan horse programs, redirecting the user to some other page or site, and modifying presentation of content. Cross-site scripting (XSS) vulnerabilities occur when: 1. Data enters a Web application through an untrusted source, most frequently a web request. 2. The data is included in dynamic content that is sent to a web user without being validated for malicious code. The malicious content sent to the web browser often takes the form of a segment of JavaScript, but may also include HTML, Flash or any other type of code that the browser may execute. The variety of attacks based on XSS is almost limitless, but they commonly include transmitting private data like cookies or other session information to the attacker, redirecting the victim to web content controlled by the attacker, or performing other malicious operations on the user's machine under the guise of the vulnerable site.

Cross-site scripting attacks can occur wherever an untrusted user has the ability to publish content to a trusted web site. Typically, a malicious user will craft a client-side script, which -- when parsed by a web browser -- performs some activity (such as sending all site cookies to a given E-mail address). If the input is unchecked, this script will be loaded and run by each user visiting the web site. Since the site requesting to run the script has access to the cookies in question, the malicious script does also. There are several other possible attacks, such as running "Active X" controls (under Microsoft Internet Explorer) from sites that a user perceives as trustworthy; cookie theft is however by far the most common. All of these attacks are easily prevented by ensuring that no script tags -- or for good measure, HTML tags at all -- are allowed in data to be posted publicly.

Cross-site scripting attacks may occur anywhere that possibly malicious users are allowed to post unregulated material to a trusted web site for the consumption of other valid users. The most common example can be found in bulletin-board web sites which provide web based mailing list-style functionality.

References

Jeremiah Grossman, Robert "RSnake" Hansen, Petko "pdp" D. Petkov, Anton Rager and Seth Fogie. "XSS Attacks". Syngress. 2007.

M. Howard and D. LeBlanc. "Writing Secure Code". 2nd Edition. Microsoft. 2003.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class74Failure to Sanitize Data into a Different Plane (aka 'Injection')
CanPrecedeWeakness VariantWeakness VariantWeakness Variant494Download of Untrusted Mobile Code Without Integrity Check
PeerOfCompound Element: CompositeCompound Element: Composite352Cross-Site Request Forgery (CSRF)
ChildOfViewView629
ChildOfViewView635
CanPrecedeCompound Element: ChainCompound Element: Chain692Incomplete Blacklist to Cross-Site Scripting
CanFollowWeakness BaseWeakness BaseWeakness Base113Failure to Sanitize CRLF Sequences in HTTP Headers (aka 'HTTP Response Splitting')
CanFollowWeakness BaseWeakness BaseWeakness Base184Incomplete Blacklist
CanFollowWeakness BaseWeakness BaseWeakness Base184Incomplete Blacklist
PeerOfWeakness VariantWeakness VariantWeakness Variant494Download of Untrusted Mobile Code Without Integrity Check
ParentOfWeakness VariantWeakness VariantWeakness Variant80Failure to Sanitize Script-Related HTML Tags in a Web Page (Basic XSS)
ParentOfWeakness VariantWeakness VariantWeakness Variant81Failure to Sanitize Directives in an Error Message Web Page
ParentOfWeakness VariantWeakness VariantWeakness Variant82Failure to Sanitize Script in Attributes of IMG Tags in a Web Page
ParentOfWeakness VariantWeakness VariantWeakness Variant83Failure to Sanitize Script in Attributes in a Web Page
ParentOfWeakness VariantWeakness VariantWeakness Variant84Failure to Resolve Encoded URI Schemes in a Web Page
ParentOfWeakness VariantWeakness VariantWeakness Variant85Doubled Character XSS Manipulations
ParentOfWeakness VariantWeakness VariantWeakness Variant86Invalid Characters in Identifiers
ParentOfWeakness VariantWeakness VariantWeakness Variant87Alternate XSS Syntax
Source Taxonomies

PLOVER - Cross-site scripting (XSS)

7 Pernicious Kingdoms - Cross-site Scripting

CLASP - Cross-site scripting

Applicable Platforms

All

Related Attack Patterns
CAPEC-IDAttack Pattern Name
91XSS in IMG Tags
19Embedding Scripts within Scripts
85Client Network Footprinting (using AJAX/XSS)
32Embedding Scripts in HTTP Query Strings
86Embedding Script (XSS ) in HTTP Headers
Information Leak (Information Disclosure)
Weakness ID
Status: Incomplete

200 (Weakness Class)

Description

Summary

An information leak is the intentional or unintentional disclosure of information that either (1) is regarded as sensitive within the product's own functionality, such as a private message, or (2) provides information about the product or its environment that could be useful in an attack but is normally not available to the attacker, such as the installation path of a product that is remotely accessible. Many information leaks are resultant (e.g. path disclosure in PHP script error), but they can also be primary (e.g. timing discrepancies in crypto). There are many different types of problems that involve information leaks. Their severity can range widely depending on the type of information that is leaked.

Potential Mitigations

Compartmentalize your system to have "safe" areas where trust boundaries can be unambiguously drawn. Do not allow sensitive data to go outside of the trust boundary and always be careful when interfacing with a compartment outside of the safe area.

Relationships
NatureTypeIDName
ChildOfCategoryCategory199Information Management Errors
ChildOfViewView629
ChildOfViewView635
ParentOfWeakness VariantWeakness VariantWeakness Variant201Information Leak Through Sent Data
ParentOfWeakness VariantWeakness VariantWeakness Variant202Privacy Leak through Data Queries
ParentOfWeakness ClassWeakness ClassWeakness Class203Discrepancy Information Leaks
ParentOfWeakness BaseWeakness BaseWeakness Base209Error Message Information Leaks
ParentOfWeakness BaseWeakness BaseWeakness Base212Cross-boundary Cleansing Information Leak
ParentOfWeakness BaseWeakness BaseWeakness Base213Intended Information Leak
ParentOfWeakness VariantWeakness VariantWeakness Variant214Process Environment Information Leak
ParentOfWeakness VariantWeakness VariantWeakness Variant215Information Leak Through Debug Information
ParentOfWeakness BaseWeakness BaseWeakness Base226Sensitive Information Uncleared Before Release
ParentOfWeakness BaseWeakness BaseWeakness Base497Information Leak of System Data
ParentOfWeakness Variant