167
Scope Impact Likelihood
Trojan horse programs, redirecting the user to some other
page or site, running "Active X" controls (under Microsoft
Internet Explorer) from sites that a user perceives as
trustworthy, and modifying presentation of content.
Detection Methods
Automated Static Analysis
Use automated static analysis tools that target this type of weakness. Many modern techniques
use data flow analysis to minimize the number of false positives. This is not a perfect solution,
since 100% accuracy and coverage are not feasible, especially when multiple components are
involved.
Effectiveness = Moderate
Black Box
Use the XSS Cheat Sheet [REF-714] or automated test-generation tools to help launch a wide
variety of attacks against your web application. The Cheat Sheet contains many subtle XSS
variations that are specifically targeted against weak XSS defenses.
Effectiveness = Moderate
With Stored XSS, the indirection caused by the data store can make it more difficult to find the
problem. The tester must first inject the XSS string into the data store, then find the appropriate
application functionality in which the XSS string is sent to other users of the application. These
are two distinct steps in which the activation of the XSS can take place minutes, hours, or days
after the XSS was originally injected into the data store.
Potential Mitigations
Phase: Architecture and Design
Strategy = Libraries or Frameworks
Use a vetted library or framework that does not allow this weakness to occur or provides
constructs that make this weakness easier to avoid. Examples of libraries and frameworks that
make it easier to generate properly encoded output include Microsoft's Anti-XSS library, the
OWASP ESAPI Encoding module, and Apache Wicket.
Phase: Implementation
Phase: Architecture and Design
Understand the context in which your data will be used and the encoding that will be expected.
This is especially important when transmitting data between different components, or when
generating outputs that can contain multiple encodings at the same time, such as web pages or
multi-part mail messages. Study all expected communication protocols and data representations
to determine the required encoding strategies. For any data that will be output to another web
page, especially any data that was received from external inputs, use the appropriate encoding
on all non-alphanumeric characters. Parts of the same output document may require different
encodings, which will vary depending on whether the output is in the: HTML body Element
attributes (such as src="XYZ") URIs JavaScript sections Cascading Style Sheets and style
property etc. Note that HTML Entity Encoding is only appropriate for the HTML body. Consult the
XSS Prevention Cheat Sheet [REF-724] for more details on the types of encoding and escaping
that are needed.
Phase: Architecture and Design
Phase: Implementation
Strategy = Attack Surface Reduction
CWE Version 4.14
CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
CWE-79: Improper Neutralization of Input During
Web Page Generation ('Cross-site Scripting') 168
Understand all the potential areas where untrusted inputs can enter your software: parameters
or arguments, cookies, anything read from the network, environment variables, reverse DNS
lookups, query results, request headers, URL components, e-mail, files, filenames, databases,
and any external systems that provide data to the application. Remember that such inputs may
be obtained indirectly through API calls.
Effectiveness = Limited
This technique has limited effectiveness, but can be helpful when it is possible to store client
state and sensitive information on the server side instead of in cookies, headers, hidden form
fields, etc.
Phase: Architecture and Design
For any security checks that are performed on the client side, ensure that these checks are
duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side
checks by modifying values after the checks have been performed, or by changing the client to
remove the client-side checks entirely. Then, these modified values would be submitted to the
server.
Phase: Architecture and Design
Strategy = Parameterization
If available, use structured mechanisms that automatically enforce the separation between
data and code. These mechanisms may be able to provide the relevant quoting, encoding, and
validation automatically, instead of relying on the developer to provide this capability at every
point where output is generated.
Phase: Implementation
Strategy = Output Encoding
Use and specify an output encoding that can be handled by the downstream component that
is reading the output. Common encodings include ISO-8859-1, UTF-7, and UTF-8. When an
encoding is not specified, a downstream component may choose a different encoding, either
by assuming a default encoding or automatically inferring which encoding is being used, which
can be erroneous. When the encodings are inconsistent, the downstream component might
treat some character or byte sequences as special, even if they are not special in the original
encoding. Attackers might then be able to exploit this discrepancy and conduct injection attacks;
they even might be able to bypass protection mechanisms that assume the original encoding is
also being used by the downstream component. The problem of inconsistent output encodings
often arises in web pages. If an encoding is not specified in an HTTP header, web browsers
often guess about which encoding is being used. This can open up the browser to subtle XSS
attacks.
Phase: Implementation
With Struts, write all data from form beans with the bean's filter attribute set to true.
Phase: Implementation
Strategy = Attack Surface Reduction
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 more recent versions of Internet
Explorer and Firefox), this attribute can prevent the user's session cookie from being accessible
to malicious client-side scripts that use document.cookie. This is not a complete solution, since
HttpOnly is not supported by all browsers. More importantly, XMLHTTPRequest and other
powerful browser technologies provide read access to HTTP headers, including the Set-Cookie
header in which the HttpOnly flag is set.
Effectiveness = Defense in Depth
Phase: Implementation
CWE Version 4.14
CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
CWE-79: Improper Neutralization of Input During
Web Page Generation ('Cross-site Scripting')