CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Export to Word

Description

The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.

Extended Description

There are many variants of cross-site scripting, characterized by a variety of terms or involving different attack topologies. However, they all indicate the same fundamental weakness: improper neutralization of dangerous input between the adversary and a victim.


ThreatScore

Threat Mapped score: 0.0

Industry: Finiancial

Threat priority: Unclassified


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation REALIZATION: This weakness is caused during implementation of an architectural security tactic.

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: The following code displays a welcome message on a web page based on the HTTP GET username parameter (covers a Reflected XSS (Type 1) scenario).

Body: Because the parameter can be arbitrary, the url of the page could be modified so $username contains scripting syntax, such as

$username = $_GET['username']; echo '<div class="header"> Welcome, ' . $username . '</div>';

Intro: The following code displays a Reflected XSS (Type 1) scenario.

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

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

Intro: The following code displays a Stored XSS (Type 2) scenario.

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

<%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 %>

Intro: The following code consists of two separate pages in a web application, one devoted to creating user accounts and another devoted to listing active users currently logged in. It also displays a Stored XSS (Type 2) scenario.

Body: CreateUser.php

$username = mysql_real_escape_string($username); $fullName = mysql_real_escape_string($fullName); $query = sprintf('Insert Into users (username,password) Values ("%s","%s","%s")', $username, crypt($password),$fullName) ; mysql_query($query); /.../

Intro: The following code is a simplistic message board that saves messages in HTML format and appends them to a file. When a new user arrives in the room, it makes an announcement:

Body: An attacker may be able to perform an HTML injection (Type 2 XSS) attack by setting a cookie to a value like:

$name = $_COOKIE["myname"]; $announceStr = "$name just logged in."; //save HTML-formatted message to file; implementation details are irrelevant for this example. saveMessage($announceStr);

Notes

← Back to CWE list