<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jeff+Williams</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jeff+Williams"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Jeff_Williams"/>
		<updated>2026-04-09T19:39:09Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=211876</id>
		<title>Injection Theory</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=211876"/>
				<updated>2016-03-28T02:18:33Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Injection Flaws|Injection]] is an attacker's attempt to send data to an application in a way that will change the meaning of commands being sent to an interpreter.  For example, the most common example is SQL injection, where an attacker sends &amp;quot;101 OR 1=1&amp;quot; instead of just &amp;quot;101&amp;quot;.  When included in a SQL query, this data changes the meaning to return ALL records instead of just one.  There are lots of interpreters in the typical web environment, such as SQL, LDAP, Operating System, XPath, XQuery, Expression Language, and many more.  Anything with a &amp;quot;command interface&amp;quot; that combines data into a command is susceptible.  Even XSS is really just a form of HTML injection.&lt;br /&gt;
&lt;br /&gt;
Frequently these interpreters run with a lot of access, so a successful attack can easily result in significant data breaches, or even loss of control of a browser, application, or server. Taken together, injection attacks are a huge percentage of the serious application security risk. Many organizations have poorly thought through security controls in place to prevent injection attacks.  Vague recommendations for input validation and output encoding are not going to prevent these flaws.  Instead, we recommend a strong set of controls integrated into your application frameworks.  The goal is to make injections impossible for developers.&lt;br /&gt;
&lt;br /&gt;
=Why Injection Happens to Good Developers=&lt;br /&gt;
&lt;br /&gt;
Injection can be complex. The subtleties of data flow, parsers, contexts, capabilities, and escaping are overwhelming even for security specialists.  In the following sections we will outline these topics to make it clear how injection can happen in a variety of different technologies.&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
First we need to consider the vehicle for injection attacks -- untrusted data.&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, untrusted data is input that can be manipulated to contain a web attack payload. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
As untrusted data flows through an application, it is frequently split into parts, combined with safe data, transformed, validated, and encoded in a variety of ways. A single piece of data could go through dozens of these steps before it gets to an interpreter.  This makes identifying injection problems very difficult.  Tools have a difficult time tracing the entire data flow and understanding exactly what data can run the gauntlet and what cannot.&lt;br /&gt;
&lt;br /&gt;
== Injection Context ==&lt;br /&gt;
&lt;br /&gt;
When untrusted data is used by an application, it is often inserted into a command, document, or other structure.  We will call this the '''injection context'''.  For example, consider a SQL statement constructed with &amp;quot;SELECT * FROM users WHERE name='&amp;quot; + request.getParameter( &amp;quot;name&amp;quot; ) + &amp;quot;'&amp;quot;;  In this example, the name is data from a potentially hostile user, and so could contain an attack.  But the attack is constrained by the injection context.  In this case, inside single quotes (').  That's why single quotes are so important for SQL injection.&lt;br /&gt;
&lt;br /&gt;
Consider a few of the types of commands and documents that might allow for injection...&lt;br /&gt;
* SQL queries&lt;br /&gt;
* LDAP queries&lt;br /&gt;
* Operating system command interpreters&lt;br /&gt;
* Any program invocation&lt;br /&gt;
* XML documents&lt;br /&gt;
* HTML documents&lt;br /&gt;
* JSON structures&lt;br /&gt;
* HTTP headers&lt;br /&gt;
* File paths&lt;br /&gt;
* URLs&lt;br /&gt;
* A variety of expresson languages&lt;br /&gt;
* etc...&lt;br /&gt;
&lt;br /&gt;
In all of these cases, if the attacker can &amp;quot;break out&amp;quot; of the intended injection context and modify the meaning of the command or document, they might be able to cause significant harm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Parsers ==&lt;br /&gt;
&lt;br /&gt;
Every interpreter has a parser.  Injection attacks target those parsers -- attempting to trick them into interpreting data as commands.  Understanding how a particular interpreter's parser works is the key to successful injection attacks -- and, ultimately, the path to creating defenses against injection.&lt;br /&gt;
&lt;br /&gt;
If you are a student of application security, you should learn as much as you can about how real parsers work.  Learn about grammars, and how to read BNF.  Beware, though, that the grammar may not match the implementation.  Real world parsers have many corner cases and flaws that may not match the spec.  A scientific approach to testing the *real* behavior of a parser is the best course forward.&lt;br /&gt;
&lt;br /&gt;
TBD.  Describe different types of parsers, tokens (particularly control characters), BNF.&lt;br /&gt;
&lt;br /&gt;
== Injection into References ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;reference&amp;quot; could be a database key, a URL, a filename, or some other kind of lookup index.  While injecting into these references doesn't typically allow for command execution, it's an interesting because the parsers for these references aren't typically too complicated.  However, URLs and filenames can become quite complex.  See the &amp;quot;jar:&amp;quot; scheme for examples of non-intuitive syntax begging for injection.&lt;br /&gt;
&lt;br /&gt;
TBD. This is for URLs, paths, and other simple forms.  Focus on the parser.  Could be as simple as Double.parseDouble (mark of the beast)&lt;br /&gt;
&lt;br /&gt;
== Injection into Commands ==&lt;br /&gt;
&lt;br /&gt;
TBD. Recursive descent or LALR parsers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injecting in Hierarchical Documents ==&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection with Multiple Nested Parsers ==&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=DEFENSES=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Validation ==&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
== Using Safe Interfaces ==&lt;br /&gt;
&lt;br /&gt;
TBD - parameterized interfaces with strong typing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
&lt;br /&gt;
[[User:Jeff Williams]] : jeff.williams[at]contrastsecurity.com&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=211875</id>
		<title>Injection Theory</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=211875"/>
				<updated>2016-03-28T02:07:42Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Injection Flaws|Injection]] is an attacker's attempt to send data to an application in a way that will change the meaning of commands being sent to an interpreter.  For example, the most common example is SQL injection, where an attacker sends &amp;quot;101 OR 1=1&amp;quot; instead of just &amp;quot;101&amp;quot;.  When included in a SQL query, this data changes the meaning to return ALL records instead of just one.  There are lots of interpreters in the typical web environment, such as SQL, LDAP, Operating System, XPath, XQuery, Expression Language, and many more.  Anything with a &amp;quot;command interface&amp;quot; that combines data into a command is susceptible.  Even XSS is really just a form of HTML injection.&lt;br /&gt;
&lt;br /&gt;
Frequently these interpreters run with a lot of access, so a successful attack can easily result in significant data breaches, or even loss of control of a browser, application, or server. Taken together, injection attacks are a huge percentage of the serious application security risk. Many organizations have poorly thought through security controls in place to prevent injection attacks.  Vague recommendations for input validation and output encoding are not going to prevent these flaws.  Instead, we recommend a strong set of controls integrated into your application frameworks.  The goal is to make injections impossible for developers.&lt;br /&gt;
&lt;br /&gt;
=Why Injection Happens to Good Developers=&lt;br /&gt;
&lt;br /&gt;
Injection can be complex. The subtleties of data flow, parsers, contexts, capabilities, and escaping are overwhelming even for security specialists.  In the following sections we will outline these topics to make it clear how injection can happen in a variety of different technologies.&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
First we need to consider the vehicle for injection attacks -- untrusted data.&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, untrusted data is input that can be manipulated to contain a web attack payload. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
As untrusted data flows through an application, it is frequently split into parts, combined with safe data, transformed, validated, and encoded in a variety of ways. A single piece of data could go through dozens of these steps before it gets to an interpreter.  This makes identifying injection problems very difficult.  Tools have a difficult time tracing the entire data flow and understanding exactly what data can run the gauntlet and what cannot.&lt;br /&gt;
&lt;br /&gt;
== Injection Context ==&lt;br /&gt;
&lt;br /&gt;
When untrusted data is used by an application, it is often inserted into a command, document, or other structure.  We will call this the '''injection context'''.  For example, consider a SQL statement constructed with &amp;quot;SELECT * FROM users WHERE name='&amp;quot; + request.getParameter( &amp;quot;name&amp;quot; ) + &amp;quot;'&amp;quot;;  In this example, the name is data from a potentially hostile user, and so could contain an attack.  But the attack is constrained by the injection context.  In this case, inside single quotes (').  That's why single quotes are so important for SQL injection.&lt;br /&gt;
&lt;br /&gt;
Consider a few of the types of commands and documents that might allow for injection...&lt;br /&gt;
* SQL queries&lt;br /&gt;
* LDAP queries&lt;br /&gt;
* Operating system command interpreters&lt;br /&gt;
* Any program invocation&lt;br /&gt;
* XML documents&lt;br /&gt;
* HTML documents&lt;br /&gt;
* JSON structures&lt;br /&gt;
* HTTP headers&lt;br /&gt;
* File paths&lt;br /&gt;
* URLs&lt;br /&gt;
* A variety of expresson languages&lt;br /&gt;
* etc...&lt;br /&gt;
&lt;br /&gt;
In all of these cases, if the attacker can &amp;quot;break out&amp;quot; of the intended injection context and modify the meaning of the command or document, they might be able to cause significant harm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Parsers ==&lt;br /&gt;
&lt;br /&gt;
TBD.  Describe different types of parsers, tokens (particularly control characters), BNF.&lt;br /&gt;
&lt;br /&gt;
== Injection into References ==&lt;br /&gt;
&lt;br /&gt;
TBD. This is for URLs, paths, and other simple forms.  Focus on the parser.  Could be as simple as Double.parseDouble (mark of the beast)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection into Commands ==&lt;br /&gt;
&lt;br /&gt;
TBD. Recursive descent or LALR parsers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injecting in Hierarchical Documents ==&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection with Multiple Nested Parsers ==&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=DEFENSES=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Validation ==&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
== Using Safe Interfaces ==&lt;br /&gt;
&lt;br /&gt;
TBD - parameterized interfaces with strong typing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
&lt;br /&gt;
[[User:Jeff Williams]] : jeff.williams[at]contrastsecurity.com&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=211874</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=211874"/>
				<updated>2016-03-28T02:06:23Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: This section is not for minor contributions and edits&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the [[XSS Filter Evasion Cheat Sheet]]. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
Before reading this cheatsheet, it is important to have a fundamental understanding of [[Injection Theory]].&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
Microsoft provides an encoding library named the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] for the .NET platform and ASP.NET Framework has built-in [http://msdn.microsoft.com/en-us/library/ms972969.aspx#securitybarriers_topic6 ValidateRequest] function that provides '''limited''' sanitization.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library for Java. OWASP also provides the [[OWASP Java Encoder Project]] for high-performance encoding.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; not recommended because its not in the HTML spec (See: [http://www.w3.org/TR/html4/sgml/entities.html section 24.4.1]) &amp;amp;amp;apos; is in the XML and XHTML specs.&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
=== RULE #3.1 - HTML escape JSON values in an HTML context and read the data with JSON.parse ===&lt;br /&gt;
&lt;br /&gt;
In a Web 2.0 world, the need for having data dynamically generated by an application in a javascript context is common.  One strategy is to make an AJAX call to get the values, but this isn't always performant.  Often, an initial block of JSON is loaded into the page to act as a single place to store multiple values.  This data is tricky, though not impossible, to escape correctly without breaking the format and content of the values.&lt;br /&gt;
&lt;br /&gt;
'''Ensure returned ''Content-Type'' header is application/json and not text/html. &lt;br /&gt;
This shall instruct the browser not misunderstand the context and execute injected script'''&lt;br /&gt;
&lt;br /&gt;
'''Bad HTTP response:'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: text/html; charset=utf-8''' &amp;lt;-- bad&lt;br /&gt;
    ....&lt;br /&gt;
    Content-Length: 373&lt;br /&gt;
    Keep-Alive: timeout=5, max=100&lt;br /&gt;
    Connection: Keep-Alive&lt;br /&gt;
    {&amp;quot;Message&amp;quot;:&amp;quot;No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&amp;amp;AddressLine&lt;br /&gt;
    =The+Gardens'''&amp;amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;'''&amp;amp;AddressLine2=foxlodge+woods&amp;amp;TownName=Meath'.&amp;quot;,&amp;quot;MessageDetail&amp;quot;:&amp;quot;No type was found&lt;br /&gt;
    that matches the controller named 'pay'.&amp;quot;}   &amp;lt;-- this script will pop!!&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
'''Good HTTP response'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: application/json; charset=utf-8''' &amp;lt;--good&lt;br /&gt;
    .....&lt;br /&gt;
    .....&lt;br /&gt;
&lt;br /&gt;
A common '''anti-pattern''' one would see:&lt;br /&gt;
&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      var initData = &amp;lt;%= data.to_json %&amp;gt;; // '''Do NOT do this without encoding the data with one of the techniques listed below.'''&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== JSON entity encoding ====&lt;br /&gt;
&lt;br /&gt;
The rules for JSON encoding can be found in the [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#Output_Encoding_Rules_Summary Output Encoding Rules Summary]. Note, this will not allow you to use XSS protection provided by CSP 1.0.&lt;br /&gt;
&lt;br /&gt;
==== HTML entity encoding ====&lt;br /&gt;
&lt;br /&gt;
This technique has the advantage that html entity escaping is widely supported and helps separate data from server side code without crossing any context boundaries. Consider placing the JSON block on the page as a normal element and then parsing the innerHTML to get the contents.  The javascript that reads the span can live in an external file, thus making the implementation of CSP enforcement easier.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script id=&amp;quot;init_data&amp;quot; type=&amp;quot;application/json&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;amp;lt;%= html_escape(data.to_json) %&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  // external js file&lt;br /&gt;
  var dataElement = document.getElementById('init_data');&lt;br /&gt;
  // unescape the content of the span&lt;br /&gt;
  var jsonText = dataElement.textContent || dataElement.innerText  &lt;br /&gt;
  var initData = JSON.parse(html_unescape(jsonText));&lt;br /&gt;
&lt;br /&gt;
An alternative to escaping and unescaping JSON directly in JavaScript, is to normalize JSON server-side by converting '&amp;lt;' to '\u003c' before delivering it to the browser.&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/span&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Sanitize HTML Markup with a Library Designed for the Job ==&lt;br /&gt;
&lt;br /&gt;
If your application handles markup -- untrusted input that is supposed to contain HTML -- it can be very difficult to validate. Encoding is also difficult, since it would break all the tags that are supposed to be in the input. Therefore, you need a library that can parse and clean HTML formatted text.  There are several available at OWASP that are simple to use:&lt;br /&gt;
&lt;br /&gt;
'''HtmlSanitizer''' - https://github.com/mganss/HtmlSanitizer&lt;br /&gt;
&lt;br /&gt;
An open-source .Net library. The HTML is cleaned with a white list approach. All allowed tags and attributes can be configured. The library is unit tested with the [https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet OWASP XSS Filter Evasion Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
   var sanitizer = new HtmlSanitizer();&lt;br /&gt;
   sanitizer.AllowedAttributes.Add(&amp;quot;class&amp;quot;);&lt;br /&gt;
   var sanitized = sanitizer.Sanitize(html);&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer''' - https://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
'''Ruby on Rails SanitizeHelper''' - http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html&lt;br /&gt;
&lt;br /&gt;
The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.&lt;br /&gt;
   &lt;br /&gt;
   &amp;amp;lt;%= sanitize @comment.body, tags: %w(strong em a), attributes: %w(href) %&amp;amp;gt;   &lt;br /&gt;
&lt;br /&gt;
'''Other libraries that provide HTML Sanitization include:'''&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP Html Purifier - http://htmlpurifier.org/&amp;lt;br/&amp;gt;&lt;br /&gt;
JavaScript/Node.JS Bleach - https://github.com/ecto/bleach&amp;lt;br/&amp;gt;&lt;br /&gt;
Python Bleach - https://pypi.python.org/pypi/bleach&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule #1: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule #2: Implement Content Security Policy ==&lt;br /&gt;
&lt;br /&gt;
There is another good complex solution to mitigate the impact of an XSS flaw called Content Security Policy. It's a browser side mechanism which &lt;br /&gt;
allows you to create source whitelists for client side resources of your web application, e.g. JavaScript, CSS, images, etc. CSP via special HTTP header instructs the browser to only execute or render resources from those sources. For example this CSP &lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: default-src: 'self'; script-src: 'self' static.domain.tld&lt;br /&gt;
&lt;br /&gt;
will instruct web browser to load all resources only from the page's origin and JavaScript source code files additionaly from static.domain.tld. For more details on Content Security Policy, including what it does, and how to use it, see the OWASP article on  [[Content_Security_Policy]]&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule #3: Use an Auto-Escaping Template System ==&lt;br /&gt;
&lt;br /&gt;
Many web application frameworks provide automatic contextual escaping functionality such as [https://docs.angularjs.org/api/ng/service/$sce AngularJS strict contextual escaping] and [https://golang.org/pkg/html/template/ Go Templates]. Use these technologies when you can.&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule #4: Use the X-XSS-Protection Response Header ==&lt;br /&gt;
&lt;br /&gt;
This HTTP response header enables the Cross-site scripting (XSS) filter built into some modern web browsers. This header is usually enabled by default anyway, so the role of this header is to re-enable the filter for this particular website if it was disabled by the user.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The following snippets of HTML demonstrate how to safely render untrusted data in a variety of different contexts. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable nowraplinks&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Data Type&lt;br /&gt;
! Context&lt;br /&gt;
! Code Sample&lt;br /&gt;
! Defense&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;span&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;amp;lt;/span&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Safe HTML Attributes&lt;br /&gt;
| &amp;amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;fname&amp;quot; value=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes Aggressive HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Only place untrusted data into a whitelist of safe attributes (listed below).&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Strictly validate unsafe attributes such as background, id and name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| GET Parameter&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;/site/search?value=&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.235_-_URL_Escape_Before_Inserting_Untrusted_Data_into_HTML_URL_Parameter_Values URL Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Untrusted URL in a SRC or HREF attribute&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;iframe src=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Canonicalize input&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;URL Validation&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Safe URL verification&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Whitelist http and https URL's only ([[Avoid the JavaScript Protocol to Open a new Window]])&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Attribute encoder&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| CSS Value&lt;br /&gt;
| &amp;amp;lt;div style=&amp;quot;width: &amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;;&amp;quot;&amp;gt;Selection&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values Strict structural validation]&amp;lt;li&amp;gt;CSS Hex encoding&amp;lt;li&amp;gt;Good design of CSS Features&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| JavaScript Variable&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;var currentValue='&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;';&amp;amp;lt;/script&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;script&amp;gt;someFunction('&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;');&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Ensure JavaScript variables are quoted&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Hex Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Unicode Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Avoid backslash encoding (\&amp;quot; or \' or \\)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| HTML&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;div&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED HTML&amp;lt;/span&amp;gt;&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Use_an_HTML_Policy_engine_to_validate_or_clean_user-driven_HTML_in_an_outbound_way HTML Validation (JSoup, AntiSamy, HTML Sanitizer)]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| DOM XSS&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;document.write(&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;quot;UNTRUSTED INPUT: &amp;quot; + document.location.hash&amp;lt;/span&amp;gt;);&amp;amp;lt;script/&amp;amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[[DOM based XSS Prevention Cheat Sheet]]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''''Safe HTML Attributes include:''''' align, alink, alt, bgcolor, border, cellpadding, cellspacing, class, color, cols, colspan, coords, dir, face, height, hspace, ismap, lang, marginheight, marginwidth, multiple, nohref, noresize, noshade, nowrap, ref, rel, rev, rows, rowspan, scrolling, shape, span, summary, tabindex, title, usemap, valign, value, vlink, vspace, width&lt;br /&gt;
&lt;br /&gt;
= Output Encoding Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The purpose of output encoding (as it relates to Cross Site Scripting) is to convert untrusted input into a safe form where the input is displayed as '''data''' to the user without executing as '''code''' in the browser. The following charts details a list of critical output encoding methods needed to stop Cross Site Scripting.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Encoding Type&lt;br /&gt;
! Encoding Mechanism&lt;br /&gt;
|-&lt;br /&gt;
| HTML Entity Encoding&lt;br /&gt;
|   Convert &amp;amp; to &amp;amp;amp;amp;&amp;lt;br/&amp;gt;Convert &amp;lt; to &amp;amp;amp;lt;&amp;lt;br/&amp;gt;Convert &amp;gt; to &amp;amp;amp;gt;&amp;lt;br/&amp;gt;Convert &amp;quot; to &amp;amp;amp;quot;&amp;lt;br/&amp;gt;Convert ' to &amp;amp;amp;#x27;&amp;lt;br/&amp;gt;Convert / to &amp;amp;amp;#x2F;&lt;br /&gt;
|-&lt;br /&gt;
| HTML Attribute Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the HTML Entity &amp;amp;amp;#xHH; format, including spaces. (HH = Hex Value)&lt;br /&gt;
|-&lt;br /&gt;
| URL Encoding&lt;br /&gt;
| Standard percent encoding, see: [http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp]. URL encoding should only be used to encode parameter values, not the entire URL or path fragments of a URL.&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the \uXXXX unicode escaping format (X = Integer).&lt;br /&gt;
|-&lt;br /&gt;
| CSS Hex Encoding&lt;br /&gt;
| CSS escaping supports \XX and \XXXXXX. Using a two character escape can cause problems if the next character continues the escape sequence. There are two solutions (a) Add a space after the CSS escape (will be ignored by the CSS parser) (b) use the full amount of CSS escaping possible by zero padding the value.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* OWASP: [[XSS Filter Evasion Cheat Sheet]] - Based on - RSnake's: &amp;quot;XSS Cheat Sheet&amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''Discussion on the Types of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[Types of Cross-Site Scripting]]&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* [[XSS Experimental Minimal Encoding Rules]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]contrastsecurity.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Neil Mattatall - neil[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
[[Category:Popular]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=201596</id>
		<title>User:Jeff Williams</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=201596"/>
				<updated>2015-10-04T20:56:09Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm Jeff Williams, I'm the CTO and cofounder of [http://contrastsecurity.com Contrast Security]. Contrast is not a scanner or static analysis tool. Instead, Contrast uses software instrumentation to *both* find vulnerabilities and block attacks.  The instrumentation approach provides access to not only the code and HTTP traffic, but also full data flow, control flow, configuration, libraries and frameworks, architecture, and much more.  This wealth of information yields incredible accuracy.  And that's not all... because Contrast runs in parallel and provides results in real time, you can provide security at [http://www.contrastsecurity.com/jeff-williams-appsec-at-devops-speed-and-portfolio-scale devops speed and portfolio scale].&lt;br /&gt;
&lt;br /&gt;
in the early 2000's, I helped found OWASP, created the OWASP Foundation 501c3, and served as the volunteer Chair of the OWASP Foundation from 2003 to 2012. I’ve dedicated my life to trying to make the world’s software more secure, and so I create lots of free and open tools, libraries, guidance, and standards to try to change the status quo. Thank you all for your dedication to application security and your participation in OWASP. Please send any questions or comments to me via email at [mailto:jeff.williams@contrastsecurity.com jeff.williams@contrastsecurity.com]. Or you can twitter @planetlevel.&lt;br /&gt;
&lt;br /&gt;
last revised {{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}&lt;br /&gt;
&lt;br /&gt;
I'm particularly proud of this free tool that uses instrumentation to find vulnerabilities. Far easier to use and more accurate than static (SAST) or dynamic analysis (DAST) scanners.&lt;br /&gt;
* FREE tool - Contrast for Eclipse - http://marketplace.eclipse.org/content/contrast-eclipse &lt;br /&gt;
&lt;br /&gt;
Also please read the &amp;quot;Continuous Security Handbook&amp;quot; which reinterprets application security for high-speed DevOps environments.&lt;br /&gt;
* FREE CAS Handbook - http://www1.contrastsecurity.com/continuous-app-security&lt;br /&gt;
&lt;br /&gt;
Some of my other work (in roughly reverse chronological order)&lt;br /&gt;
* Enterprise Java Rootkits - https://www.blackhat.com/presentations/bh-usa-09/WILLIAMS/BHUSA09-Williams-EnterpriseJavaRootkits-PAPER.pdf&lt;br /&gt;
* XSS-Proofing Your JavaEE, JSP, and JSP Applications - http://www.oracle.com/technetwork/server-storage/ts-4374-159351.pdf &lt;br /&gt;
   I'm an official [https://www.oracle.com/javaone/rock-stars/index.html#jwilliams Java Rock Star]!&lt;br /&gt;
* XSS Prevention Cheatsheet – http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&lt;br /&gt;
* Java EE ClickJack Filter - http://www.owasp.org/index.php/ClickjackFilter_for_Java_EE &lt;br /&gt;
* Enterprise Security API – http://www.owasp.org/index.php/ESAPI &lt;br /&gt;
* Application Security Verification Standard - http://www.owasp.org/index.php/ASVS &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java PDF Attack Filter - http://www.owasp.org/index.php/PDF_Attack_Filter_for_Java_EE &lt;br /&gt;
* Application Security Risk Rating Model - http://www.owasp.org/index.php/OWASP_Risk_Rating_Methodology &lt;br /&gt;
* CSRF Tester Tool - http://www.owasp.org/index.php/Category:OWASP_CSRFTester_Project &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java Stinger Validation Library - http://www.owasp.org/index.php/Category:OWASP_Stinger_Project &lt;br /&gt;
* Application Security Contract Annex - http://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex &lt;br /&gt;
* OWASP Chapters Program - http://www.owasp.org/index.php/Category:OWASP_Chapter &lt;br /&gt;
* OWASP Foundation - http://www.owasp.org/index.php/OWASP_Foundation &lt;br /&gt;
* OWASP Top Ten – http://www.owasp.org/index.php/Topten &lt;br /&gt;
* WebGoat Application Security Learning Environment - http://www.owasp.org/index.php/Webgoat &lt;br /&gt;
* Systems Security Engineering CMM - http://sse-cmm.org/index.html &lt;br /&gt;
&lt;br /&gt;
To see my wiki contributions, [[:Special:Contributions/Jeff Williams|click here]].&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
My background, from an [http://myappsecurity.blogspot.com/2007/03/reflection-on-jeff-williams.html interview]&lt;br /&gt;
&lt;br /&gt;
I set out to be a user interface guy, but I got into security accidentally. I was working at TRW in 1992 on the user interface for a big Navy system that just happened to be highly secure – targeting B2 in the Orange Book. I took on an R&amp;amp;D project to port the user interface to the new compartmented mode workstation (what became Trusted Solaris) and I found that I really liked the challenge of securing such a complex system.&lt;br /&gt;
&lt;br /&gt;
Then Java 1.0 came along and I got NIST and NRL funding to do security research. At the time, we thought the Java sandbox was a good idea, but that there were attacks that might bypass it. So I wrote a special classloader that modified the bytecode to wrap security relevant method calls with a reference monitor. After that I spent several years developing a Java-based multilevel secure network guard on Trusted Solaris. That guard handled HTTP, FTP, TDS, and a number of other protocols – sort of a very early application firewall. But unlike the modern WAFs, we took a whitelist approach where you would define exactly the data formats and rules for allowing messages.&lt;br /&gt;
&lt;br /&gt;
In the mid-90’s, I chaired the group that authored the SSE-CMM, which is now ISO 21827. As it turns out, the processes involved in systems security engineering are quite similar to those necessary for secure software development. I’m very glad to see that the idea of assurance arguments from my work is starting to be used in the application security world.&lt;br /&gt;
&lt;br /&gt;
Then in 1998, while I was the technical director of the Global Security Practice at Exodus Communications, a Fortune 10 company approached us and said “We’d like to host our applications with you, but we have this rule – every line of code has to be reviewed before it goes on the Internet.” So I started an application security practice and started providing application assessments, developer training, and help with security requirements and architecture. We built a successful practice securing some of the biggest and most complex web applications in the world.&lt;br /&gt;
&lt;br /&gt;
In April 2002, together with Dave Wichers, Noelle Hardy, and some other great folks, I started [http://aspectsecurity.com Aspect Security] to focus exclusively on application security. I just feel so fortunate to work with such an amazing group of consultants and customers. I’m having the most fun of my professional career.&lt;br /&gt;
&lt;br /&gt;
I first heard of OWASP in 2001 from Chuck Pfleeger (the author of Security in Computing). The idea of a free and open community for application security was an interesting idea. At the time, getting companies to focus on application security was difficult. In meetings with several government agencies, they acknowledged that it was an issue, but that they were managing to the SANS Top 20. I came home and literally in the shower said to myself, “I wish we had an application security top ten…” So a small team of us at Aspect took the lead in drafting the first OWASP Top Ten.&lt;br /&gt;
&lt;br /&gt;
Later, Aspect donated WebGoat, a hands-on training environment for application security issues that we had developed for our courses. A huge number of organizations, including Google, use WebGoat today to teach their developers about application security. We started to see that participation in OWASP allowed Aspect to demonstrate our skills in a very constructive way, and many of our customers have contacted us after seeing our participation in OWASP.&lt;br /&gt;
&lt;br /&gt;
I was honored to take over the leadership of OWASP in 2003. At that time, we had a number of great contributors, but OWASP itself was just a domain name and a few small projects. So I got us set up as a 501c3 nonprofit organization and put a management structure in place. I want the OWASP Foundation to provide a free, open, supportive community infrastructure for application security projects. We’re making the barriers to entry for contribution so low that security experts will be motivated to make the effort and share their expertise.&lt;br /&gt;
&lt;br /&gt;
One of the key challenges has been to ensure that OWASP is not influenced by commercial interests. When I set up the AppSec conference and local chapter rules, I made sure that vendors are cannot use OWASP to market their products. We’re also starting to ferret out abuse of the OWASP brand by companies that claim their products “address the OWASP Top Ten” or enable “OWASP Compliance.” The local chapters have been growing very quickly and starting to contribute back to the mothership. Our conferences have also been a great experience.&lt;br /&gt;
&lt;br /&gt;
I think the switch to the MediaWiki platform in 2006 was a major step for OWASP. Prior to that, contributing content was a difficult and painful process. Now, anyone can create an account and contribute easily. We have a team set up to review all the contributions and the number of abuses in our first year has been astoundingly low (less than 10 incidents). We’re to the point now where we get dozens of articles and contributions every day. I don’t see how a non-open approach to building an application security body of knowledge can possibly keep up with our productivity.&lt;br /&gt;
&lt;br /&gt;
We’re still a long way from the point where a company can go to OWASP for everything they need in order to build, acquire, and operate secure applications… but we’ve got an incredible process and we’re working very hard to get there.&lt;br /&gt;
&lt;br /&gt;
I have big family and absolutely love my kids. We live in the woods and spend a lot of time outside with our two Labrador retrievers. I’m very much into sports – I rowed on the crew team at UVA and still play basketball three times a week (if you meet me you'll know why). For a while I was into extreme rollerblading and then I got into mountain bike trials – I broke a lot of equipment, but never had any serious injuries :)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Articles / Presentations==&lt;br /&gt;
&lt;br /&gt;
Opening the Black Box: A Source Code Security Analysis Case Study&lt;br /&gt;
http://www.aspectsecurity.com/documents/Aspect_Opening_Black_Box.doc&lt;br /&gt;
&lt;br /&gt;
Application Security Initiatives - The Best Defense Is a Good Offense&lt;br /&gt;
http://www.aspectsecurity.com/documents/Application_Security_Initiatives.htm&lt;br /&gt;
&lt;br /&gt;
Let's Sue the Idiots -- Security, Software, Contracts, and Lawyers&lt;br /&gt;
http://www.aspectsecurity.com/article/sscl.htm&lt;br /&gt;
&lt;br /&gt;
How to Build an HTTP Request Validation Engine for Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/bld_HTTP_req_val_engine.htm&lt;br /&gt;
&lt;br /&gt;
Access Control (aka Authorization) in Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/access_control.htm&lt;br /&gt;
&lt;br /&gt;
Trustworthy Java - Are your apps bulletproof?&lt;br /&gt;
http://www.aspectsecurity.com/article/trust_java.htm&lt;br /&gt;
&lt;br /&gt;
The Ten Most Critical Web Application Security Vulnerabilities&lt;br /&gt;
http://www.aspectsecurity.com/owasp.htm&lt;br /&gt;
&lt;br /&gt;
Security Code Review - the Best Way to Eliminate Vulnerabilities in Software&amp;quot; -&lt;br /&gt;
http://www.aspectsecurity.com/documents/AspectCodeReviewWhitePaper.pdf&lt;br /&gt;
&lt;br /&gt;
Can a 'Social Protocol' Help Protect Privacy?&lt;br /&gt;
http://www.aspectsecurity.com/documents/p3p.pdf&lt;br /&gt;
&lt;br /&gt;
Jini and Mobile Agent Security - Proceedings of the Workshop on Agent Technologies (AT ‘98)&lt;br /&gt;
http://www.aspectsecurity.com/documents/jini.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Improving and Communicating Assurance - Proceedings of the 10th Canadian Information Technology Security Symposium (CITSS)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Arguing.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Measuring Assurance - Proceedings of the 1998 Security Applications Conference (ACSAC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Measuring.pdf&lt;br /&gt;
&lt;br /&gt;
System Security Engineering Capability Maturity Model (SSE-CMM) version 2.0 - Released at the 21st Annual National Information System Security Conference (NISSC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/SSECMMv2Final.pdf&lt;br /&gt;
&lt;br /&gt;
Just Sick about Security - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Sick.pdf&lt;br /&gt;
&lt;br /&gt;
An Enterprise Assurance Framework - Proceedings of the 5th Workshop on Enabling Technologies&lt;br /&gt;
http://www.aspectsecurity.com/documents/WetIce.pdf&lt;br /&gt;
&lt;br /&gt;
Pretty Good Assurance - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Pretty.pdf&lt;br /&gt;
&lt;br /&gt;
Need for a Framework for Reasoning about Assurance - Proceedings of the International Workshop on IT Assurance and Trustworthiness (WITAT)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Need.pdf&lt;br /&gt;
&lt;br /&gt;
Assurance is an N-Space (Where N is Hopefully Small) - Proceedings of the International Invitational Workshop on Developmental Assurance&lt;br /&gt;
http://www.aspectsecurity.com/documents/Nspace.pdf&lt;br /&gt;
&lt;br /&gt;
A Capability Maturity Model For Security Engineering - Proceedings of the 6th Annual Canadian Computer Security Symposium&lt;br /&gt;
http://www.aspectsecurity.com/documents/CITSS94.doc&lt;br /&gt;
&lt;br /&gt;
Unsafe at Any (CPU) Speed: Why We Keep Making the Same Mistakes - NSA High Confidence Software and Systems Conference&lt;br /&gt;
&lt;br /&gt;
Web Applications: The “Last Mile” of Internet Security&lt;br /&gt;
&lt;br /&gt;
A Constructionist Approach to Law and Society - Law and Society Seminar, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
Interpreting Anticircumvention (DMCA) - Advanced International Copyright Law, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
P3I – Protection Profile Process Improvement - Proceedings of the 22nd National Information System Security Conference (NISSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Security - 17th Annual National Computer Security Conference (NCSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Client Security and Windows NTAS Security - The Local Area Network Security Conference (LANSEC)&lt;br /&gt;
&lt;br /&gt;
Reusing Existing C3I Systems in a Secure Environment - Proceedings of the Application of COTS and Reusable Components Conference&lt;br /&gt;
&lt;br /&gt;
A Framework for Reasoning about Assurance - Published by the National Computer Security Center of the NSA&lt;br /&gt;
Proceedings of the 11th Annual Conference on Computer Assurance (COMPASS)&lt;br /&gt;
&lt;br /&gt;
Interconnecting MLS Command Centers - White paper for the Multilevel Security Initiative at Hanscomb AFB&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Education==&lt;br /&gt;
&lt;br /&gt;
* JD cum laude – Georgetown Law - Cyberlaw and Intellectual Property&lt;br /&gt;
* MA – George Mason - Human Factors Engineering&lt;br /&gt;
* BA – University of Virginia - Cognitive Psychology and Computer Science (Specialization in AI)&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=201595</id>
		<title>User:Jeff Williams</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=201595"/>
				<updated>2015-10-04T20:48:45Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm Jeff Williams, I'm the CTO of both [http://contrastsecurity.com Contrast Security]. I helped found OWASP, created the OWASP Foundation 501c3, and served as the volunteer Chair of the OWASP Foundation from 2003 to 2012. I’ve dedicated my life to trying to make the world’s software more secure, and so I create lots of free and open tools, libraries, guidance, and standards to try to change the status quo. Thank you all for your dedication to application security and your participation in OWASP. Please send any questions or comments to me via email at [mailto:jeff.williams@contrastsecurity.com jeff.williams@contrastsecurity.com]. Or you can twitter @planetlevel.&lt;br /&gt;
&lt;br /&gt;
last revised {{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}&lt;br /&gt;
&lt;br /&gt;
I'm particularly proud of this free tool that uses instrumentation to find vulnerabilities. Far easier to use and more accurate than static (SAST) or dynamic analysis (DAST) scanners.&lt;br /&gt;
* FREE tool - Contrast for Eclipse - http://marketplace.eclipse.org/content/contrast-eclipse &lt;br /&gt;
&lt;br /&gt;
Also please read the &amp;quot;Continuous Security Handbook&amp;quot; which reinterprets application security for high-speed DevOps environments.&lt;br /&gt;
* FREE CAS Handbook - http://www1.contrastsecurity.com/continuous-app-security&lt;br /&gt;
&lt;br /&gt;
Some of my other work (in roughly reverse chronological order)&lt;br /&gt;
* Enterprise Java Rootkits - https://www.blackhat.com/presentations/bh-usa-09/WILLIAMS/BHUSA09-Williams-EnterpriseJavaRootkits-PAPER.pdf&lt;br /&gt;
* XSS-Proofing Your JavaEE, JSP, and JSP Applications - http://www.oracle.com/technetwork/server-storage/ts-4374-159351.pdf &lt;br /&gt;
   I'm an official [https://www.oracle.com/javaone/rock-stars/index.html#jwilliams Java Rock Star]!&lt;br /&gt;
* XSS Prevention Cheatsheet – http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&lt;br /&gt;
* Java EE ClickJack Filter - http://www.owasp.org/index.php/ClickjackFilter_for_Java_EE &lt;br /&gt;
* Enterprise Security API – http://www.owasp.org/index.php/ESAPI &lt;br /&gt;
* Application Security Verification Standard - http://www.owasp.org/index.php/ASVS &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java PDF Attack Filter - http://www.owasp.org/index.php/PDF_Attack_Filter_for_Java_EE &lt;br /&gt;
* Application Security Risk Rating Model - http://www.owasp.org/index.php/OWASP_Risk_Rating_Methodology &lt;br /&gt;
* CSRF Tester Tool - http://www.owasp.org/index.php/Category:OWASP_CSRFTester_Project &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java Stinger Validation Library - http://www.owasp.org/index.php/Category:OWASP_Stinger_Project &lt;br /&gt;
* Application Security Contract Annex - http://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex &lt;br /&gt;
* OWASP Chapters Program - http://www.owasp.org/index.php/Category:OWASP_Chapter &lt;br /&gt;
* OWASP Foundation - http://www.owasp.org/index.php/OWASP_Foundation &lt;br /&gt;
* OWASP Top Ten – http://www.owasp.org/index.php/Topten &lt;br /&gt;
* WebGoat Application Security Learning Environment - http://www.owasp.org/index.php/Webgoat &lt;br /&gt;
* Systems Security Engineering CMM - http://sse-cmm.org/index.html &lt;br /&gt;
&lt;br /&gt;
To see my wiki contributions, [[:Special:Contributions/Jeff Williams|click here]].&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
My background, from an [http://myappsecurity.blogspot.com/2007/03/reflection-on-jeff-williams.html interview]&lt;br /&gt;
&lt;br /&gt;
I set out to be a user interface guy, but I got into security accidentally. I was working at TRW in 1992 on the user interface for a big Navy system that just happened to be highly secure – targeting B2 in the Orange Book. I took on an R&amp;amp;D project to port the user interface to the new compartmented mode workstation (what became Trusted Solaris) and I found that I really liked the challenge of securing such a complex system.&lt;br /&gt;
&lt;br /&gt;
Then Java 1.0 came along and I got NIST and NRL funding to do security research. At the time, we thought the Java sandbox was a good idea, but that there were attacks that might bypass it. So I wrote a special classloader that modified the bytecode to wrap security relevant method calls with a reference monitor. After that I spent several years developing a Java-based multilevel secure network guard on Trusted Solaris. That guard handled HTTP, FTP, TDS, and a number of other protocols – sort of a very early application firewall. But unlike the modern WAFs, we took a whitelist approach where you would define exactly the data formats and rules for allowing messages.&lt;br /&gt;
&lt;br /&gt;
In the mid-90’s, I chaired the group that authored the SSE-CMM, which is now ISO 21827. As it turns out, the processes involved in systems security engineering are quite similar to those necessary for secure software development. I’m very glad to see that the idea of assurance arguments from my work is starting to be used in the application security world.&lt;br /&gt;
&lt;br /&gt;
Then in 1998, while I was the technical director of the Global Security Practice at Exodus Communications, a Fortune 10 company approached us and said “We’d like to host our applications with you, but we have this rule – every line of code has to be reviewed before it goes on the Internet.” So I started an application security practice and started providing application assessments, developer training, and help with security requirements and architecture. We built a successful practice securing some of the biggest and most complex web applications in the world.&lt;br /&gt;
&lt;br /&gt;
In April 2002, together with Dave Wichers, Noelle Hardy, and some other great folks, I started [http://aspectsecurity.com Aspect Security] to focus exclusively on application security. I just feel so fortunate to work with such an amazing group of consultants and customers. I’m having the most fun of my professional career.&lt;br /&gt;
&lt;br /&gt;
I first heard of OWASP in 2001 from Chuck Pfleeger (the author of Security in Computing). The idea of a free and open community for application security was an interesting idea. At the time, getting companies to focus on application security was difficult. In meetings with several government agencies, they acknowledged that it was an issue, but that they were managing to the SANS Top 20. I came home and literally in the shower said to myself, “I wish we had an application security top ten…” So a small team of us at Aspect took the lead in drafting the first OWASP Top Ten.&lt;br /&gt;
&lt;br /&gt;
Later, Aspect donated WebGoat, a hands-on training environment for application security issues that we had developed for our courses. A huge number of organizations, including Google, use WebGoat today to teach their developers about application security. We started to see that participation in OWASP allowed Aspect to demonstrate our skills in a very constructive way, and many of our customers have contacted us after seeing our participation in OWASP.&lt;br /&gt;
&lt;br /&gt;
I was honored to take over the leadership of OWASP in 2003. At that time, we had a number of great contributors, but OWASP itself was just a domain name and a few small projects. So I got us set up as a 501c3 nonprofit organization and put a management structure in place. I want the OWASP Foundation to provide a free, open, supportive community infrastructure for application security projects. We’re making the barriers to entry for contribution so low that security experts will be motivated to make the effort and share their expertise.&lt;br /&gt;
&lt;br /&gt;
One of the key challenges has been to ensure that OWASP is not influenced by commercial interests. When I set up the AppSec conference and local chapter rules, I made sure that vendors are cannot use OWASP to market their products. We’re also starting to ferret out abuse of the OWASP brand by companies that claim their products “address the OWASP Top Ten” or enable “OWASP Compliance.” The local chapters have been growing very quickly and starting to contribute back to the mothership. Our conferences have also been a great experience.&lt;br /&gt;
&lt;br /&gt;
I think the switch to the MediaWiki platform in 2006 was a major step for OWASP. Prior to that, contributing content was a difficult and painful process. Now, anyone can create an account and contribute easily. We have a team set up to review all the contributions and the number of abuses in our first year has been astoundingly low (less than 10 incidents). We’re to the point now where we get dozens of articles and contributions every day. I don’t see how a non-open approach to building an application security body of knowledge can possibly keep up with our productivity.&lt;br /&gt;
&lt;br /&gt;
We’re still a long way from the point where a company can go to OWASP for everything they need in order to build, acquire, and operate secure applications… but we’ve got an incredible process and we’re working very hard to get there.&lt;br /&gt;
&lt;br /&gt;
I have big family and absolutely love my kids. We live in the woods and spend a lot of time outside with our two Labrador retrievers. I’m very much into sports – I rowed on the crew team at UVA and still play basketball three times a week (if you meet me you'll know why). For a while I was into extreme rollerblading and then I got into mountain bike trials – I broke a lot of equipment, but never had any serious injuries :)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Articles / Presentations==&lt;br /&gt;
&lt;br /&gt;
Opening the Black Box: A Source Code Security Analysis Case Study&lt;br /&gt;
http://www.aspectsecurity.com/documents/Aspect_Opening_Black_Box.doc&lt;br /&gt;
&lt;br /&gt;
Application Security Initiatives - The Best Defense Is a Good Offense&lt;br /&gt;
http://www.aspectsecurity.com/documents/Application_Security_Initiatives.htm&lt;br /&gt;
&lt;br /&gt;
Let's Sue the Idiots -- Security, Software, Contracts, and Lawyers&lt;br /&gt;
http://www.aspectsecurity.com/article/sscl.htm&lt;br /&gt;
&lt;br /&gt;
How to Build an HTTP Request Validation Engine for Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/bld_HTTP_req_val_engine.htm&lt;br /&gt;
&lt;br /&gt;
Access Control (aka Authorization) in Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/access_control.htm&lt;br /&gt;
&lt;br /&gt;
Trustworthy Java - Are your apps bulletproof?&lt;br /&gt;
http://www.aspectsecurity.com/article/trust_java.htm&lt;br /&gt;
&lt;br /&gt;
The Ten Most Critical Web Application Security Vulnerabilities&lt;br /&gt;
http://www.aspectsecurity.com/owasp.htm&lt;br /&gt;
&lt;br /&gt;
Security Code Review - the Best Way to Eliminate Vulnerabilities in Software&amp;quot; -&lt;br /&gt;
http://www.aspectsecurity.com/documents/AspectCodeReviewWhitePaper.pdf&lt;br /&gt;
&lt;br /&gt;
Can a 'Social Protocol' Help Protect Privacy?&lt;br /&gt;
http://www.aspectsecurity.com/documents/p3p.pdf&lt;br /&gt;
&lt;br /&gt;
Jini and Mobile Agent Security - Proceedings of the Workshop on Agent Technologies (AT ‘98)&lt;br /&gt;
http://www.aspectsecurity.com/documents/jini.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Improving and Communicating Assurance - Proceedings of the 10th Canadian Information Technology Security Symposium (CITSS)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Arguing.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Measuring Assurance - Proceedings of the 1998 Security Applications Conference (ACSAC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Measuring.pdf&lt;br /&gt;
&lt;br /&gt;
System Security Engineering Capability Maturity Model (SSE-CMM) version 2.0 - Released at the 21st Annual National Information System Security Conference (NISSC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/SSECMMv2Final.pdf&lt;br /&gt;
&lt;br /&gt;
Just Sick about Security - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Sick.pdf&lt;br /&gt;
&lt;br /&gt;
An Enterprise Assurance Framework - Proceedings of the 5th Workshop on Enabling Technologies&lt;br /&gt;
http://www.aspectsecurity.com/documents/WetIce.pdf&lt;br /&gt;
&lt;br /&gt;
Pretty Good Assurance - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Pretty.pdf&lt;br /&gt;
&lt;br /&gt;
Need for a Framework for Reasoning about Assurance - Proceedings of the International Workshop on IT Assurance and Trustworthiness (WITAT)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Need.pdf&lt;br /&gt;
&lt;br /&gt;
Assurance is an N-Space (Where N is Hopefully Small) - Proceedings of the International Invitational Workshop on Developmental Assurance&lt;br /&gt;
http://www.aspectsecurity.com/documents/Nspace.pdf&lt;br /&gt;
&lt;br /&gt;
A Capability Maturity Model For Security Engineering - Proceedings of the 6th Annual Canadian Computer Security Symposium&lt;br /&gt;
http://www.aspectsecurity.com/documents/CITSS94.doc&lt;br /&gt;
&lt;br /&gt;
Unsafe at Any (CPU) Speed: Why We Keep Making the Same Mistakes - NSA High Confidence Software and Systems Conference&lt;br /&gt;
&lt;br /&gt;
Web Applications: The “Last Mile” of Internet Security&lt;br /&gt;
&lt;br /&gt;
A Constructionist Approach to Law and Society - Law and Society Seminar, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
Interpreting Anticircumvention (DMCA) - Advanced International Copyright Law, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
P3I – Protection Profile Process Improvement - Proceedings of the 22nd National Information System Security Conference (NISSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Security - 17th Annual National Computer Security Conference (NCSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Client Security and Windows NTAS Security - The Local Area Network Security Conference (LANSEC)&lt;br /&gt;
&lt;br /&gt;
Reusing Existing C3I Systems in a Secure Environment - Proceedings of the Application of COTS and Reusable Components Conference&lt;br /&gt;
&lt;br /&gt;
A Framework for Reasoning about Assurance - Published by the National Computer Security Center of the NSA&lt;br /&gt;
Proceedings of the 11th Annual Conference on Computer Assurance (COMPASS)&lt;br /&gt;
&lt;br /&gt;
Interconnecting MLS Command Centers - White paper for the Multilevel Security Initiative at Hanscomb AFB&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Education==&lt;br /&gt;
&lt;br /&gt;
* JD cum laude – Georgetown Law - Cyberlaw and Intellectual Property&lt;br /&gt;
* MA – George Mason - Human Factors Engineering&lt;br /&gt;
* BA – University of Virginia - Cognitive Psychology and Computer Science (Specialization in AI)&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=188248</id>
		<title>User:Jeff Williams</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=188248"/>
				<updated>2015-01-19T18:35:41Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm Jeff Williams, I'm the CTO of both [http://contrastsecurity.com Contrast Security] and [http://aspectsecurity.com Aspect Security]. I helped found OWASP, created the OWASP Foundation 501c3, and served as the volunteer Chair of the OWASP Foundation from 2003 to 2012. I’ve dedicated my life to trying to make the world’s software more secure, and so I create lots of free and open tools, libraries, guidance, and standards to try to change the status quo. Thank you all for your dedication to application security and your participation in OWASP. Please send any questions or comments to me via email at [mailto:jeff.williams@contrastsecurity.com jeff.williams@contrastsecurity.com]. Or you can twitter @planetlevel.&lt;br /&gt;
&lt;br /&gt;
last revised {{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}&lt;br /&gt;
&lt;br /&gt;
I'm particularly proud of this free tool that uses instrumentation to find vulnerabilities. Far easier to use and more accurate than static (SAST) or dynamic analysis (DAST) scanners.&lt;br /&gt;
* FREE tool - Contrast for Eclipse - http://marketplace.eclipse.org/content/contrast-eclipse &lt;br /&gt;
&lt;br /&gt;
Also please read the &amp;quot;Continuous Security Handbook&amp;quot; which reinterprets application security for high-speed DevOps environments.&lt;br /&gt;
* FREE CAS Handbook - http://www1.contrastsecurity.com/continuous-app-security&lt;br /&gt;
&lt;br /&gt;
Some of my other work (in roughly reverse chronological order)&lt;br /&gt;
* Enterprise Java Rootkits - https://www.blackhat.com/presentations/bh-usa-09/WILLIAMS/BHUSA09-Williams-EnterpriseJavaRootkits-PAPER.pdf&lt;br /&gt;
* XSS-Proofing Your JavaEE, JSP, and JSP Applications - http://www.oracle.com/technetwork/server-storage/ts-4374-159351.pdf &lt;br /&gt;
   I'm an official [https://www.oracle.com/javaone/rock-stars/index.html#jwilliams Java Rock Star]!&lt;br /&gt;
* XSS Prevention Cheatsheet – http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&lt;br /&gt;
* Java EE ClickJack Filter - http://www.owasp.org/index.php/ClickjackFilter_for_Java_EE &lt;br /&gt;
* Enterprise Security API – http://www.owasp.org/index.php/ESAPI &lt;br /&gt;
* Application Security Verification Standard - http://www.owasp.org/index.php/ASVS &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java PDF Attack Filter - http://www.owasp.org/index.php/PDF_Attack_Filter_for_Java_EE &lt;br /&gt;
* Application Security Risk Rating Model - http://www.owasp.org/index.php/OWASP_Risk_Rating_Methodology &lt;br /&gt;
* CSRF Tester Tool - http://www.owasp.org/index.php/Category:OWASP_CSRFTester_Project &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java Stinger Validation Library - http://www.owasp.org/index.php/Category:OWASP_Stinger_Project &lt;br /&gt;
* Application Security Contract Annex - http://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex &lt;br /&gt;
* OWASP Chapters Program - http://www.owasp.org/index.php/Category:OWASP_Chapter &lt;br /&gt;
* OWASP Foundation - http://www.owasp.org/index.php/OWASP_Foundation &lt;br /&gt;
* OWASP Top Ten – http://www.owasp.org/index.php/Topten &lt;br /&gt;
* WebGoat Application Security Learning Environment - http://www.owasp.org/index.php/Webgoat &lt;br /&gt;
* Systems Security Engineering CMM - http://sse-cmm.org/index.html &lt;br /&gt;
&lt;br /&gt;
To see my wiki contributions, [[:Special:Contributions/Jeff Williams|click here]].&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
My background, from an [http://myappsecurity.blogspot.com/2007/03/reflection-on-jeff-williams.html interview]&lt;br /&gt;
&lt;br /&gt;
I set out to be a user interface guy, but I got into security accidentally. I was working at TRW in 1992 on the user interface for a big Navy system that just happened to be highly secure – targeting B2 in the Orange Book. I took on an R&amp;amp;D project to port the user interface to the new compartmented mode workstation (what became Trusted Solaris) and I found that I really liked the challenge of securing such a complex system.&lt;br /&gt;
&lt;br /&gt;
Then Java 1.0 came along and I got NIST and NRL funding to do security research. At the time, we thought the Java sandbox was a good idea, but that there were attacks that might bypass it. So I wrote a special classloader that modified the bytecode to wrap security relevant method calls with a reference monitor. After that I spent several years developing a Java-based multilevel secure network guard on Trusted Solaris. That guard handled HTTP, FTP, TDS, and a number of other protocols – sort of a very early application firewall. But unlike the modern WAFs, we took a whitelist approach where you would define exactly the data formats and rules for allowing messages.&lt;br /&gt;
&lt;br /&gt;
In the mid-90’s, I chaired the group that authored the SSE-CMM, which is now ISO 21827. As it turns out, the processes involved in systems security engineering are quite similar to those necessary for secure software development. I’m very glad to see that the idea of assurance arguments from my work is starting to be used in the application security world.&lt;br /&gt;
&lt;br /&gt;
Then in 1998, while I was the technical director of the Global Security Practice at Exodus Communications, a Fortune 10 company approached us and said “We’d like to host our applications with you, but we have this rule – every line of code has to be reviewed before it goes on the Internet.” So I started an application security practice and started providing application assessments, developer training, and help with security requirements and architecture. We built a successful practice securing some of the biggest and most complex web applications in the world.&lt;br /&gt;
&lt;br /&gt;
In April 2002, together with Dave Wichers, Noelle Hardy, and some other great folks, I started Aspect Security to focus exclusively on application security. I just feel so fortunate to get to work with such an amazing group of consultants and customers. I’m having the most fun of my professional career.&lt;br /&gt;
&lt;br /&gt;
I first heard of OWASP in 2001 from Chuck Pfleeger (the author of Security in Computing). The idea of a free and open community for application security was an interesting idea. At the time, getting companies to focus on application security was difficult. In meetings with several government agencies, they acknowledged that it was an issue, but that they were managing to the SANS Top 20. I came home and literally in the shower said to myself, “I wish we had an application security top ten…” So a small team of us at Aspect took the lead in drafting the first OWASP Top Ten.&lt;br /&gt;
&lt;br /&gt;
Later, Aspect donated WebGoat, a hands-on training environment for application security issues that we had developed for our courses. A huge number of organizations, including Google, use WebGoat today to teach their developers about application security. We started to see that participation in OWASP allowed Aspect to demonstrate our skills in a very constructive way, and many of our customers have contacted us after seeing our participation in OWASP.&lt;br /&gt;
&lt;br /&gt;
I was honored to take over the leadership of OWASP in 2003. At that time, we had a number of great contributors, but OWASP itself was just a domain name and a few small projects. So I got us set up as a 501c3 nonprofit organization and put a management structure in place. I want the OWASP Foundation to provide a free, open, supportive community infrastructure for application security projects. We’re making the barriers to entry for contribution so low that security experts will be motivated to make the effort and share their expertise.&lt;br /&gt;
&lt;br /&gt;
One of the key challenges has been to ensure that OWASP is not influenced by commercial interests. When I set up the AppSec conference and local chapter rules, I made sure that vendors are cannot use OWASP to market their products. We’re also starting to ferret out abuse of the OWASP brand by companies that claim their products “address the OWASP Top Ten” or enable “OWASP Compliance.” The local chapters have been growing very quickly and starting to contribute back to the mothership. Our conferences have also been a great experience.&lt;br /&gt;
&lt;br /&gt;
I think the switch to the MediaWiki platform in 2006 was a major step for OWASP. Prior to that, contributing content was a difficult and painful process. Now, anyone can create an account and contribute easily. We have a team set up to review all the contributions and the number of abuses in our first year has been astoundingly low (less than 10 incidents). We’re to the point now where we get dozens of articles and contributions every day. I don’t see how a non-open approach to building an application security body of knowledge can possibly keep up with our productivity.&lt;br /&gt;
&lt;br /&gt;
We’re still a long way from the point where a company can go to OWASP for everything they need in order to build, acquire, and operate secure applications… but we’ve got an incredible process and we’re working very hard to get there.&lt;br /&gt;
&lt;br /&gt;
I have big family and absolutely love my kids. We live in the woods and spend a lot of time outside with our two Labrador retrievers. I’m very much into sports – I rowed on the crew team at UVA and still play basketball three times a week (if you meet me you'll know why). For a while I was into extreme rollerblading and then I got into mountain bike trials – I broke a lot of equipment, but never had any serious injuries :)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Articles / Presentations==&lt;br /&gt;
&lt;br /&gt;
Opening the Black Box: A Source Code Security Analysis Case Study&lt;br /&gt;
http://www.aspectsecurity.com/documents/Aspect_Opening_Black_Box.doc&lt;br /&gt;
&lt;br /&gt;
Application Security Initiatives - The Best Defense Is a Good Offense&lt;br /&gt;
http://www.aspectsecurity.com/documents/Application_Security_Initiatives.htm&lt;br /&gt;
&lt;br /&gt;
Let's Sue the Idiots -- Security, Software, Contracts, and Lawyers&lt;br /&gt;
http://www.aspectsecurity.com/article/sscl.htm&lt;br /&gt;
&lt;br /&gt;
How to Build an HTTP Request Validation Engine for Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/bld_HTTP_req_val_engine.htm&lt;br /&gt;
&lt;br /&gt;
Access Control (aka Authorization) in Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/access_control.htm&lt;br /&gt;
&lt;br /&gt;
Trustworthy Java - Are your apps bulletproof?&lt;br /&gt;
http://www.aspectsecurity.com/article/trust_java.htm&lt;br /&gt;
&lt;br /&gt;
The Ten Most Critical Web Application Security Vulnerabilities&lt;br /&gt;
http://www.aspectsecurity.com/owasp.htm&lt;br /&gt;
&lt;br /&gt;
Security Code Review - the Best Way to Eliminate Vulnerabilities in Software&amp;quot; -&lt;br /&gt;
http://www.aspectsecurity.com/documents/AspectCodeReviewWhitePaper.pdf&lt;br /&gt;
&lt;br /&gt;
Can a 'Social Protocol' Help Protect Privacy?&lt;br /&gt;
http://www.aspectsecurity.com/documents/p3p.pdf&lt;br /&gt;
&lt;br /&gt;
Jini and Mobile Agent Security - Proceedings of the Workshop on Agent Technologies (AT ‘98)&lt;br /&gt;
http://www.aspectsecurity.com/documents/jini.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Improving and Communicating Assurance - Proceedings of the 10th Canadian Information Technology Security Symposium (CITSS)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Arguing.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Measuring Assurance - Proceedings of the 1998 Security Applications Conference (ACSAC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Measuring.pdf&lt;br /&gt;
&lt;br /&gt;
System Security Engineering Capability Maturity Model (SSE-CMM) version 2.0 - Released at the 21st Annual National Information System Security Conference (NISSC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/SSECMMv2Final.pdf&lt;br /&gt;
&lt;br /&gt;
Just Sick about Security - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Sick.pdf&lt;br /&gt;
&lt;br /&gt;
An Enterprise Assurance Framework - Proceedings of the 5th Workshop on Enabling Technologies&lt;br /&gt;
http://www.aspectsecurity.com/documents/WetIce.pdf&lt;br /&gt;
&lt;br /&gt;
Pretty Good Assurance - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Pretty.pdf&lt;br /&gt;
&lt;br /&gt;
Need for a Framework for Reasoning about Assurance - Proceedings of the International Workshop on IT Assurance and Trustworthiness (WITAT)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Need.pdf&lt;br /&gt;
&lt;br /&gt;
Assurance is an N-Space (Where N is Hopefully Small) - Proceedings of the International Invitational Workshop on Developmental Assurance&lt;br /&gt;
http://www.aspectsecurity.com/documents/Nspace.pdf&lt;br /&gt;
&lt;br /&gt;
A Capability Maturity Model For Security Engineering - Proceedings of the 6th Annual Canadian Computer Security Symposium&lt;br /&gt;
http://www.aspectsecurity.com/documents/CITSS94.doc&lt;br /&gt;
&lt;br /&gt;
Unsafe at Any (CPU) Speed: Why We Keep Making the Same Mistakes - NSA High Confidence Software and Systems Conference&lt;br /&gt;
&lt;br /&gt;
Web Applications: The “Last Mile” of Internet Security&lt;br /&gt;
&lt;br /&gt;
A Constructionist Approach to Law and Society - Law and Society Seminar, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
Interpreting Anticircumvention (DMCA) - Advanced International Copyright Law, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
P3I – Protection Profile Process Improvement - Proceedings of the 22nd National Information System Security Conference (NISSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Security - 17th Annual National Computer Security Conference (NCSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Client Security and Windows NTAS Security - The Local Area Network Security Conference (LANSEC)&lt;br /&gt;
&lt;br /&gt;
Reusing Existing C3I Systems in a Secure Environment - Proceedings of the Application of COTS and Reusable Components Conference&lt;br /&gt;
&lt;br /&gt;
A Framework for Reasoning about Assurance - Published by the National Computer Security Center of the NSA&lt;br /&gt;
Proceedings of the 11th Annual Conference on Computer Assurance (COMPASS)&lt;br /&gt;
&lt;br /&gt;
Interconnecting MLS Command Centers - White paper for the Multilevel Security Initiative at Hanscomb AFB&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Education==&lt;br /&gt;
&lt;br /&gt;
* JD cum laude – Georgetown Law - Cyberlaw and Intellectual Property&lt;br /&gt;
* MA – George Mason - Human Factors Engineering&lt;br /&gt;
* BA – University of Virginia - Cognitive Psychology and Computer Science (Specialization in AI)&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=185317</id>
		<title>How to write insecure code</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=185317"/>
				<updated>2014-11-12T20:46:03Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
&lt;br /&gt;
=HOW TO WRITE INSECURE CODE=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
In the interest of ensuring that there will be a future for hackers, criminals, and others who want to destroy the digital future, this paper captures tips from the masters on how to create insecure code. With a little creative use of these tips, you can also ensure your own financial future. Be careful, you don't want to make your code look hopelessly insecure, or your insecurity may be uncovered and fixed.&lt;br /&gt;
&lt;br /&gt;
The idea for this article comes from Roedy Green's [http://mindprod.com/jgloss/unmain.html How to write unmaintainable code]. You may find the [http://thc.org/root/phun/unmaintain.html one page version more readable]. Actually, making your code unmaintainable is a great first step towards making it insecure and there are some great ideas in this article, particularly the section on camouflage. Also many thanks to Steven Christey from MITRE who contributed a bunch of particularly insecure items.&lt;br /&gt;
&lt;br /&gt;
''Special note for the slow to pick up on irony set. This essay is a '''joke'''! Developers and architects are often bored with lectures about how to write '''secure''' code. Perhaps this is another way to get the point across.''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Use this format for adding items to the list&lt;br /&gt;
; '''Title'''&lt;br /&gt;
: Details&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==General Principles==&lt;br /&gt;
&lt;br /&gt;
; '''Avoid the tools'''&lt;br /&gt;
: To ensure an application is forever insecure, you have to think about how security vulnerabilities are identified and remediated. Many software teams believe that automated tools can solve their security problems. So if you want to ensure vulnerabilities, simply make them difficult for automated tools to find. This is a lot easier than it sounds. All you have to do is make sure your vulnerabilities don't match anything in the tool's database of signatures. Your code can be as complex as you want, so it's pretty easy to avoid getting found. In fact, most inadvertent vulnerabilities can't be found by tools anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Always use default deny'''&lt;br /&gt;
: Apply the principle of &amp;quot;Default Deny&amp;quot; when building your application. Deny that your code can ever be broken, deny vulnerabilities until there's a proven exploit, deny to your customers that there was ever anything wrong, and above all - deny responsibility for flaws. Blame the dirty cache buffers.&lt;br /&gt;
&lt;br /&gt;
; '''Be a shark'''&lt;br /&gt;
: Always be on the move.  Leave security problems to operations staff.&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
&lt;br /&gt;
; '''Distribute security mechanisms'''&lt;br /&gt;
: Security checks should be designed so that they are as distributed as possible throughout the codebase. Try not to follow a consistent pattern and don't make it easy to find all the places where the mechanism is used. This will virtually ensure that security is implemented inconsistently.&lt;br /&gt;
&lt;br /&gt;
; '''Spread the wealth'''&lt;br /&gt;
: Another great way to avoid being found is to make sure your security holes aren't located in one place in your code. It's very difficult for analysts to keep all of your code in their head, so by spreading out the holes you prevent anyone from finding or understanding them.&lt;br /&gt;
&lt;br /&gt;
; '''Use dynamic code'''&lt;br /&gt;
: The single best way to make it difficult for a security analyst (or security tool for that matter) to follow through an application and uncover a flaw is to use dynamic code. It can be almost impossible to trace the flow through code that is loaded at runtime. Features like reflection and classloading are beautiful features for hiding vulnerabilities. Enable as many &amp;quot;plugin&amp;quot; points as possible.&lt;br /&gt;
&lt;br /&gt;
==Secure Languages==&lt;br /&gt;
&lt;br /&gt;
; '''Type safety'''&lt;br /&gt;
: Means anything you enter at the keyboard is secure.&lt;br /&gt;
&lt;br /&gt;
; '''Secure languages'''&lt;br /&gt;
: Pick only programming languages that are completely safe and don't require any security knowledge or special programming to secure.&lt;br /&gt;
&lt;br /&gt;
; '''Mix languages'''&lt;br /&gt;
: Different languages have different security rules, so the more languages you include the more difficult it will be to learn them all. It's hard enough for development teams to even understand the security ramifications of one language, much less three or four. You can use the transitions between languages to hide vulnerabilities too.&lt;br /&gt;
&lt;br /&gt;
==Trust Relationships==&lt;br /&gt;
&lt;br /&gt;
; '''Rely on security checks done elsewhere'''&lt;br /&gt;
: It's redundant to do security checks twice, so if someone else says that they've done a check, there's no point in doing it again. When possible, it's probably best to just assume that others are doing security right, and not waste time doing it yourself. Web services and other service interfaces are generally pretty secure, so don't bother checking what you send or what they return.&lt;br /&gt;
&lt;br /&gt;
; '''Trust insiders'''&lt;br /&gt;
: Malicious input only comes from the Internet, and you can trust that all the data in your databases is perfectly validated, encoded, and sanitized for your purposes.&lt;br /&gt;
&lt;br /&gt;
; '''Code wants to be free!'''&lt;br /&gt;
: Drop your source code into repositories that are accessible by all within the company.  This also prevents having to email those hard-coded shared secrets around.&lt;br /&gt;
&lt;br /&gt;
==Logging==&lt;br /&gt;
&lt;br /&gt;
; '''Use your logs for debugging'''&lt;br /&gt;
: Nobody will be able to trace attacks on your code if you fill up the logs with debugging nonsense. Extra points for making your log messages undecipherable by anyone except you. Even more points if the log messages look as though they might be security relevant.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use a logging framework'''&lt;br /&gt;
: The best approach to logging is just to write to stdout, or maybe to a file. Logging frameworks make the logs too easy to search and manage to be sure that nobody will ever review them.&lt;br /&gt;
&lt;br /&gt;
==Encryption==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own encryption scheme'''&lt;br /&gt;
: The standard encryption mechanisms are way too complicated to use. It's much easier to make up an encryption algorithm that scrambles up secret stuff. You don't need to bother with a key or anything, just mix it all up and nobody will figure it out.&lt;br /&gt;
&lt;br /&gt;
; '''Hard-code your keys'''&lt;br /&gt;
: Hard-coding is the best way to retain control. This way those pesky operations folks won't be able to monkey with (they say &amp;quot;rotate&amp;quot;) the keys, and they'll be locked into the source code where only smart people can understand them.  This will also make it easier to move from environment to environment as the hard-coded key will be the same everywhere.  This in turn means your code is secure everywhere.&lt;br /&gt;
&lt;br /&gt;
; '''Smart coders don't read manuals'''&lt;br /&gt;
: Just keep adding bytes until the algorithm stops throwing exceptions.  Or just save yourself time and cut-and-paste from a popular coding site.  This looks like a good start: byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };&lt;br /&gt;
&lt;br /&gt;
; '''Pack up your sensitive payload'''&lt;br /&gt;
: If you need to pass things that are sensitive, like passwords or PII, just pack it up in an encrypted blob.  Then just email the key to the developer who is coding the other side of the transaction, and punch out early.  This will also get you past Data Loss Prevention (DLP) tools which is a huge bonus.&lt;br /&gt;
&lt;br /&gt;
; '''Encryption is hard'''&lt;br /&gt;
: A great way to improve the security posture of your site is to use client-side JavaScript to encrypt passwords and other sensitive data that are submitted.  This can be used with or without HTTPS (TLS/SSL).  If you use it without HTTPS, you can save some money by skipping the annual purchase of a signed third party certificate.&lt;br /&gt;
&lt;br /&gt;
; '''HTTPS makes your application bullet proof'''&lt;br /&gt;
: If you use HTTPS encryption between your web application endpoint and the client, there is absolutely no way for anyone to steal any of the data that is transmitted.&lt;br /&gt;
&lt;br /&gt;
==Authentication==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own authentication scheme'''&lt;br /&gt;
: Authentication is simple, so just use your common sense and implement. Don't worry about esoteric stuff you hear about like session prediction, hashing credentials, brute force attacks, and so on. Only NSA eggheads could possibly ever figure that stuff out. And if users want to choose weak passwords, that's their own fault.&lt;br /&gt;
&lt;br /&gt;
; '''Sessions are inherently secure'''&lt;br /&gt;
: Sessions timeout after 20 minutes, so don't worry about them. You can put the SESSIONID in the URL, log files, or wherever else you feel like. What could an attacker do with a SESSIONID anyway? It's just a bunch of random letters and numbers.&lt;br /&gt;
&lt;br /&gt;
; '''Single Sign-On is easy'''&lt;br /&gt;
: If you need to submit a username and password (or other secret knocks) from one site to another, pack it up in an encrypted blob as above.  This way if anyone finds the blob, they'll have a heck of a time decrypting it, which is what they'll need to do to be able to encrypt it again and create the blob themselves.&lt;br /&gt;
: A one-way hash cannot be decrypted.  Therefore, this is a way to take the latter approach and make it unbreakable.&lt;br /&gt;
&lt;br /&gt;
==Authorization==&lt;br /&gt;
&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think there's a difference between authentication and authorization.&lt;br /&gt;
&lt;br /&gt;
; '''Just let your authorization scheme evolve'''&lt;br /&gt;
: It's really hard to figure out all the access control rules for your application, so use a '''just in time''' development methodology. This way you can just code up new rules when you figure them out. If you end up with hundreds or thousands of lines of authorization code scattered throughout your application, you're on the right track.&lt;br /&gt;
&lt;br /&gt;
; '''Privilege makes code just work'''&lt;br /&gt;
: Using the highest privilege levels makes your product easier to install and run.&lt;br /&gt;
&lt;br /&gt;
; '''Optimize the developer... always'''&lt;br /&gt;
: Each developer, independent of one another, must decide where authorization decision and enforcement is made.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: RIA clients and fat clients that use remote services can make decisions about what the end-user can or can't see.&lt;br /&gt;
&lt;br /&gt;
; '''Volunteer to authorize access to other systems'''&lt;br /&gt;
: When a service you are calling, for example, has inappropriate access controls just be nice and live with it.  After all it will be your fault when a direct object reference permits any user of your system to see any data on their service.  Should that happen, it will be a chance for you to show your dedication when you're up at 3 AM on a Saturday morning sorting out a breach.&lt;br /&gt;
&lt;br /&gt;
==Policy==&lt;br /&gt;
&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: Policy can't be known until the user requests arrive.  Put authorization logic where you see fit.  Sometimes you need to roll it into the UI.  Sometimes it's in the data layer.  Sometimes it's both.    &lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think that security requirements can be known at design time and expressed in a runtime-readable/declarative format.&lt;br /&gt;
&lt;br /&gt;
; '''The tool knows how to do it'''&lt;br /&gt;
: Let your automated tools dictate your security requirements. Tailoring is for suckers.&lt;br /&gt;
&lt;br /&gt;
==Input Validation==&lt;br /&gt;
&lt;br /&gt;
; '''Validation is for suckers'''&lt;br /&gt;
: Your application is already protected by a firewall, so you don't have to worry about attacks in user input. The security ''experts'' who keep nagging you are just looking to keep themselves in a job and know nothing about programming.&lt;br /&gt;
&lt;br /&gt;
; '''Let developers validate their way'''&lt;br /&gt;
: Don't bother with a standard way of doing validation, you're just cramping developer style. To create truly insecure code, you should try to validate as many different ways as possible, and in as many different places as possible.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: If the client doesn't, by design, produce wacky encoding, for example, then wacky encoding isn't a threat.&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
&lt;br /&gt;
; '''If you can build it and it appears to work then why describe it?'''&lt;br /&gt;
: The most successful applications do not waste time with requirements, security or otherwise.  Optimize the development by keeping the developers from having to read.&lt;br /&gt;
&lt;br /&gt;
; '''Security is just another option'''&lt;br /&gt;
: Assume that your sysadmins will RTFM and change the default settings you specified in a footnote on page 124.&lt;br /&gt;
&lt;br /&gt;
; '''Don't document how security works'''&lt;br /&gt;
: There is no point in writing down all the details of a security design. If someone wants to figure out if it works, they should check the code. After all, the code may change and then the documentation would be useless.&lt;br /&gt;
&lt;br /&gt;
; '''Freedom to innovate'''&lt;br /&gt;
: Standards are really just guidelines for you to add your own custom extensions.&lt;br /&gt;
&lt;br /&gt;
; '''Print is dead'''&lt;br /&gt;
: You already know everything about security, what else is there to learn? Books are for lamers, mailing lists and blogs are for media whores and FUD-tossing blowhards.&lt;br /&gt;
&lt;br /&gt;
==Coding==&lt;br /&gt;
&lt;br /&gt;
; '''Most APIs are safe'''&lt;br /&gt;
: Don't waste time poring through documentation for API functions. It's generally pretty safe to assume that APIs do proper validation, exception handling, logging, and thread safety.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use security patterns'''&lt;br /&gt;
: Make sure there's no standard way of implementing validation, logging, error handling, etc... on your project. It's best when developers are left free to express themselves and channel their inner muse in their code. Avoid establishing any security coding guidelines, that'll just inhibit creativity.&lt;br /&gt;
&lt;br /&gt;
; '''Make sure the build process has lots of steps'''&lt;br /&gt;
: You want to maximize the number of steps in the build process that have to occur in the right order to make a successful build. It's best if only one person knows how to actually set up all the config files and build the distribution. If you do have steps written down, you should have lots of notes distributed across a bunch of files and howto's in lots of locations.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
; '''Test with a browser'''&lt;br /&gt;
: All you need to test a web application is a browser. That way, you ensure that your code will work perfectly for all of your legitimate users.  And what do you care if it doesn't work for hackers, attackers, and criminals? Using a fancy security testing tool like [[WebScarab]] is a waste of your valuable time.&lt;br /&gt;
&lt;br /&gt;
; '''Build test code into every module'''&lt;br /&gt;
: You should build test code throughout the application. That way you'll have it there in production in case anything goes wrong and you need to run it.&lt;br /&gt;
&lt;br /&gt;
; '''Security warnings are all false alarms'''&lt;br /&gt;
: Everyone knows that security warnings are all false alarms, so you can safely just ignore them. Why should you waste your valuable time chasing down possible problems when it's not your money on the line. If a tool doesn't produce perfect results, then just forget it.&lt;br /&gt;
&lt;br /&gt;
==Libraries==&lt;br /&gt;
&lt;br /&gt;
; '''Use lots of precompiled libraries'''&lt;br /&gt;
: Libraries are great because you don't have to worry about whether the code has any security issues. You can trust your business to just about any old library that you download off the Internet and include in your application. Don't worry about checking the source code, it's probably not available and it's too much trouble to recompile. And it would take way too long to check all that source code anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Don't worry about using the latest version of components'''&lt;br /&gt;
: Just because a library has known vulnerabilities doesn't mean it's not safe to use. If there's no proof that *my* application is vulnerable then you're just wasting my time.&lt;br /&gt;
&lt;br /&gt;
==Culture==&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;I got a security approval&amp;quot;&lt;br /&gt;
: So what if it was several years ago, it's basically the same code anyway.&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;Security has to *prove* it before I do anything&amp;quot;&lt;br /&gt;
: So what if you exploited my application, you cheated by using hacking&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;Hello, this is an internal application, so security doesn't matter&amp;quot;&lt;br /&gt;
: We have firewalls and stuff&lt;br /&gt;
&lt;br /&gt;
[[Category:How To]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=185316</id>
		<title>How to write insecure code</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=185316"/>
				<updated>2014-11-12T20:40:25Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Add to this Article==&lt;br /&gt;
&lt;br /&gt;
Help us out and add your favorite ways to discourage secure coding below.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
In the interest of ensuring that there will be a future for hackers, criminals, and others who want to destroy the digital future, this paper captures tips from the masters on how to create insecure code. With a little creative use of these tips, you can also ensure your own financial future. Be careful, you don't want to make your code look hopelessly insecure, or your insecurity may be uncovered and fixed.&lt;br /&gt;
&lt;br /&gt;
The idea for this article comes from Roedy Green's [http://mindprod.com/jgloss/unmain.html How to write unmaintainable code]. You may find the [http://thc.org/root/phun/unmaintain.html one page version more readable]. Actually, making your code unmaintainable is a great first step towards making it insecure and there are some great ideas in this article, particularly the section on camouflage. Also many thanks to Steven Christey from MITRE who contributed a bunch of particularly insecure items.&lt;br /&gt;
&lt;br /&gt;
''Special note for the slow to pick up on irony set. This essay is a '''joke'''! Developers and architects are often bored with lectures about how to write '''secure''' code. Perhaps this is another way to get the point across.''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Use this format for adding items to the list&lt;br /&gt;
; '''Title'''&lt;br /&gt;
: Details&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==General Principles==&lt;br /&gt;
&lt;br /&gt;
; '''Avoid the tools'''&lt;br /&gt;
: To ensure an application is forever insecure, you have to think about how security vulnerabilities are identified and remediated. Many software teams believe that automated tools can solve their security problems. So if you want to ensure vulnerabilities, simply make them difficult for automated tools to find. This is a lot easier than it sounds. All you have to do is make sure your vulnerabilities don't match anything in the tool's database of signatures. Your code can be as complex as you want, so it's pretty easy to avoid getting found. In fact, most inadvertent vulnerabilities can't be found by tools anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Always use default deny'''&lt;br /&gt;
: Apply the principle of &amp;quot;Default Deny&amp;quot; when building your application. Deny that your code can ever be broken, deny vulnerabilities until there's a proven exploit, deny to your customers that there was ever anything wrong, and above all - deny responsibility for flaws. Blame the dirty cache buffers.&lt;br /&gt;
&lt;br /&gt;
; '''Be a shark'''&lt;br /&gt;
: Always be on the move.  Leave security problems to operations staff.&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
&lt;br /&gt;
; '''Distribute security mechanisms'''&lt;br /&gt;
: Security checks should be designed so that they are as distributed as possible throughout the codebase. Try not to follow a consistent pattern and don't make it easy to find all the places where the mechanism is used. This will virtually ensure that security is implemented inconsistently.&lt;br /&gt;
&lt;br /&gt;
; '''Spread the wealth'''&lt;br /&gt;
: Another great way to avoid being found is to make sure your security holes aren't located in one place in your code. It's very difficult for analysts to keep all of your code in their head, so by spreading out the holes you prevent anyone from finding or understanding them.&lt;br /&gt;
&lt;br /&gt;
; '''Use dynamic code'''&lt;br /&gt;
: The single best way to make it difficult for a security analyst (or security tool for that matter) to follow through an application and uncover a flaw is to use dynamic code. It can be almost impossible to trace the flow through code that is loaded at runtime. Features like reflection and classloading are beautiful features for hiding vulnerabilities. Enable as many &amp;quot;plugin&amp;quot; points as possible.&lt;br /&gt;
&lt;br /&gt;
==Secure Languages==&lt;br /&gt;
&lt;br /&gt;
; '''Type safety'''&lt;br /&gt;
: Means anything you enter at the keyboard is secure.&lt;br /&gt;
&lt;br /&gt;
; '''Secure languages'''&lt;br /&gt;
: Pick only programming languages that are completely safe and don't require any security knowledge or special programming to secure.&lt;br /&gt;
&lt;br /&gt;
; '''Mix languages'''&lt;br /&gt;
: Different languages have different security rules, so the more languages you include the more difficult it will be to learn them all. It's hard enough for development teams to even understand the security ramifications of one language, much less three or four. You can use the transitions between languages to hide vulnerabilities too.&lt;br /&gt;
&lt;br /&gt;
==Trust Relationships==&lt;br /&gt;
&lt;br /&gt;
; '''Rely on security checks done elsewhere'''&lt;br /&gt;
: It's redundant to do security checks twice, so if someone else says that they've done a check, there's no point in doing it again. When possible, it's probably best to just assume that others are doing security right, and not waste time doing it yourself. Web services and other service interfaces are generally pretty secure, so don't bother checking what you send or what they return.&lt;br /&gt;
&lt;br /&gt;
; '''Trust insiders'''&lt;br /&gt;
: Malicious input only comes from the Internet, and you can trust that all the data in your databases is perfectly validated, encoded, and sanitized for your purposes.&lt;br /&gt;
&lt;br /&gt;
; '''Share the love'''&lt;br /&gt;
: Drop your source code into repositories that are accessible by all within the company.  This also prevents having to email those hard-coded shared secrets around.&lt;br /&gt;
&lt;br /&gt;
; '''Ignore decoupling requirements'''&lt;br /&gt;
: Security is hard enough.  Don't listen when anyone says that point-to-point trust relationships undermine efforts to build decoupled systems.  They're only trying to sound smart and well read.&lt;br /&gt;
&lt;br /&gt;
==Logging==&lt;br /&gt;
&lt;br /&gt;
; '''Use your logs for debugging'''&lt;br /&gt;
: Nobody will be able to trace attacks on your code if you fill up the logs with debugging nonsense. Extra points for making your log messages undecipherable by anyone except you. Even more points if the log messages look as though they might be security relevant.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use a logging framework'''&lt;br /&gt;
: The best approach to logging is just to write to stdout, or maybe to a file. Logging frameworks make the logs too easy to search and manage to be sure that nobody will ever review them.&lt;br /&gt;
&lt;br /&gt;
==Encryption==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own encryption scheme'''&lt;br /&gt;
: The standard encryption mechanisms are way too complicated to use. It's much easier to make up an encryption algorithm that scrambles up secret stuff. You don't need to bother with a key or anything, just mix it all up and nobody will figure it out.&lt;br /&gt;
&lt;br /&gt;
; '''Hard-code your keys'''&lt;br /&gt;
: Hard-coding is the best way to retain control. This way those pesky operations folks won't be able to monkey with (they say &amp;quot;rotate&amp;quot;) the keys, and they'll be locked into the source code where only smart people can understand them.  This will also make it easier to move from environment to environment as the hard-coded key will be the same everywhere.  This in turn means your code is secure everywhere.&lt;br /&gt;
&lt;br /&gt;
; '''Smart coders don't read manuals'''&lt;br /&gt;
: Just keep adding bytes until the algorithm stops throwing exceptions.  Or just save yourself time and cut-and-paste from a popular coding site.  This looks like a good start: byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };&lt;br /&gt;
&lt;br /&gt;
; '''Pack up your sensitive payload'''&lt;br /&gt;
: If you need to pass things that are sensitive, like passwords or PII, just pack it up in an encrypted blob.  Then just email the key to the developer who is coding the other side of the transaction, and punch out early.  This will also get you past Data Loss Prevention (DLP) tools which is a huge bonus.&lt;br /&gt;
&lt;br /&gt;
; '''Encryption is hard'''&lt;br /&gt;
: A great way to improve the security posture of your site is to use client-side JavaScript to encrypt passwords and other sensitive data that are submitted.  This can be used with or without HTTPS (TLS/SSL).  If you use it without HTTPS, you can save some money by skipping the annual purchase of a signed third party certificate.&lt;br /&gt;
&lt;br /&gt;
; '''HTTPS makes your application bullet proof'''&lt;br /&gt;
: If you use HTTPS encryption between your web application endpoint and the client, there is absolutely no way for anyone to steal any of the data that is transmitted.&lt;br /&gt;
&lt;br /&gt;
==Authentication==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own authentication scheme'''&lt;br /&gt;
: Authentication is simple, so just use your common sense and implement. Don't worry about esoteric stuff you hear about like session prediction, hashing credentials, brute force attacks, and so on. Only NSA eggheads could possibly ever figure that stuff out. And if users want to choose weak passwords, that's their own fault.&lt;br /&gt;
&lt;br /&gt;
; '''Sessions are inherantly secure'''&lt;br /&gt;
: Sessions timeout after 20 minutes, so don't worry about them. You can put the SESSIONID in the URL, log files, or wherever else you feel like. What could an attacker do with a SESSIONID anyway? It's just a bunch of random letters and numbers.&lt;br /&gt;
&lt;br /&gt;
; '''Single Sign-On is easy'''&lt;br /&gt;
: If you need to submit a username and password (or other secret knocks) from one site to another, pack it up in an encrypted blob as above.  This way if anyone finds the blob, they'll have a heck of a time decrypting it, which is what they'll need to do to be able to encrypt it again and create the blob themselves.&lt;br /&gt;
: A one-way hash cannot be decrypted.  Therefore, this is a way to take the latter approach and make it unbreakable.&lt;br /&gt;
&lt;br /&gt;
==Authorization==&lt;br /&gt;
&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think there's a difference between authentication and authorization.&lt;br /&gt;
&lt;br /&gt;
; '''Just let your authorization scheme evolve'''&lt;br /&gt;
: It's really hard to figure out all the access control rules for your application, so use a '''just in time''' development methodology. This way you can just code up new rules when you figure them out. If you end up with hundreds or thousands of lines of authorization code scattered throughout your application, you're on the right track.&lt;br /&gt;
&lt;br /&gt;
; '''Privilege makes code just work'''&lt;br /&gt;
: Using the highest privilege levels makes your product easier to install and run.&lt;br /&gt;
&lt;br /&gt;
; '''Optimize the developer... always'''&lt;br /&gt;
: Each developer, independent of one another, must decide where authorization decision and enforcement is made.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: RIA clients and fat clients that use remote services can make decisions about what the end-user can or can't see.&lt;br /&gt;
&lt;br /&gt;
; '''Volunteer to authorize access to other systems'''&lt;br /&gt;
: When a service you are calling, for example, has inappropriate access controls just be nice and live with it.  After all it will be your fault when a direct object reference permits any user of your system to see any data on their service.  Should that happen, it will be a chance for you to show your dedication when you're up at 3 AM on a Saturday morning sorting out a breach.&lt;br /&gt;
&lt;br /&gt;
==Policy==&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: Policy can't be known until the user requests arrive.  Put authorization logic where you see fit.  Sometimes you need to roll it into the UI.  Sometimes it's in the data layer.  Sometimes it's both.    &lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think that security requirements can be known at design time and expressed in a runtime-readable/declarative format.&lt;br /&gt;
&lt;br /&gt;
; '''The tool knows how to do it'''&lt;br /&gt;
: Let your authentication technology dictate your authorization requirements.&lt;br /&gt;
&lt;br /&gt;
==Input Validation==&lt;br /&gt;
&lt;br /&gt;
; '''Validation is for suckers'''&lt;br /&gt;
: Your application is already protected by a firewall, so you don't have to worry about attacks in user input. The security ''experts'' who keep nagging you are just looking to keep themselves in a job and know nothing about programming.&lt;br /&gt;
&lt;br /&gt;
; '''Let developers validate their way'''&lt;br /&gt;
: Don't bother with a standard way of doing validation, you're just cramping developer style. To create truly insecure code, you should try to validate as many different ways as possible, and in as many different places as possible.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: If the client doesn't, by design, produce wacky encoding, for example, then wacky encoding isn't a threat.&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
&lt;br /&gt;
; '''If you can build it and it appears to work then why describe it?'''&lt;br /&gt;
: The most successful applications do not waste time with requirements, security or otherwise.  Optimize the development by keeping the developers from having to read.&lt;br /&gt;
&lt;br /&gt;
; '''Security is just another option'''&lt;br /&gt;
: Assume that your sysadmins will RTFM and change the default settings you specified in a footnote on page 124.&lt;br /&gt;
&lt;br /&gt;
; '''Don't document how security works'''&lt;br /&gt;
: There is no point in writing down all the details of a security design. If someone wants to figure out if it works, they should check the code. After all, the code may change and then the documentation would be useless.&lt;br /&gt;
&lt;br /&gt;
; '''Freedom to innovate'''&lt;br /&gt;
: Standards are really just guidelines for you to add your own custom extensions.&lt;br /&gt;
&lt;br /&gt;
; '''Print is dead'''&lt;br /&gt;
: You already know everything about security, what else is there to learn? Books are for lamers, mailing lists and blogs are for media whores and FUD-tossing blowhards.&lt;br /&gt;
&lt;br /&gt;
==Coding==&lt;br /&gt;
&lt;br /&gt;
; '''Most APIs are safe'''&lt;br /&gt;
: Don't waste time poring through documentation for API functions. It's generally pretty safe to assume that APIs do proper validation, exception handling, logging, and thread safety.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use security patterns'''&lt;br /&gt;
: Make sure there's no standard way of implementing validation, logging, error handling, etc... on your project. It's best when developers are left free to express themselves and channel their inner muse in their code. Avoid establishing any security coding guidelines, that'll just inhibit creativity.&lt;br /&gt;
&lt;br /&gt;
; '''Make sure the build process has lots of steps'''&lt;br /&gt;
: You want to maximize the number of steps in the build process that have to occur in the right order to make a successful build. It's best if only one person knows how to actually set up all the config files and build the distribution. If you do have steps written down, you should have lots of notes distributed across a bunch of files and howto's in lots of locations.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
; '''Test with a browser'''&lt;br /&gt;
: All you need to test a web application is a browser. That way, you ensure that your code will work perfectly for all of your legitimate users.  And what do you care if it doesn't work for hackers, attackers, and criminals? Using a fancy security testing tool like [[WebScarab]] is a waste of your valuable time.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use static analysis tools'''&lt;br /&gt;
: These tools aren't perfect, so just forget about them. Static analysis tools are likely to create annoying warning messages that will slow down your development time. Also they're a pain to learn, setup, and use.&lt;br /&gt;
&lt;br /&gt;
; '''Build test code into every module'''&lt;br /&gt;
: You should build test code throughout the application. That way you'll have it there in production in case anything goes wrong and you need to run it.&lt;br /&gt;
&lt;br /&gt;
; '''Security warnings are all false alarms'''&lt;br /&gt;
: Everyone knows that security warnings are all false alarms, so you can safely just ignore them. Why should you waste your valuable time chasing down possible problems when it's not your money on the line. If a tool doesn't produce perfect results, then just forget it.&lt;br /&gt;
&lt;br /&gt;
==Libraries==&lt;br /&gt;
&lt;br /&gt;
; '''Use lots of precompiled libraries'''&lt;br /&gt;
: Libraries are great because you don't have to worry about whether the code has any security issues. You can trust your business to just about any old library that you download off the Internet and include in your application. Don't worry about checking the source code, it's probably not available and it's too much trouble to recompile. And it would take way too long to check all that source code anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Don't worry about using the latest version of components'''&lt;br /&gt;
: Just because a library has known vulnerabilities doesn't mean it's not safe to use. If there's no proof that *my* application is vulnerable then you're just wasting my time.&lt;br /&gt;
&lt;br /&gt;
==Culture==&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;I got a security approval&amp;quot;&lt;br /&gt;
: So what if it was several years ago, it's basically the same code anyway.&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;Security has to *prove* it before I do anything&amp;quot;&lt;br /&gt;
: So what if you exploited my application, you cheated by using hacking&lt;br /&gt;
&lt;br /&gt;
; &amp;quot;Hello, this is an internal application, so security doesn't matter&amp;quot;&lt;br /&gt;
: We have firewalls and stuff&lt;br /&gt;
&lt;br /&gt;
[[Category:How To]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=2014_BASC_Presentations&amp;diff=183826</id>
		<title>2014 BASC Presentations</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=2014_BASC_Presentations&amp;diff=183826"/>
				<updated>2014-10-17T17:25:21Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{2014_BASC:Header_Template | Presentations}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__FORCETOC__&lt;br /&gt;
We would like to thank our speakers for donating their time and effort to help make this conference successful.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|AppSec: How It Fits into Digital Security|Jared DeMott| | | }}&lt;br /&gt;
Securing code is important. But history has shown us that &lt;br /&gt;
we can never be certain that our code is 100% perfect. This &lt;br /&gt;
becomes particularly true in rapidly evolving environments. &lt;br /&gt;
As an industry we need to take a broader look. What security&lt;br /&gt;
features are provided by the hardware, OS, language, compiler, &lt;br /&gt;
and even application type? Join us bright and early as Dr. &lt;br /&gt;
DeMott kicks off the 2014 Boston Application Security Conference &lt;br /&gt;
with a Keynote you won’t forget.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Code Assisted PenTest for Mobile Applications|Dinesh Shetty| | | }}&lt;br /&gt;
&lt;br /&gt;
The presentation focuses on problems of following bad Mobile development practice. During this&lt;br /&gt;
session, you will learn how to perform a Code Assisted PenTest on Mobile applications and uncover &lt;br /&gt;
some well-known and some other not so well known security issues. It is far easy to gain a practical &lt;br /&gt;
knowledge of security vulnerabilities than it is to read about them. Watch as Dinesh walks you through&lt;br /&gt;
custom created demo applications and source code review tools, to catch security flaws noted in the&lt;br /&gt;
various hand-held devices. Expect to see a lot of demos, tools, hacking and a lot of fun.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Finding and Exploiting Access Control Vulnerabilities in Graphical User Interfaces|Collin Mulliner| | | }}&lt;br /&gt;
&lt;br /&gt;
Graphical user interfaces (GUIs) contain a number of common visual&lt;br /&gt;
elements or widgets such as labels, text fields, buttons, and lists.&lt;br /&gt;
GUIs typically provide the ability to set attributes on these widgets to&lt;br /&gt;
control their visibility, enabled status, and whether they are writable.&lt;br /&gt;
While these attributes are extremely useful to provide visual cues to&lt;br /&gt;
users to guide them through an application's GUI, they can also be&lt;br /&gt;
misused for purposes they were not intended. In particular, in the&lt;br /&gt;
context of GUI-based applications that include multiple privilege levels&lt;br /&gt;
within the application, GUI element attributes are often misused as a&lt;br /&gt;
mechanism for enforcing access control policies.&lt;br /&gt;
&lt;br /&gt;
In this session, we introduce GEMs, or instances of GUI element misuse,&lt;br /&gt;
as a novel class of access control vulnerabilities in GUI-based&lt;br /&gt;
applications. We present a classification of different GEMs that can&lt;br /&gt;
arise through misuse of widget attributes, and describe a general&lt;br /&gt;
algorithm for identifying and confirming the presence of GEMs in&lt;br /&gt;
vulnerable applications. We then present GEM Miner, an implementation of&lt;br /&gt;
our GEM analysis for the Windows platform. We evaluate GEM Miner using&lt;br /&gt;
real-world GUI-based applications that target the small business and&lt;br /&gt;
enterprise markets, and demonstrate the efficacy of our analysis by&lt;br /&gt;
finding numerous previously unknown access control vulnerabilities in&lt;br /&gt;
these applications.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|How a Hacker Views Your Web Site|Patrick Laverty| | | }}&lt;br /&gt;
&lt;br /&gt;
As defenders, we have to be right 100% of the time where an attacker only needs to be right once. The attack surface of a modern web site is incredibly large and we need to be aware of all of it. Additionally, individual attacks may not always be effective but sometimes using them together can gain the desired effect. In this talk, we’ll take a look at the whole attack surface for a typical web site and the various ways that an attacker will use to compromise a site. &lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|The Intersection of Application Architecture and Security Architecture|Walt Williams| | | }}&lt;br /&gt;
&lt;br /&gt;
This presentation will look at the relationship between security architecture and application architecture, specifically on the impact on application security from recent proposed changes to the Clark-Wilson integrity model.  I'll explore those changes in depth, discuss the implications for application design.  I'll also discuss the implications of these changes to distributed application architectures such as service oriented architectures and other distributed models.  &lt;br /&gt;
&lt;br /&gt;
This presentation will be based upon my recent book: Security for Service Oriented Architectures, CRC press, and 10 years of experience working with application security architecture in various corporations.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Lean Security for Small or Medium Sized Business|Anson Gomes and Jeremy Spencer| | | }}&lt;br /&gt;
&lt;br /&gt;
For a small or medium sized business (SMB) the fallout from a security or privacy incident can be at best a PR nightmare. At their worst it can cause irrecoverable damage and end your business by impacting sales or ad revenue. Your user base may take a hit. You may need to draft a blog post or email your customers describing the incident and asking them to change passwords. A key culprit is budget constraints – as a SMB you are allocating resources to innovating, creating, and improving your product. Security, while important, isn't always the primary objective.&lt;br /&gt;
 &lt;br /&gt;
Our talk will introduce a simple framework for SMBs to focus their security efforts. We will then discuss a common scenario applicable to most SMBs that employs our framework; and leverages it to introduce cheap and effective security mechanisms that provide prevention, limitation, detection, and response capabilities. The key take away will be the thought process and sample techniques that can enable a SMB to take their rag-tag security outfit and turn it into a business enabler.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Mobile First AppSec: Evolving AppSec for Mobile Applications|Sagar Dongre| | | }}&lt;br /&gt;
&lt;br /&gt;
Development teams are embracing Mobile First Development. They are building native iOS and Android&lt;br /&gt;
mobile apps, some are using PhoneGap, and others are using Appcelerator. Evolving AppSec from web &lt;br /&gt;
applications to include mobile is where Mobile First AppSec comes in. Mobile First AppSec describes &lt;br /&gt;
what application security teams must consider for successfully testing mobile applications. The heart of &lt;br /&gt;
Mobile First AppSec is driving the security testing based on the mobile application’s architecture.&lt;br /&gt;
This talk discusses the popular mobile application architectures and how the architecture drives risk. The &lt;br /&gt;
talk then relates the different application architectures and development frameworks to differences in &lt;br /&gt;
their threat model and the consequences on security tests and testing techniques.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Open Source Vulnerability Response|EMC Product Security Response Center| | | }}&lt;br /&gt;
&lt;br /&gt;
Like all software vendors, EMC faces challenges when it comes to managing the response to security vulnerabilities reported on open source embedded components. We will share our experiences by taking OpenSSL Heartbleed and the Bash Bug ‘ShellShock’ as examples and walk through the various challenges we encountered while dealing with it and the processes we built to overcome some of those problems.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Securing The Android Apps On Your Wrist and Face|Jack Mannino and Geller Bedoya| | | }}&lt;br /&gt;
&lt;br /&gt;
Android Wear and Google Glass introduce new ways of interacting with our apps and receiving timely, contextual information from the world around us. Smartphones and tablets are becoming the central point for sending and receiving data from wearables and sensors. Building apps for a wearable world introduces new risks as well as shifts the responsibilities for implementing security controls to other layers.&lt;br /&gt;
&lt;br /&gt;
Many of the same issues we’re familiar with from past Android experiences are still relevant, while some issues are less impactful or not (currently) possible within existing wearables. At the same time, extending the app’s trust boundaries introduces new points of exposure for developers to be aware of in order to proactively defend against attacks. We want to highlight these areas, which developers may not be aware of when adding a wearable component to an existing app.&lt;br /&gt;
&lt;br /&gt;
In this presentation, we will explore how Android Wear and Glass work underneath the hood. We will examine their methods of communication, data replication, and persistence options. We will examine how they fit into the Android development ecosystem and the new risks to privacy and security that need to be considered. Our goal isn’t to deter developers from building wearable apps, but to enable them to make strong security decisions throughout development.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Securing Native Big Data Deployments|Steve Markey| | | }}&lt;br /&gt;
&lt;br /&gt;
This session will provide thought leadership and use cases on securing Big Data technologies &lt;br /&gt;
through stateless tokenization. We will cover: an overview of what native Big Data consists of, &lt;br /&gt;
Big Data architectures, stateless tokenization use, and finally how to implement and secure Big &lt;br /&gt;
Data architectures through stateless tokenization deployments. &lt;br /&gt;
&lt;br /&gt;
Specific focal points include:&lt;br /&gt;
* What Big Data is and how it is used&lt;br /&gt;
* An overview of Big Data architectures in the enterprise&lt;br /&gt;
* What stateless tokenization is and how it is used&lt;br /&gt;
* Secure Big Data deployments through stateless tokenization&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Using the OCTAVE Allegro Framework to Model Application Risks and Countermeasures|George Ehrhorn| | | }}&lt;br /&gt;
&lt;br /&gt;
Effective Risk Assessment is an incredible tool available to the Information Security professional. A defensible risk assessment ensures that you’ll analyze the most risky aspects of your most risky applications. It lets you develop countermeasures that have the biggest impact. In a real world scenario a properly conducted risk assessment can help you work in the most efficient way. This talk is about how MathWorks uses the OCTAVE Allegro Framework to model application risks and develop countermeasures.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Why is CSP Failing? Trends and Challenges in CSP Adoption|Michael Weissbacher| | | }}&lt;br /&gt;
&lt;br /&gt;
Content Security Policy (CSP) has been proposed as a principled and&lt;br /&gt;
robust browser security mechanism against content injection attacks such&lt;br /&gt;
as XSS. When configured correctly, CSP renders malicious code injection&lt;br /&gt;
and data exfiltration exceedingly difficult for attackers.  However,&lt;br /&gt;
despite the promise of these security benefits and being implemented in&lt;br /&gt;
almost all major browsers, CSP adoption is minuscule-our measurements&lt;br /&gt;
show that CSP is deployed in enforcement mode on only 1% of the Alexa&lt;br /&gt;
Top 100.&lt;br /&gt;
&lt;br /&gt;
In this paper, we present the results of a long-term study to determine&lt;br /&gt;
challenges in CSP deployments that can prevent wide adoption. We&lt;br /&gt;
performed weekly crawls of the Alexa Top 1M to measure adoption of web&lt;br /&gt;
security headers, and find that CSP both significantly lags other&lt;br /&gt;
security headers, and that the policies in use are often ineffective at&lt;br /&gt;
actually preventing content injection. In addition, we evaluate the&lt;br /&gt;
feasibility of deploying CSP from the perspective of a&lt;br /&gt;
security-conscious website operator. We used an incremental deployment&lt;br /&gt;
approach through CSP's report-only mode on four websites, collecting&lt;br /&gt;
over 10M reports. Furthermore, we used semi-automated policy generation&lt;br /&gt;
through web application crawling on a set of popular websites. We found&lt;br /&gt;
both that automated methods do not suffice and that significant barriers&lt;br /&gt;
exist to producing accurate results.&lt;br /&gt;
&lt;br /&gt;
Finally, based on our observations, we suggest several improvements to&lt;br /&gt;
CSP that could help to ease its adoption by the web community.&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Presentaton_Info_Template|Why Your AppSec Experts Are Killing You|Jeff Williams| | | }}&lt;br /&gt;
&lt;br /&gt;
Software development has been transformed by practices like Continuous Integration and Continuous Delivery, while application security has remained trapped in expert-based waterfall mode. In this talk, Jeff will show you how you can evolve into a “Continuous Application Security” organization that generates assurance automatically across an entire application security portfolio. Jeff will show you how to bootstrap the “sensor-model-dashboard” feedback loop that makes real time, continuous application security possible. He will demonstrate the approach with a new *free* tool called [http://marketplace.eclipse.org/node/1876552 &amp;quot;Contrast for Eclipse&amp;quot;] that brings the power of instrumentation-based application security testing directly into the popular IDE.  Check out [https://www.youtube.com/watch?v=4B-HgsT_J_M “Application Security at DevOps Speed and Portfolio Scale”] for some background.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{2014_BASC:Footer_Template | Presentations}}&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=167256</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=167256"/>
				<updated>2014-02-03T22:04:50Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the [[XSS Filter Evasion Cheat Sheet]]. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
Before reading this cheatsheet, it is important to have a fundamental understanding of [[Injection Theory]].&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
Microsoft provides an encoding library named the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] for the .NET platform and ASP.NET Framework has built-in [http://msdn.microsoft.com/en-us/library/ms972969.aspx#securitybarriers_topic6 ValidateRequest] function that provides '''limited''' sanitization.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library for Java. OWASP also provides the [[OWASP Java Encoder Project]] for high-performance encoding.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; not recommended because its not in the HTML spec (See: [http://www.w3.org/TR/html4/sgml/entities.html section 24.4.1]) &amp;amp;amp;apos; is in the XML and XHTML specs.&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
=== RULE #3.1 - HTML escape JSON values in an HTML context and read the data with JSON.parse ===&lt;br /&gt;
&lt;br /&gt;
In a Web 2.0 world, the need for having data dynamically generated by an application in a javascript context is common.  One strategy is to make an AJAX call to get the values, but this isn't always performant.  Often, an initial block of JSON is loaded into the page to act as a single place to store multiple values.  This data is tricky, though not impossible, to escape correctly without breaking the format and content of the values.&lt;br /&gt;
&lt;br /&gt;
'''Ensure returned ''Content-Type'' header is application/json and not text/html. &lt;br /&gt;
This shall instruct the browser not misunderstand the context and execute injected script'''&lt;br /&gt;
&lt;br /&gt;
'''Bad HTTP response:'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: text/html; charset=utf-8''' &amp;lt;-- bad&lt;br /&gt;
    ....&lt;br /&gt;
    Content-Length: 373&lt;br /&gt;
    Keep-Alive: timeout=5, max=100&lt;br /&gt;
    Connection: Keep-Alive&lt;br /&gt;
    {&amp;quot;Message&amp;quot;:&amp;quot;No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&amp;amp;AddressLine&lt;br /&gt;
    =The+Gardens'''&amp;amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;'''&amp;amp;AddressLine2=foxlodge+woods&amp;amp;TownName=Meath'.&amp;quot;,&amp;quot;MessageDetail&amp;quot;:&amp;quot;No type was found&lt;br /&gt;
    that matches the controller named 'pay'.&amp;quot;}   &amp;lt;-- this script will pop!!&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
'''Good HTTP response'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: application/json; charset=utf-8''' &amp;lt;--good&lt;br /&gt;
    .....&lt;br /&gt;
    .....&lt;br /&gt;
&lt;br /&gt;
A common '''anti-pattern''' one would see:&lt;br /&gt;
&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      var initData = &amp;lt;%= data.to_json %&amp;gt;; // '''Do NOT do this without encoding the data with one of the techniques listed below.'''&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== JSON entity encoding ====&lt;br /&gt;
&lt;br /&gt;
The rules for JSON encoding can be found in the [https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#Output_Encoding_Rules_Summary Output Encoding Rules Summary]. Note, this will not allow you to use XSS protection provided by CSP 1.0.&lt;br /&gt;
&lt;br /&gt;
==== HTML entity encoding ====&lt;br /&gt;
&lt;br /&gt;
This technique has the advantage that html entity escaping is widely supported and helps separate data from server side code without crossing any context boundaries. Consider placing the JSON block on the page as a normal element and then parsing the innerHTML to get the contents.  The javascript that reads the span can live in an external file, thus making the implementation of CSP enforcement easier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script id=&amp;quot;init_data&amp;quot; type=&amp;quot;application/json&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;amp;lt;%= html_escape(data.to_json) %&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  // external js file&lt;br /&gt;
  var dataElement = document.getElementById('init_data');&lt;br /&gt;
  var jsonText = dataElement.textContent || dataElement.innerText  // unescapes the content of the span&lt;br /&gt;
  var initData = JSON.parse(jsonText);&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/span&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Sanitize HTML Markup with a Library Designed for the Job ==&lt;br /&gt;
&lt;br /&gt;
If your application handles markup -- untrusted input that is supposed to contain HTML -- it can be very difficult to validate. Encoding is also difficult, since it would break all the tags that are supposed to be in the input. Therefore, you need a library that can parse and clean HTML formatted text.  There are several available at OWASP that are simple to use:&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy''' - https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer''' - https://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
'''Other libraries that provide HTML Sanitization include:'''&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP Html Purifier - http://htmlpurifier.org/&amp;lt;br/&amp;gt;&lt;br /&gt;
JavaScript/Node.JS Bleach - https://github.com/ecto/bleach&amp;lt;br/&amp;gt;&lt;br /&gt;
Python Bleach - https://pypi.python.org/pypi/bleach&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule #1: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule #2: Implement Content Security Policy ==&lt;br /&gt;
&lt;br /&gt;
There is another good complex solution to mitigate the impact of an XSS flaw called Content Security Policy. It's a browser side mechanism which &lt;br /&gt;
allows you to create source whitelists for client side resources of your web application, e.g. JavaScript, CSS, images, etc. CSP via special HTTP header instructs the browser to only execute or render resources from those sources. For example this CSP &lt;br /&gt;
&lt;br /&gt;
 Content-Security-Policy: default-src: 'self'; script-src: 'self' static.domain.tld&lt;br /&gt;
&lt;br /&gt;
will instruct web browser to load all resources only from the page's origin and JavaScript source code files additionaly from static.domain.tld. For more details on Content Security Policy, including what it does, and how to use it, see the OWASP article on  [[Content_Security_Policy]]&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The following snippets of HTML demonstrate how to safely render untrusted data in a variety of different contexts. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable nowraplinks&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Data Type&lt;br /&gt;
! Context&lt;br /&gt;
! Code Sample&lt;br /&gt;
! Defense&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;span&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;amp;lt;/span&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Safe HTML Attributes&lt;br /&gt;
| &amp;amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;fname&amp;quot; value=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes Aggressive HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Only place untrusted data into a whitelist of safe attributes (listed below).&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Strictly validate unsafe attributes such as background, id and name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| GET Parameter&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;/site/search?value=&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.235_-_URL_Escape_Before_Inserting_Untrusted_Data_into_HTML_URL_Parameter_Values URL Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Untrusted URL in a SRC or HREF attribute&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;iframe src=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Canonicalize input&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;URL Validation&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Safe URL verification&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Whitelist http and https URL's only ([[Avoid the JavaScript Protocol to Open a new Window]])&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Attribute encoder&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| CSS Value&lt;br /&gt;
| &amp;amp;lt;div style=&amp;quot;width: &amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;;&amp;quot;&amp;gt;Selection&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values Strict structural validation]&amp;lt;li&amp;gt;CSS Hex encoding&amp;lt;li&amp;gt;Good design of CSS Features&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| JavaScript Variable&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;var currentValue='&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;';&amp;amp;lt;/script&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;script&amp;gt;someFunction('&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;');&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Ensure JavaScript variables are quoted&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Hex Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Unicode Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Avoid backslash encoding (\&amp;quot; or \' or \\)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| HTML&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;div&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED HTML&amp;lt;/span&amp;gt;&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Use_an_HTML_Policy_engine_to_validate_or_clean_user-driven_HTML_in_an_outbound_way HTML Validation (JSoup, AntiSamy, HTML Sanitizer)]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| DOM XSS&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;document.write(&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;quot;UNTRUSTED INPUT: &amp;quot; + document.location.hash&amp;lt;/span&amp;gt;);&amp;amp;lt;script/&amp;amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[[DOM based XSS Prevention Cheat Sheet]]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''''Safe HTML Attributes include:''''' align, alink, alt, bgcolor, border, cellpadding, cellspacing, class, color, cols, colspan, coords, dir, face, height, hspace, ismap, lang, marginheight, marginwidth, multiple, nohref, noresize, noshade, nowrap, ref, rel, rev, rows, rowspan, scrolling, shape, span, summary, tabindex, title, usemap, valign, value, vlink, vspace, width&lt;br /&gt;
&lt;br /&gt;
= Output Encoding Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The purpose of output encoding (as it relates to Cross Site Scripting) is to convert untrusted input into a safe form where the input is displayed as '''data''' to the user without executing as '''code''' in the browser. The following charts details a list of critical output encoding methods needed to stop Cross Site Scripting.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Encoding Type&lt;br /&gt;
! Encoding Mechanism&lt;br /&gt;
|-&lt;br /&gt;
| HTML Entity Encoding&lt;br /&gt;
|   Convert &amp;amp; to &amp;amp;amp;amp;&amp;lt;br/&amp;gt;Convert &amp;lt; to &amp;amp;amp;lt;&amp;lt;br/&amp;gt;Convert &amp;gt; to &amp;amp;amp;gt;&amp;lt;br/&amp;gt;Convert &amp;quot; to &amp;amp;amp;quot;&amp;lt;br/&amp;gt;Convert ' to &amp;amp;amp;#x27;&amp;lt;br/&amp;gt;Convert / to &amp;amp;amp;#x2F;&lt;br /&gt;
|-&lt;br /&gt;
| HTML Attribute Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the HTML Entity &amp;amp;amp;#xHH; format, including spaces. (HH = Hex Value)&lt;br /&gt;
|-&lt;br /&gt;
| URL Encoding&lt;br /&gt;
| Standard percent encoding, see: [http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp]. URL encoding should only be used to encode parameter values, not the entire URL or path fragments of a URL.&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the \uXXXX unicode escaping format (X = Integer).&lt;br /&gt;
|-&lt;br /&gt;
| CSS Hex Encoding&lt;br /&gt;
| CSS escaping supports \XX and \XXXXXX. Using a two character escape can cause problems if the next character continues the escape sequence. There are two solutions (a) Add a space after the CSS escape (will be ignored by the CSS parser) (b) use the full amount of CSS escaping possible by zero padding the value.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* OWASP: [[XSS Filter Evasion Cheat Sheet]] - Based on - RSnake's: &amp;quot;XSS Cheat Sheet&amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''Discussion on the Types of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[Types of Cross-Site Scripting]]&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* [[XSS Experimental Minimal Encoding Rules]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Neil Mattatall - neil[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Eoin Keary - eoin.keary[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=List_of_useful_HTTP_headers&amp;diff=166802</id>
		<title>List of useful HTTP headers</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=List_of_useful_HTTP_headers&amp;diff=166802"/>
				<updated>2014-01-28T15:18:14Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: /* Real life examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page lists useful security-related HTTP headers. In most architectures these headers can be set in web server configuration ([http://httpd.apache.org/docs/2.0/mod/mod_headers.html Apache], [http://technet.microsoft.com/pl-pl/library/cc753133(v=ws.10).aspx IIS]), without changing actual application's code. This offers significantly faster and cheaper method for at least partial mitigation of existing issues, and an additional layer of defense for new applications.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field name&lt;br /&gt;
! Description&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
|[http://tools.ietf.org/html/rfc6797 Strict-Transport-Security]&lt;br /&gt;
|HTTP Strict-Transport-Security (HSTS) enforces secure (HTTP over SSL/TLS) connections to the server. This reduces impact of bugs in web applications leaking session data through cookies and external links and defends against Man-in-the-middle attacks. HSTS also disables the ability for user's to ignore SSL negotiation warnings.&lt;br /&gt;
|&amp;lt;code&amp;gt;Strict-Transport-Security: max-age=16070400; includeSubDomains&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-01 X-Frame-Options], [http://tools.ietf.org/html/draft-ietf-websec-frame-options-00 Frame-Options]&lt;br /&gt;
| Provides [[Clickjacking]] protection. Values: ''deny'' - no rendering within a frame, ''sameorigin'' - no rendering if origin mismatch, ''allow-from: DOMAIN'' - allow rendering if framed by frame loaded from ''DOMAIN''&lt;br /&gt;
| &amp;lt;code&amp;gt; X-Frame-Options: deny&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx X-XSS-Protection]&lt;br /&gt;
| This header enables the [[Cross-site scripting]] (XSS) filter built into most recent web browsers. It's usually enabled by default anyway, so the role of this header is to re-enable the filter for this particular website if it was disabled by the user. This header is supported in IE 8+, and in Chrome (not sure which versions). The anti-XSS filter was added in Chrome 4. Its unknown if that version honored this header.&lt;br /&gt;
| &amp;lt;code&amp;gt;X-XSS-Protection: 1; mode=block&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx X-Content-Type-Options]&lt;br /&gt;
| The only defined value, &amp;quot;nosniff&amp;quot;, prevents Internet Explorer and Google Chrome from MIME-sniffing a response away from the declared content-type. This also applies to [http://code.google.com/chrome/extensions/hosting.html Google Chrome], when downloading extensions. This reduces exposure to drive-by download attacks and sites serving user uploaded content that, by clever naming, could be treated by MSIE as executable or dynamic HTML files.&lt;br /&gt;
| &amp;lt;code&amp;gt; X-Content-Type-Options: nosniff &amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|[http://www.w3.org/TR/CSP/ X-Content-Security-Policy, X-WebKit-CSP]&lt;br /&gt;
|[[Content Security Policy]] requires careful tuning and precise definition of the policy. If enabled, CSP has significant impact on the way browser renders pages (e.g., inline JavaScript disabled by default and must be explicitly allowed in policy). CSP prevents a wide range of attacks, including [[Cross-site scripting]] and other cross-site injections.&lt;br /&gt;
|&amp;lt;code&amp;gt;X-WebKit-CSP: default-src 'self'&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Check Your Headers==&lt;br /&gt;
&lt;br /&gt;
Visit Check Your Headers to view and evaluate any website's security headers.  http://cyh.herokuapp.com/cyh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Real life examples==&lt;br /&gt;
Below examples present selected HTTP headers as set by popular websites to demonstrate that they are indeed being used in production services:&lt;br /&gt;
&lt;br /&gt;
===Facebook===&lt;br /&gt;
As of January 2013 [https://www.facebook.com/ Facebook] main page was setting these security related HTTP headers. &lt;br /&gt;
&lt;br /&gt;
 '''Strict-Transport-Security:''' max-age=60&lt;br /&gt;
 '''X-Content-Type-Options:''' nosniff&lt;br /&gt;
 '''X-Frame-Options:''' DENY&lt;br /&gt;
 '''X-WebKit-CSP:''' &amp;lt;small&amp;gt;default-src *; script-src https://*.facebook.com&lt;br /&gt;
   http://*.facebook.com https://*.fbcdn.net http://*.fbcdn.net *.facebook.net&lt;br /&gt;
   *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:*&lt;br /&gt;
   'unsafe-inline' 'unsafe-eval' https://*.akamaihd.net http://*.akamaihd.net;&lt;br /&gt;
   style-src * 'unsafe-inline'; connect-src https://*.facebook.com http://*.facebook.com&lt;br /&gt;
   https://*.fbcdn.net http://*.fbcdn.net *.facebook.net *.spotilocal.com:*&lt;br /&gt;
   https://*.akamaihd.net ws://*.facebook.com:* http://*.akamaihd.net;&amp;lt;/small&amp;gt;&lt;br /&gt;
 '''X-XSS-Protection:''' 1; mode=block&lt;br /&gt;
&lt;br /&gt;
Especially interesting is Facebook's use of [http://www.w3.org/TR/CSP/ Content Security Policy] (using Google Chrome syntax), whose implementation can be [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ challenging] for large sites with heavy usage of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Google+===&lt;br /&gt;
As of January 2013 [https://plus.google.com/ Google+] main page was setting these security related HTTP headers:&lt;br /&gt;
&lt;br /&gt;
 '''x-content-type-options:''' nosniff&lt;br /&gt;
 '''x-frame-options:''' SAMEORIGIN&lt;br /&gt;
 '''x-xss-protection:''' 1; mode=block&lt;br /&gt;
&lt;br /&gt;
===Twitter===&lt;br /&gt;
As of May 2013 [https://twitter.com/ Twitter] main page was setting these security related HTTP headers:&lt;br /&gt;
&lt;br /&gt;
 '''strict-transport-security:''' max-age=631138519&lt;br /&gt;
 '''x-frame-options:''' SAMEORIGIN&lt;br /&gt;
 '''x-xss-protection:''' 1; mode=block&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=List_of_useful_HTTP_headers&amp;diff=166801</id>
		<title>List of useful HTTP headers</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=List_of_useful_HTTP_headers&amp;diff=166801"/>
				<updated>2014-01-28T15:17:29Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page lists useful security-related HTTP headers. In most architectures these headers can be set in web server configuration ([http://httpd.apache.org/docs/2.0/mod/mod_headers.html Apache], [http://technet.microsoft.com/pl-pl/library/cc753133(v=ws.10).aspx IIS]), without changing actual application's code. This offers significantly faster and cheaper method for at least partial mitigation of existing issues, and an additional layer of defense for new applications.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field name&lt;br /&gt;
! Description&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
|[http://tools.ietf.org/html/rfc6797 Strict-Transport-Security]&lt;br /&gt;
|HTTP Strict-Transport-Security (HSTS) enforces secure (HTTP over SSL/TLS) connections to the server. This reduces impact of bugs in web applications leaking session data through cookies and external links and defends against Man-in-the-middle attacks. HSTS also disables the ability for user's to ignore SSL negotiation warnings.&lt;br /&gt;
|&amp;lt;code&amp;gt;Strict-Transport-Security: max-age=16070400; includeSubDomains&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-01 X-Frame-Options], [http://tools.ietf.org/html/draft-ietf-websec-frame-options-00 Frame-Options]&lt;br /&gt;
| Provides [[Clickjacking]] protection. Values: ''deny'' - no rendering within a frame, ''sameorigin'' - no rendering if origin mismatch, ''allow-from: DOMAIN'' - allow rendering if framed by frame loaded from ''DOMAIN''&lt;br /&gt;
| &amp;lt;code&amp;gt; X-Frame-Options: deny&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx X-XSS-Protection]&lt;br /&gt;
| This header enables the [[Cross-site scripting]] (XSS) filter built into most recent web browsers. It's usually enabled by default anyway, so the role of this header is to re-enable the filter for this particular website if it was disabled by the user. This header is supported in IE 8+, and in Chrome (not sure which versions). The anti-XSS filter was added in Chrome 4. Its unknown if that version honored this header.&lt;br /&gt;
| &amp;lt;code&amp;gt;X-XSS-Protection: 1; mode=block&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx X-Content-Type-Options]&lt;br /&gt;
| The only defined value, &amp;quot;nosniff&amp;quot;, prevents Internet Explorer and Google Chrome from MIME-sniffing a response away from the declared content-type. This also applies to [http://code.google.com/chrome/extensions/hosting.html Google Chrome], when downloading extensions. This reduces exposure to drive-by download attacks and sites serving user uploaded content that, by clever naming, could be treated by MSIE as executable or dynamic HTML files.&lt;br /&gt;
| &amp;lt;code&amp;gt; X-Content-Type-Options: nosniff &amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|[http://www.w3.org/TR/CSP/ X-Content-Security-Policy, X-WebKit-CSP]&lt;br /&gt;
|[[Content Security Policy]] requires careful tuning and precise definition of the policy. If enabled, CSP has significant impact on the way browser renders pages (e.g., inline JavaScript disabled by default and must be explicitly allowed in policy). CSP prevents a wide range of attacks, including [[Cross-site scripting]] and other cross-site injections.&lt;br /&gt;
|&amp;lt;code&amp;gt;X-WebKit-CSP: default-src 'self'&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Real life examples==&lt;br /&gt;
Below examples present selected HTTP headers as set by popular websites to demonstrate that they are indeed being used in production services:&lt;br /&gt;
&lt;br /&gt;
Visit Check Your Headers to view and evaluate any website's security headers.  http://cyh.herokuapp.com/cyh&lt;br /&gt;
&lt;br /&gt;
===Facebook===&lt;br /&gt;
As of January 2013 [https://www.facebook.com/ Facebook] main page was setting these security related HTTP headers. &lt;br /&gt;
&lt;br /&gt;
 '''Strict-Transport-Security:''' max-age=60&lt;br /&gt;
 '''X-Content-Type-Options:''' nosniff&lt;br /&gt;
 '''X-Frame-Options:''' DENY&lt;br /&gt;
 '''X-WebKit-CSP:''' &amp;lt;small&amp;gt;default-src *; script-src https://*.facebook.com&lt;br /&gt;
   http://*.facebook.com https://*.fbcdn.net http://*.fbcdn.net *.facebook.net&lt;br /&gt;
   *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:*&lt;br /&gt;
   'unsafe-inline' 'unsafe-eval' https://*.akamaihd.net http://*.akamaihd.net;&lt;br /&gt;
   style-src * 'unsafe-inline'; connect-src https://*.facebook.com http://*.facebook.com&lt;br /&gt;
   https://*.fbcdn.net http://*.fbcdn.net *.facebook.net *.spotilocal.com:*&lt;br /&gt;
   https://*.akamaihd.net ws://*.facebook.com:* http://*.akamaihd.net;&amp;lt;/small&amp;gt;&lt;br /&gt;
 '''X-XSS-Protection:''' 1; mode=block&lt;br /&gt;
&lt;br /&gt;
Especially interesting is Facebook's use of [http://www.w3.org/TR/CSP/ Content Security Policy] (using Google Chrome syntax), whose implementation can be [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ challenging] for large sites with heavy usage of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Google+===&lt;br /&gt;
As of January 2013 [https://plus.google.com/ Google+] main page was setting these security related HTTP headers:&lt;br /&gt;
&lt;br /&gt;
 '''x-content-type-options:''' nosniff&lt;br /&gt;
 '''x-frame-options:''' SAMEORIGIN&lt;br /&gt;
 '''x-xss-protection:''' 1; mode=block&lt;br /&gt;
&lt;br /&gt;
===Twitter===&lt;br /&gt;
As of May 2013 [https://twitter.com/ Twitter] main page was setting these security related HTTP headers:&lt;br /&gt;
&lt;br /&gt;
 '''strict-transport-security:''' max-age=631138519&lt;br /&gt;
 '''x-frame-options:''' SAMEORIGIN&lt;br /&gt;
 '''x-xss-protection:''' 1; mode=block&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=List_of_useful_HTTP_headers&amp;diff=166800</id>
		<title>List of useful HTTP headers</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=List_of_useful_HTTP_headers&amp;diff=166800"/>
				<updated>2014-01-28T15:16:51Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: /* Real life examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page lists useful security-related HTTP headers. In most architectures these headers can be set in web server configuration ([http://httpd.apache.org/docs/2.0/mod/mod_headers.html Apache], [http://technet.microsoft.com/pl-pl/library/cc753133(v=ws.10).aspx IIS]), without changing actual application's code. This offers significantly faster and cheaper method for at least partial mitigation of existing issues, and an additional layer of defense for new applications.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field name&lt;br /&gt;
! Description&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
|[http://tools.ietf.org/html/rfc6797 Strict-Transport-Security]&lt;br /&gt;
|HTTP Strict-Transport-Security (HSTS) enforces secure (HTTP over SSL/TLS) connections to the server. This reduces impact of bugs in web applications leaking session data through cookies and external links and defends against Man-in-the-middle attacks. HSTS also disables the ability for user's to ignore SSL negotiation warnings.&lt;br /&gt;
|&amp;lt;code&amp;gt;Strict-Transport-Security: max-age=16070400; includeSubDomains&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-01 X-Frame-Options], [http://tools.ietf.org/html/draft-ietf-websec-frame-options-00 Frame-Options]&lt;br /&gt;
| Provides [[Clickjacking]] protection. Values: ''deny'' - no rendering within a frame, ''sameorigin'' - no rendering if origin mismatch, ''allow-from: DOMAIN'' - allow rendering if framed by frame loaded from ''DOMAIN''&lt;br /&gt;
| &amp;lt;code&amp;gt; X-Frame-Options: deny&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx X-XSS-Protection]&lt;br /&gt;
| This header enables the [[Cross-site scripting]] (XSS) filter built into most recent web browsers. It's usually enabled by default anyway, so the role of this header is to re-enable the filter for this particular website if it was disabled by the user. This header is supported in IE 8+, and in Chrome (not sure which versions). The anti-XSS filter was added in Chrome 4. Its unknown if that version honored this header.&lt;br /&gt;
| &amp;lt;code&amp;gt;X-XSS-Protection: 1; mode=block&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| [http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx X-Content-Type-Options]&lt;br /&gt;
| The only defined value, &amp;quot;nosniff&amp;quot;, prevents Internet Explorer and Google Chrome from MIME-sniffing a response away from the declared content-type. This also applies to [http://code.google.com/chrome/extensions/hosting.html Google Chrome], when downloading extensions. This reduces exposure to drive-by download attacks and sites serving user uploaded content that, by clever naming, could be treated by MSIE as executable or dynamic HTML files.&lt;br /&gt;
| &amp;lt;code&amp;gt; X-Content-Type-Options: nosniff &amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|[http://www.w3.org/TR/CSP/ X-Content-Security-Policy, X-WebKit-CSP]&lt;br /&gt;
|[[Content Security Policy]] requires careful tuning and precise definition of the policy. If enabled, CSP has significant impact on the way browser renders pages (e.g., inline JavaScript disabled by default and must be explicitly allowed in policy). CSP prevents a wide range of attacks, including [[Cross-site scripting]] and other cross-site injections.&lt;br /&gt;
|&amp;lt;code&amp;gt;X-WebKit-CSP: default-src 'self'&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Real life examples==&lt;br /&gt;
Below examples present selected HTTP headers as set by popular websites to demonstrate that they are indeed being used in production services:&lt;br /&gt;
&lt;br /&gt;
Visit Check Your Headers to view and evalaute any website's security headers.  http://cyh.herokuapp.com/cyh&lt;br /&gt;
&lt;br /&gt;
===Facebook===&lt;br /&gt;
As of January 2013 [https://www.facebook.com/ Facebook] main page was setting these security related HTTP headers. &lt;br /&gt;
&lt;br /&gt;
 '''Strict-Transport-Security:''' max-age=60&lt;br /&gt;
 '''X-Content-Type-Options:''' nosniff&lt;br /&gt;
 '''X-Frame-Options:''' DENY&lt;br /&gt;
 '''X-WebKit-CSP:''' &amp;lt;small&amp;gt;default-src *; script-src https://*.facebook.com&lt;br /&gt;
   http://*.facebook.com https://*.fbcdn.net http://*.fbcdn.net *.facebook.net&lt;br /&gt;
   *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:*&lt;br /&gt;
   'unsafe-inline' 'unsafe-eval' https://*.akamaihd.net http://*.akamaihd.net;&lt;br /&gt;
   style-src * 'unsafe-inline'; connect-src https://*.facebook.com http://*.facebook.com&lt;br /&gt;
   https://*.fbcdn.net http://*.fbcdn.net *.facebook.net *.spotilocal.com:*&lt;br /&gt;
   https://*.akamaihd.net ws://*.facebook.com:* http://*.akamaihd.net;&amp;lt;/small&amp;gt;&lt;br /&gt;
 '''X-XSS-Protection:''' 1; mode=block&lt;br /&gt;
&lt;br /&gt;
Especially interesting is Facebook's use of [http://www.w3.org/TR/CSP/ Content Security Policy] (using Google Chrome syntax), whose implementation can be [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ challenging] for large sites with heavy usage of JavaScript.&lt;br /&gt;
&lt;br /&gt;
===Google+===&lt;br /&gt;
As of January 2013 [https://plus.google.com/ Google+] main page was setting these security related HTTP headers:&lt;br /&gt;
&lt;br /&gt;
 '''x-content-type-options:''' nosniff&lt;br /&gt;
 '''x-frame-options:''' SAMEORIGIN&lt;br /&gt;
 '''x-xss-protection:''' 1; mode=block&lt;br /&gt;
&lt;br /&gt;
===Twitter===&lt;br /&gt;
As of May 2013 [https://twitter.com/ Twitter] main page was setting these security related HTTP headers:&lt;br /&gt;
&lt;br /&gt;
 '''strict-transport-security:''' max-age=631138519&lt;br /&gt;
 '''x-frame-options:''' SAMEORIGIN&lt;br /&gt;
 '''x-xss-protection:''' 1; mode=block&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Tools_Categories&amp;diff=161925</id>
		<title>Category:Tools Categories</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Tools_Categories&amp;diff=161925"/>
				<updated>2013-10-28T19:59:18Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Stub}}&lt;br /&gt;
[[Category:OWASP Tools Project]]&lt;br /&gt;
&lt;br /&gt;
== Tool Categories  ==&lt;br /&gt;
&lt;br /&gt;
The web application security tools can be divided mainly in two categories. One that protect applications against vulnerabilities and the others that detect vulnerabilities within web applications. Therefore we will be categorizing tools under these headings. The categories of tools currently being addressed by this project are: &lt;br /&gt;
&lt;br /&gt;
=== Web Application Vulnerability Detection Tools ===&lt;br /&gt;
*Threat Modeling Tools&lt;br /&gt;
*Source Code Analysis (SAST) Tools&lt;br /&gt;
*Vulnerability Scanning (DAST) Tools&lt;br /&gt;
*Interactive Application Security Testing (IAST) Tools&lt;br /&gt;
*Penetration Testing Tools&lt;br /&gt;
&lt;br /&gt;
=== Web Application Protection Tools === &lt;br /&gt;
&lt;br /&gt;
*Web Application Firewalls (WAFs) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The goal is to provide the following information (at a minimum) in each tool category: &lt;br /&gt;
&lt;br /&gt;
*Description of this tool category &lt;br /&gt;
*General strengths and weaknesses of tools in this category &lt;br /&gt;
*Important selection criteria for comparing tools within the category (e.g. ease of use, performance, cost, likelihood of false positives)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[[Appendix_A:_Testing_Tools|OWASP Guide Testing Tools Listing]]&lt;br /&gt;
*[[:Category:OWASP Tool|Tools from OWASP]]&lt;br /&gt;
*[[:Category:Non-OWASP Open Tool|Open Source Tools]]&lt;br /&gt;
*Samurai Web Testing Framework Tools: http://www.cgisecurity.com/2008/09/samurai-web-tes.html&lt;br /&gt;
*Tools from OWASP Live CD Project: http://mtesauro.com/livecd/index.php?title=Potential_Tool_List&lt;br /&gt;
*OWASP Phoenix Tools Project: http://www.owasp.org/index.php/Phoenix/Tools&lt;br /&gt;
*Open Source Testing Tools: https://lists.owasp.org/pipermail/owasp-cincinnati/2009-February/000151.html&lt;br /&gt;
*NIST SAMATE Project: http://samate.nist.gov/index.php/Main_Page.html&lt;br /&gt;
*[[Source Code Analysis Tools]]&lt;br /&gt;
*[[Web Application Firewalls]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Source_Code_Analysis_Tools&amp;diff=161924</id>
		<title>Category:Source Code Analysis Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Source_Code_Analysis_Tools&amp;diff=161924"/>
				<updated>2013-10-28T19:57:17Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Stub}}&lt;br /&gt;
[[Category:OWASP Tools Project]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Here we will provide a listing of security source code analysis tools currently available in the market. The plan is to extend this listing to provide information about each tool's strengths and weaknesses to enable you to make an informed decision about the selection of a particular tool to meet your requirements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; '''Disclaimer:''' The tools listing in the table below has been presented in an alphabetical order. OWASP does not endorse any of the Vendors or Source Code Analysis Tools by listing them in the table below. We have made every effort to put this information as accurately as possible. If you are the vendor of a tool below and think that this information is incomplete or incorrect, please send an e-mail to our mailing list and we will make every effort to correct this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evaluation Criteria ==&lt;br /&gt;
TBC&lt;br /&gt;
&lt;br /&gt;
== Tools Listing ==&lt;br /&gt;
&lt;br /&gt;
{{:Template:OWASP Tool Headings}}&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://contrastsecurity.com Contrast] || tool_owner = Contrast Security (Aspect) || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Most platforms supported }}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.fortify.com/security-resources/rats.jsp RATS] || tool_owner =  || tool_licence =  || tool_platforms = }}&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[[Source Code Analysis Tools]]&lt;br /&gt;
*NIST list of Source Code Security Analyzers: http://samate.nist.gov/index.php/Source_Code_Security_Analyzers.html&lt;br /&gt;
*Semate Publications on Static Source Code Analyzers: http://samate.nist.gov/index.php/SAMATE_Publications.html&lt;br /&gt;
*http://swreflections.blogspot.com/2009/06/value-of-static-analysis-tools.html&lt;br /&gt;
*AppSecEU08 Presentation: http://www.owasp.org/index.php/AppSecEU08_Scanstud_-_Evaluating_static_analysis_tools&lt;br /&gt;
*NSA comparison of source code analysis tools: http://krvw.com/pipermail/sc-l/2009/002094.html&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=161923</id>
		<title>Category:Vulnerability Scanning Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=161923"/>
				<updated>2013-10-28T19:50:44Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Stub}} &lt;br /&gt;
&lt;br /&gt;
== Description  ==&lt;br /&gt;
&lt;br /&gt;
Web Application Vulnerability Scanners are the automated tools that scan web applications to look for known security vulnerabilities such as cross-site scripting, SQL injection, command execution, directory traversal and insecure server configuration. A large number of both commercial and open source tools are available and and all these tools have their own strengths and weaknesses. &lt;br /&gt;
&lt;br /&gt;
Here we will provide a listing of vulnerability scanning tools currently available in the market. The plan is to extend this listing to provide information about each tool's strengths and weaknesses to enable you to make an informed decision about the selection of a particular tool to meet your requirements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; '''Disclaimer:''' The tools listing in the table below has been presented in an alphabetical order. OWASP does not endorse any of the Vendors or Scanning Tools by listing them in the table below. We have made every effort to put this information as accurately as possible. If you are the vendor of a tool below and think that this information is incomplete or incorrect, please send an e-mail to our mailing list and we will make every effort to correct this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools Listing  ==&lt;br /&gt;
&lt;br /&gt;
{{:Template:OWASP Tool Headings}} &lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.acunetix.com/ Acunetix WVS] || tool_owner = Acunetix || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www-01.ibm.com/software/rational/offerings/websecurity/ AppScan] || tool_owner = IBM || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.portswigger.net/suite/ Burp Suite] || tool_owner = PortSwiger || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Most platforms supported }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://contrastsecurity.com Contrast] || tool_owner = Contrast Security (Aspect) || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Most platforms supported }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.gamasec.com/Gamascan.aspx GamaScan] || tool_owner = GamaSec || tool_licence = Commercial || tool_platforms = Windows }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://rgaucher.info/beta/grabber/ Grabber] || tool_owner = Romain Gaucher || tool_licence = Open Source || tool_platforms = Python 2.4, BeautifulSoup and PyXML}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://sourceforge.net/p/grendel/code/ci/c59780bfd41bdf34cc13b27bc3ce694fd3cb7456/tree/ Grendel-Scan] || tool_owner = David Byrne || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cenzic.com/ Hailstorm] || tool_owner = Cenzic || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ikare-monitoring.com/ IKare] || tool_owner = ITrust || tool_licence = Commercial || tool_platforms = N/A }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.nstalker.com/ N-Stealth] || tool_owner = N-Stalker || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.mavitunasecurity.com/ Netsparker] || tool_owner = MavitunaSecurity || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/nexpose-community-edition.jsp NeXpose] || tool_owner = Rapid7 || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Windows/Linux}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cirt.net/nikto2 Nikto] || tool_owner = CIRT || tool_licence = Open Source|| tool_platforms = Unix/Linux}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ntobjectives.com/ntospider NTOSpider] || tool_owner = NT OBJECTives || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.milescan.com/hk/ ParosPro] || tool_owner = MileSCAN || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.qualys.com/products/qg_suite/was/ QualysGuard] || tool_owner = Qualys || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondtrust.com/Products/RetinaNetworkSecurityScanner/ Retina] || tool_owner = BeyondTrust || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.kavado.com/ ScanDo] || tool_owner = KaVaDo Inc || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.isecpartners.com/SecurityQAToolbar.html SecurityQA Toolbar] || tool_owner = iSec Partners || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.orvant.com Securus] || tool_owner = Orvant, Inc || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.secpoint.com/penetrator.html SecPoint Penetrator] || tool_owner = SecPoint || tool_licence = Commercial || tool_platforms = Windows, Unix/Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.whitehatsec.com/home/services/services.html Sentinel] || tool_owner = WhiteHat Security || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.subgraph.com/products.html Vega] || tool_owner = Subgraph || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://wapiti.sourceforge.net/ Wapiti] || tool_owner = Informática Gesfor || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ncircle.com/index.php?s=products_webapp360 WebApp360] || tool_owner = nCircle || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&amp;amp;cp=1-11-201-200^9570_4000_100__ WebInspect] || tool_owner = HP || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.openvas.org OpenVAS] || tool_owner = OpenVAS || tool_licence = Open Source || tool_platforms = Windows / Linux }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.parasoft.com/jsp/solutions/soa_solution.jsp?itemId=86 WebKing] || tool_owner = Parasoft || tool_licence = Commercial || tool_platforms = Windows / Linux / Solaris}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/external-vulnerability-scanning.php Trustkeeper Scanner] || tool_owner = Trustwave SpiderLabs || tool_licence = Commercial || tool_platforms = SaaS}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.german-websecurity.com/en/products/webscanservice/product-details/overview/ WebScanService] || tool_owner = German Web Security || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com Websecurify] || tool_owner = GNUCITIZEN / Websecurify || tool_licence = Commercial / Free || tool_platforms = Windows, Mac OS, Linux and others}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.sensepost.com/research/wikto/ Wikto] || tool_owner = Sensepost || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project Zed Attack Proxy] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}} &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&lt;br /&gt;
*http://projects.webappsec.org/Web-Application-Security-Scanner-Evaluation-Criteria &lt;br /&gt;
*https://buildsecurityin.us-cert.gov/daisy/bsi/articles/tools/black-box/261-BSI.html#dsy261-BSI_Evaluation-Criteria &lt;br /&gt;
*http://www.uml.org.cn/Test/12/Automated%20Testing%20Tool%20Evaluation%20Matrix.pdf &lt;br /&gt;
*http://securityinnovation.com/security-report/October/vulnScanners15.htm &lt;br /&gt;
*http://samate.nist.gov/index.php/Web_Application_Vulnerability_Scanners.html &lt;br /&gt;
*http://www.tssci-security.com/archives/2007/11/24/2007-security-testing-tools-in-review/ &lt;br /&gt;
*http://www.softwareqatest.com/qatweb1.html&lt;br /&gt;
*http://www.proactiverisk.com/tools-page&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Tools_Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=161922</id>
		<title>Category:Vulnerability Scanning Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:Vulnerability_Scanning_Tools&amp;diff=161922"/>
				<updated>2013-10-28T19:46:33Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Stub}} &lt;br /&gt;
&lt;br /&gt;
== Description  ==&lt;br /&gt;
&lt;br /&gt;
Web Application Vulnerability Scanners are the automated tools that scan web applications to look for known security vulnerabilities such as cross-site scripting, SQL injection, command execution, directory traversal and insecure server configuration. A large number of both commercial and open source tools are available and and all these tools have their own strengths and weaknesses. &lt;br /&gt;
&lt;br /&gt;
Here we will provide a listing of vulnerability scanning tools currently available in the market. The plan is to extend this listing to provide information about each tool's strengths and weaknesses to enable you to make an informed decision about the selection of a particular tool to meet your requirements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt; '''Disclaimer:''' The tools listing in the table below has been presented in an alphabatical order. OWASP does not endorse any of the Vendors or Scanning Tools by listing them in the table below. We have made every effort to put this information as accurately as possible. If you are the vendor of a tool below and think that this information is incomplete or incorrect, please send an e-mail to our mailing list and we will make every effort to correct this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools Listing  ==&lt;br /&gt;
&lt;br /&gt;
{{:Template:OWASP Tool Headings}} &lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.acunetix.com/ Acunetix WVS] || tool_owner = Acunetix || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www-01.ibm.com/software/rational/offerings/websecurity/ AppScan] || tool_owner = IBM || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.portswigger.net/suite/ Burp Suite] || tool_owner = PortSwiger || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Most platforms supported }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://contrastsecurity.com Contrast] || tool_owner = Contrast Security (Aspect) || tool_licence = Commercial / Free (Limited Capability) || tool_platforms = Most platforms supported }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.gamasec.com/Gamascan.aspx GamaScan] || tool_owner = GamaSec || tool_licence = Commercial || tool_platforms = Windows }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://rgaucher.info/beta/grabber/ Grabber] || tool_owner = Romain Gaucher || tool_licence = Open Source || tool_platforms = Python 2.4, BeautifulSoup and PyXML}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://sourceforge.net/p/grendel/code/ci/c59780bfd41bdf34cc13b27bc3ce694fd3cb7456/tree/ Grendel-Scan] || tool_owner = David Byrne || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cenzic.com/ Hailstorm] || tool_owner = Cenzic || tool_licence = Commercial || tool_platforms = Windows }}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ikare-monitoring.com/ IKare] || tool_owner = ITrust || tool_licence = Commercial || tool_platforms = N/A }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.nstalker.com/ N-Stealth] || tool_owner = N-Stalker || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.mavitunasecurity.com/ Netsparker] || tool_owner = MavitunaSecurity || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.rapid7.com/products/nexpose-community-edition.jsp NeXpose] || tool_owner = Rapid7 || tool_licence = Commercial / Free (Limited Capability)|| tool_platforms = Windows/Linux}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.cirt.net/nikto2 Nikto] || tool_owner = CIRT || tool_licence = Open Source|| tool_platforms = Unix/Linux}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ntobjectives.com/ntospider NTOSpider] || tool_owner = NT OBJECTives || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.milescan.com/hk/ ParosPro] || tool_owner = MileSCAN || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.qualys.com/products/qg_suite/was/ QualysGuard] || tool_owner = Qualys || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.beyondtrust.com/Products/RetinaNetworkSecurityScanner/ Retina] || tool_owner = BeyondTrust || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.kavado.com/ ScanDo] || tool_owner = KaVaDo Inc || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.isecpartners.com/SecurityQAToolbar.html SecurityQA Toolbar] || tool_owner = iSec Partners || tool_licence = Commercial || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.orvant.com Securus] || tool_owner = Orvant, Inc || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.secpoint.com/penetrator.html SecPoint Penetrator] || tool_owner = SecPoint || tool_licence = Commercial || tool_platforms = Windows, Unix/Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.whitehatsec.com/home/services/services.html Sentinel] || tool_owner = WhiteHat Security || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.subgraph.com/products.html Vega] || tool_owner = Subgraph || tool_licence = Open Source || tool_platforms = Windows, Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://wapiti.sourceforge.net/ Wapiti] || tool_owner = Informática Gesfor || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.ncircle.com/index.php?s=products_webapp360 WebApp360] || tool_owner = nCircle || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&amp;amp;cp=1-11-201-200^9570_4000_100__ WebInspect] || tool_owner = HP || tool_licence = Commercial || tool_platforms = Windows}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.openvas.org OpenVAS] || tool_owner = OpenVAS || tool_licence = Open Source || tool_platforms = Windows / Linux }} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.parasoft.com/jsp/solutions/soa_solution.jsp?itemId=86 WebKing] || tool_owner = Parasoft || tool_licence = Commercial || tool_platforms = Windows / Linux / Solaris}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.trustwave.com/external-vulnerability-scanning.php Trustkeeper Scanner] || tool_owner = Trustwave SpiderLabs || tool_licence = Commercial || tool_platforms = SaaS}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.german-websecurity.com/en/products/webscanservice/product-details/overview/ WebScanService] || tool_owner = German Web Security || tool_licence = Commercial || tool_platforms = N/A}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.websecurify.com Websecurify] || tool_owner = GNUCITIZEN / Websecurify || tool_licence = Commercial / Free || tool_platforms = Windows, Mac OS, Linux and others}} &lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [http://www.sensepost.com/research/wikto/ Wikto] || tool_owner = Sensepost || tool_licence = Open Source || tool_platforms = Windows}}&lt;br /&gt;
|&lt;br /&gt;
{{OWASP Tool Info || tool_name = [https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project Zed Attack Proxy] || tool_owner = OWASP || tool_licence = Open Source || tool_platforms = Windows, Unix/Linux and Macintosh}} &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&lt;br /&gt;
*http://projects.webappsec.org/Web-Application-Security-Scanner-Evaluation-Criteria &lt;br /&gt;
*https://buildsecurityin.us-cert.gov/daisy/bsi/articles/tools/black-box/261-BSI.html#dsy261-BSI_Evaluation-Criteria &lt;br /&gt;
*http://www.uml.org.cn/Test/12/Automated%20Testing%20Tool%20Evaluation%20Matrix.pdf &lt;br /&gt;
*http://securityinnovation.com/security-report/October/vulnScanners15.htm &lt;br /&gt;
*http://samate.nist.gov/index.php/Web_Application_Vulnerability_Scanners.html &lt;br /&gt;
*http://www.tssci-security.com/archives/2007/11/24/2007-security-testing-tools-in-review/ &lt;br /&gt;
*http://www.softwareqatest.com/qatweb1.html&lt;br /&gt;
*http://www.proactiverisk.com/tools-page&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP_Tools_Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161508</id>
		<title>Business Logic Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161508"/>
				<updated>2013-10-24T18:35:33Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides some guidance for identifying some of the various types of business logic vulnerabilities and some guidance for preventing and testing for them.&lt;br /&gt;
&lt;br /&gt;
= What is Business Logic Vulnerability? =&lt;br /&gt;
&lt;br /&gt;
Business logic vulnerability is one that allows the attacker to misuse an application by circumventing the business rules.  Most security problems are weaknesses in an application that result from a broken or missing security control (authentication, access control, input validation, etc...). By contrast, business logic vulnerabilities are ways of using the legitimate processing flow of an application in a way that results in a negative consequence to the organization. &lt;br /&gt;
&lt;br /&gt;
Many articles that describe business logic problems simply take an existing and well understood web application security problem and discuss the business consequence of the vulnerability. True business logic problems are actually different from the typical security vulnerability. Too often, the business logic category is used for vulnerabilities that can't be scanned for automatically. This makes it very difficult to apply any kind of categorization scheme. A useful rule-of-thumb to use is that if you need to truly understand the business to understand the vulnerability, you might have a business-logic problem on your hands. If you don't understand the business, then it's probably just a typical application vulnerability in one of the other categories.&lt;br /&gt;
&lt;br /&gt;
For example, an electronic bulletin board system was designed to ensure that initial posts do not contain profanity based on a list that the post is compared against. If a word on the list is found the submission is not posted. But, once a submission is posted the submitter can access, edit, and change the submission contents to include words included on the profanity list since on edit the posting is never compared again. &lt;br /&gt;
&lt;br /&gt;
Testing for business rules vulnerabilities involves developing business logic abuse cases with the goal of successfully completing the business process while not complying with one or more of the business rules.&lt;br /&gt;
&lt;br /&gt;
= 1. Identify Business Rules and Derive Test/Abuse Cases =&lt;br /&gt;
&lt;br /&gt;
The first step is to identify the business rules that you care about and turn them into experiments designed to verify whether the application properly enforces the business rule.  For example, if the rule is that purchases over $1000 are discounted by 10%, then positive and negative tests should be designed to ensure that&lt;br /&gt;
#) the control is in place to implement the business rule,&lt;br /&gt;
#) the control is implemented correctly and cannot be bypassed or tampered with, and&lt;br /&gt;
#) the control is used properly in all the necessary places&lt;br /&gt;
&lt;br /&gt;
Business rules vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent any business rules, constraints or restrictions put in place to properly complete the business process.  &lt;br /&gt;
For example, on a stock trading application is the attacker allowed to start a trade at the beginning of the day and lock in a price, hold the transaction open until the end of the day, then complete the sale if the stock price has risen or cancel out if the price dropped.    &lt;br /&gt;
Business Logic testing uses many of the same testing tools and techniques used by functional testers. While a majority of Business Logic testing remains an art relying on the manual skills of the tester, their knowledge of the complete business process, and its rules, the actual testing may involve the use of some functional and security testing tools.&lt;br /&gt;
&lt;br /&gt;
= 2. Consider Time Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used to change orders after they are committed, make transactions appear in the wrong sequence, etc...&lt;br /&gt;
&lt;br /&gt;
The application must be time-aware and not allow attackers to hold transactions open preventing them completing until and unless it is advantageous to do so.   &lt;br /&gt;
&lt;br /&gt;
= 3. Consider Money Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: These should cover financial limits and other undesirable transactions.  Can the application be used to create inappropriate financial transactions?  Does it allow the use of NaN or Infinity?  Are inaccuracies introduced because of the data structures used to model money?&lt;br /&gt;
&lt;br /&gt;
= 4. Consider Process Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for steps in a process, approvals, communications, etc... Can the application be used to bypass or otherwise abuse the steps in a process?&lt;br /&gt;
&lt;br /&gt;
Workflow vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent the designed workflow or continue once the workflow has been broken.   For example, an ecommerce site that give loyalty points for each dollar spent should not apply points to the customer’s account until the transaction is tendered. Applying points to the account before tendering may allow the customer to cancel the transaction and incorrectly receive points.&lt;br /&gt;
&lt;br /&gt;
The application must have checks in place ensuring that the users complete each step in the process in the correct order and prevent attackers from circumventing any steps/processes in the workflow. &lt;br /&gt;
Test for workflow vulnerabilities involves attempts to execute the steps in the process in an inappropriate order. &lt;br /&gt;
&lt;br /&gt;
= 5. Consider Human Resource Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for rules surrounding HR. Could the application be used to violate any HR procedures or standards&lt;br /&gt;
&lt;br /&gt;
= 6. Consider Contractual Relationship Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used in a manner that is inconsistent with any contractual relationships -- such as a contract with a service provider&lt;br /&gt;
&lt;br /&gt;
= 7. TBD - Let's think of some other REAL Business Rules =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
WARNING: Most of the examples discussed in these articles are not actually business logic flaws&lt;br /&gt;
&lt;br /&gt;
* Seven Business Logic Flaws That Put Your Website At Risk – Jeremiah Grossman Founder and CTO, WhiteHat Security – &lt;br /&gt;
https://www.whitehatsec.com/assets/WP_bizlogic092407.pdf&lt;br /&gt;
* Top 10 Business Logic Attack Vectors Attacking and Exploiting Business Application Assets and Flaws – Vulnerability Detection to Fix - http://www.ntobjectives.com/go/business-logic-attack-vectors-white-paper/ and http://www.ntobjectives.com/files/Business_Logic_White_Paper.pdf&lt;br /&gt;
* CWE-840: Business Logic Errors - http://cwe.mitre.org/data/definitions/840.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Ashish Rao rao.ashish20[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
David Fern dfern[at]verizon.net&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161507</id>
		<title>Business Logic Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161507"/>
				<updated>2013-10-24T18:35:09Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides some guidance for identifying some of the various types of business logic vulnerabilities and some guidance for preventing and testing for them.&lt;br /&gt;
&lt;br /&gt;
= What is Business Logic Vulnerability? =&lt;br /&gt;
&lt;br /&gt;
Business logic vulnerability is one that allows the attacker to misuse an application by circumventing the business rules.  Most security problems are weaknesses in an application that result from a broken or missing security control (authentication, access control, input validation, etc...). By contrast, business logic vulnerabilities are ways of using the legitimate processing flow of an application in a way that results in a negative consequence to the organization. &lt;br /&gt;
&lt;br /&gt;
Many articles that describe business logic problems simply take an existing and well understood web application security problem and discuss the business consequence of the vulnerability. True business logic problems are actually different from the typical security vulnerability. Too often, the business logic category is used for vulnerabilities that can't be scanned for automatically. This makes it very difficult to apply any kind of categorization scheme. A useful rule-of-thumb to use is that if you need to truly understand the business to understand the vulnerability, you might have a business-logic problem on your hands. If you don't understand the business, then it's probably just a typical application vulnerability in one of the other categories.&lt;br /&gt;
&lt;br /&gt;
For example, an electronic bulletin board system was designed to ensure that initial posts do not contain profanity based on a list that the post is compared against. If a word on the list is found the submission is not posted. But, once a submission is posted the submitter can access, edit, and change the submission contents to include words included on the profanity list since on edit the posting is never compared again. &lt;br /&gt;
&lt;br /&gt;
Testing for business rules vulnerabilities involves developing business logic abuse cases with the goal of successfully completing the business process while not complying with one or more of the business rules.&lt;br /&gt;
&lt;br /&gt;
= 1. Identify Business Rules and Derive Test/Abuse Cases =&lt;br /&gt;
&lt;br /&gt;
The first step is to identify the business rules that you care about and turn them into experiments designed to verify whether the application properly enforces the business rule.  For example, if the rule is that purchases over $1000 are discounted by 10%, then positive and negative tests should be designed to ensure that&lt;br /&gt;
#) the control is in place to perform the transactions,&lt;br /&gt;
#) the control is implemented correctly and cannot be bypassed or tampered with, and&lt;br /&gt;
#) the control is used properly in all the necessary places&lt;br /&gt;
&lt;br /&gt;
Business rules vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent any business rules, constraints or restrictions put in place to properly complete the business process.  &lt;br /&gt;
For example, on a stock trading application is the attacker allowed to start a trade at the beginning of the day and lock in a price, hold the transaction open until the end of the day, then complete the sale if the stock price has risen or cancel out if the price dropped.    &lt;br /&gt;
Business Logic testing uses many of the same testing tools and techniques used by functional testers. While a majority of Business Logic testing remains an art relying on the manual skills of the tester, their knowledge of the complete business process, and its rules, the actual testing may involve the use of some functional and security testing tools.&lt;br /&gt;
&lt;br /&gt;
= 2. Consider Time Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used to change orders after they are committed, make transactions appear in the wrong sequence, etc...&lt;br /&gt;
&lt;br /&gt;
The application must be time-aware and not allow attackers to hold transactions open preventing them completing until and unless it is advantageous to do so.   &lt;br /&gt;
&lt;br /&gt;
= 3. Consider Money Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: These should cover financial limits and other undesirable transactions.  Can the application be used to create inappropriate financial transactions?  Does it allow the use of NaN or Infinity?  Are inaccuracies introduced because of the data structures used to model money?&lt;br /&gt;
&lt;br /&gt;
= 4. Consider Process Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for steps in a process, approvals, communications, etc... Can the application be used to bypass or otherwise abuse the steps in a process?&lt;br /&gt;
&lt;br /&gt;
Workflow vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent the designed workflow or continue once the workflow has been broken.   For example, an ecommerce site that give loyalty points for each dollar spent should not apply points to the customer’s account until the transaction is tendered. Applying points to the account before tendering may allow the customer to cancel the transaction and incorrectly receive points.&lt;br /&gt;
&lt;br /&gt;
The application must have checks in place ensuring that the users complete each step in the process in the correct order and prevent attackers from circumventing any steps/processes in the workflow. &lt;br /&gt;
Test for workflow vulnerabilities involves attempts to execute the steps in the process in an inappropriate order. &lt;br /&gt;
&lt;br /&gt;
= 5. Consider Human Resource Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for rules surrounding HR. Could the application be used to violate any HR procedures or standards&lt;br /&gt;
&lt;br /&gt;
= 6. Consider Contractual Relationship Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used in a manner that is inconsistent with any contractual relationships -- such as a contract with a service provider&lt;br /&gt;
&lt;br /&gt;
= 7. TBD - Let's think of some other REAL Business Rules =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
WARNING: Most of the examples discussed in these articles are not actually business logic flaws&lt;br /&gt;
&lt;br /&gt;
* Seven Business Logic Flaws That Put Your Website At Risk – Jeremiah Grossman Founder and CTO, WhiteHat Security – &lt;br /&gt;
https://www.whitehatsec.com/assets/WP_bizlogic092407.pdf&lt;br /&gt;
* Top 10 Business Logic Attack Vectors Attacking and Exploiting Business Application Assets and Flaws – Vulnerability Detection to Fix - http://www.ntobjectives.com/go/business-logic-attack-vectors-white-paper/ and http://www.ntobjectives.com/files/Business_Logic_White_Paper.pdf&lt;br /&gt;
* CWE-840: Business Logic Errors - http://cwe.mitre.org/data/definitions/840.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Ashish Rao rao.ashish20[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
David Fern dfern[at]verizon.net&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161506</id>
		<title>Business Logic Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161506"/>
				<updated>2013-10-24T18:34:42Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides some guidance for identifying some of the various types of business logic vulnerabilities and some guidance for preventing and testing for them.&lt;br /&gt;
&lt;br /&gt;
= What is Business Logic Vulnerability? =&lt;br /&gt;
&lt;br /&gt;
Business logic vulnerability is one that allows the attacker to misuse an application by circumventing the business rules.  Most security problems are weaknesses in an application that result from a broken or missing security control (authentication, access control, input validation, etc...). By contrast, business logic vulnerabilities are ways of using the legitimate processing flow of an application in a way that results in a negative consequence to the organization. &lt;br /&gt;
&lt;br /&gt;
Many articles that describe business logic problems simply take an existing and well understood web application security problem and discuss the business consequence of the vulnerability. True business logic problems are actually different from the typical security vulnerability. Too often, the business logic category is used for vulnerabilities that can't be scanned for automatically. This makes it very difficult to apply any kind of categorization scheme. A useful rule-of-thumb to use is that if you need to truly understand the business to understand the vulnerability, you might have a business-logic problem on your hands. If you don't understand the business, then it's probably just a typical application vulnerability in one of the other categories.&lt;br /&gt;
&lt;br /&gt;
For example, an electronic bulletin board system was designed to ensure that initial posts do not contain profanity based on a list that the post is compared against. If a word on the list is found the submission is not posted. But, once a submission is posted the submitter can access, edit, and change the submission contents to include words included on the profanity list since on edit the posting is never compared again. &lt;br /&gt;
&lt;br /&gt;
Testing for business rules vulnerabilities involves developing business logic abuse cases with the goal of successfully completing the business process while not complying with one or more of the business rules.&lt;br /&gt;
&lt;br /&gt;
= 1. Identify Business Rules and Derive Test/Abuse Cases =&lt;br /&gt;
&lt;br /&gt;
The first step is to identify the business rules that you care about and turn them into experiments designed to verify whether the application properly enforces the business rule.  For example, if the rule is that purchases over $1000 are discounted by 10%, then positive and negative tests should be designed to ensure that&lt;br /&gt;
1) the control is in place to perform the transactions,&lt;br /&gt;
2) the control is implemented correctly and cannot be bypassed or tampered with, and&lt;br /&gt;
3) the control is used properly in all the necessary places&lt;br /&gt;
&lt;br /&gt;
Business rules vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent any business rules, constraints or restrictions put in place to properly complete the business process.  &lt;br /&gt;
For example, on a stock trading application is the attacker allowed to start a trade at the beginning of the day and lock in a price, hold the transaction open until the end of the day, then complete the sale if the stock price has risen or cancel out if the price dropped.    &lt;br /&gt;
Business Logic testing uses many of the same testing tools and techniques used by functional testers. While a majority of Business Logic testing remains an art relying on the manual skills of the tester, their knowledge of the complete business process, and its rules, the actual testing may involve the use of some functional and security testing tools.&lt;br /&gt;
&lt;br /&gt;
= 2. Consider Time Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used to change orders after they are committed, make transactions appear in the wrong sequence, etc...&lt;br /&gt;
&lt;br /&gt;
The application must be time-aware and not allow attackers to hold transactions open preventing them completing until and unless it is advantageous to do so.   &lt;br /&gt;
&lt;br /&gt;
= 3. Consider Money Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: These should cover financial limits and other undesirable transactions.  Can the application be used to create inappropriate financial transactions?  Does it allow the use of NaN or Infinity?  Are inaccuracies introduced because of the data structures used to model money?&lt;br /&gt;
&lt;br /&gt;
= 4. Consider Process Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for steps in a process, approvals, communications, etc... Can the application be used to bypass or otherwise abuse the steps in a process?&lt;br /&gt;
&lt;br /&gt;
Workflow vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent the designed workflow or continue once the workflow has been broken.   For example, an ecommerce site that give loyalty points for each dollar spent should not apply points to the customer’s account until the transaction is tendered. Applying points to the account before tendering may allow the customer to cancel the transaction and incorrectly receive points.&lt;br /&gt;
&lt;br /&gt;
The application must have checks in place ensuring that the users complete each step in the process in the correct order and prevent attackers from circumventing any steps/processes in the workflow. &lt;br /&gt;
Test for workflow vulnerabilities involves attempts to execute the steps in the process in an inappropriate order. &lt;br /&gt;
&lt;br /&gt;
= 5. Consider Human Resource Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for rules surrounding HR. Could the application be used to violate any HR procedures or standards&lt;br /&gt;
&lt;br /&gt;
= 6. Consider Contractual Relationship Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used in a manner that is inconsistent with any contractual relationships -- such as a contract with a service provider&lt;br /&gt;
&lt;br /&gt;
= 7. TBD - Let's think of some other REAL Business Rules =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
WARNING: Most of the examples discussed in these articles are not actually business logic flaws&lt;br /&gt;
&lt;br /&gt;
* Seven Business Logic Flaws That Put Your Website At Risk – Jeremiah Grossman Founder and CTO, WhiteHat Security – &lt;br /&gt;
https://www.whitehatsec.com/assets/WP_bizlogic092407.pdf&lt;br /&gt;
* Top 10 Business Logic Attack Vectors Attacking and Exploiting Business Application Assets and Flaws – Vulnerability Detection to Fix - http://www.ntobjectives.com/go/business-logic-attack-vectors-white-paper/ and http://www.ntobjectives.com/files/Business_Logic_White_Paper.pdf&lt;br /&gt;
* CWE-840: Business Logic Errors - http://cwe.mitre.org/data/definitions/840.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Ashish Rao rao.ashish20[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
David Fern dfern[at]verizon.net&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161505</id>
		<title>Business Logic Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161505"/>
				<updated>2013-10-24T18:29:54Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides some guidance for identifying some of the various types of business logic vulnerabilities and some guidance for preventing and testing for them.&lt;br /&gt;
&lt;br /&gt;
= What is Business Logic Vulnerability? =&lt;br /&gt;
&lt;br /&gt;
Business logic vulnerability is one that allows the attacker to misuse an application by circumventing the business rules, workflow or privilege manipulation. &lt;br /&gt;
&lt;br /&gt;
An electronic bulletin board system was designed to ensure that initial posts do not contain profanity based on a list that the post is compared against. If a word on the list is found the submission is not posted. But, once a submission is posted the submitter can access, edit, and change the submission contents to include words included on the profanity list since on edit the posting is never compared again. &lt;br /&gt;
&lt;br /&gt;
While there is no definitive list of possible business logic issues this section provides some guidance and common groups and generic areas to consider. The process for testing for business logic vulnerabilities requires following a process similar to those used in functional testing including: &lt;br /&gt;
# Requirements and Design Review – Understand the application – scope, features, business rules and roles and privilege levels.&lt;br /&gt;
# Test Planning – Gather data, roles and scenarios, understand workflows and approval levels.&lt;br /&gt;
# Test Case Design – Write the test cases i.e. abuse cases&lt;br /&gt;
# Test Environment Setup – Build the test bed &lt;br /&gt;
# Test Execution – Execute the tests&lt;br /&gt;
# Test Reporting – Save and report results&lt;br /&gt;
&lt;br /&gt;
Testing for business rules vulnerabilities involves developing business logic abuse cases with the goal of successfully completing the business process while not complying with one or more of the business rules.&lt;br /&gt;
&lt;br /&gt;
= 1. Identify Business Rules and Derive Test/Abuse Cases =&lt;br /&gt;
&lt;br /&gt;
The first step is to identify the business rules that you care about and turn them into experiments designed to verify whether the application properly enforces the business rule.  For example, if the rule is that purchases over $1000 are discounted by 10%, then positive and negative tests should be designed to ensure that&lt;br /&gt;
1) the control is in place to perform the transactions,&lt;br /&gt;
2) the control is implemented correctly and cannot be bypassed or tampered with, and&lt;br /&gt;
3) the control is used properly in all the necessary places&lt;br /&gt;
&lt;br /&gt;
Business rules vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent any business rules, constraints or restrictions put in place to properly complete the business process.  &lt;br /&gt;
For example, on a stock trading application is the attacker allowed to start a trade at the beginning of the day and lock in a price, hold the transaction open until the end of the day, then complete the sale if the stock price has risen or cancel out if the price dropped.    &lt;br /&gt;
Business Logic testing uses many of the same testing tools and techniques used by functional testers. While a majority of Business Logic testing remains an art relying on the manual skills of the tester, their knowledge of the complete business process, and its rules, the actual testing may involve the use of some functional and security testing tools.&lt;br /&gt;
&lt;br /&gt;
= 2. Consider Time Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used to change orders after they are committed, make transactions appear in the wrong sequence, etc...&lt;br /&gt;
&lt;br /&gt;
The application must be time-aware and not allow attackers to hold transactions open preventing them completing until and unless it is advantageous to do so.   &lt;br /&gt;
&lt;br /&gt;
= 3. Consider Money Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: These should cover financial limits and other undesirable transactions.  Can the application be used to create inappropriate financial transactions?  Does it allow the use of NaN or Infinity?  Are inaccuracies introduced because of the data structures used to model money?&lt;br /&gt;
&lt;br /&gt;
= 4. Consider Process Related Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for steps in a process, approvals, communications, etc... Can the application be used to bypass or otherwise abuse the steps in a process?&lt;br /&gt;
&lt;br /&gt;
Workflow vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent the designed workflow or continue once the workflow has been broken.   For example, an ecommerce site that give loyalty points for each dollar spent should not apply points to the customer’s account until the transaction is tendered. Applying points to the account before tendering may allow the customer to cancel the transaction and incorrectly receive points.&lt;br /&gt;
&lt;br /&gt;
The application must have checks in place ensuring that the users complete each step in the process in the correct order and prevent attackers from circumventing any steps/processes in the workflow. &lt;br /&gt;
Test for workflow vulnerabilities involves attempts to execute the steps in the process in an inappropriate order. &lt;br /&gt;
&lt;br /&gt;
= 5. Consider Human Resource Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: This is for rules surrounding HR. Could the application be used to violate any HR procedures or standards&lt;br /&gt;
&lt;br /&gt;
= 6. Consider Contractual Relationship Business Rules =&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used in a manner that is inconsistent with any contractual relationships -- such as a contract with a service provider&lt;br /&gt;
&lt;br /&gt;
= 7. TBD - Let's think of some other REAL Business Rules =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
WARNING: Most of the examples discussed in these articles are not actually business logic flaws&lt;br /&gt;
&lt;br /&gt;
* Seven Business Logic Flaws That Put Your Website At Risk – Jeremiah Grossman Founder and CTO, WhiteHat Security – &lt;br /&gt;
https://www.whitehatsec.com/assets/WP_bizlogic092407.pdf&lt;br /&gt;
* Top 10 Business Logic Attack Vectors Attacking and Exploiting Business Application Assets and Flaws – Vulnerability Detection to Fix - http://www.ntobjectives.com/go/business-logic-attack-vectors-white-paper/ and http://www.ntobjectives.com/files/Business_Logic_White_Paper.pdf&lt;br /&gt;
* CWE-840: Business Logic Errors - http://cwe.mitre.org/data/definitions/840.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Ashish Rao rao.ashish20[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
David Fern dfern[at]verizon.net&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161504</id>
		<title>Business Logic Security Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_Logic_Security_Cheat_Sheet&amp;diff=161504"/>
				<updated>2013-10-24T18:24:14Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This cheat sheet provides some guidance for identifying some of the various types of business logic vulnerabilities and some guidance for preventing and testing for them.&lt;br /&gt;
&lt;br /&gt;
= What is Business Logic Vulnerability? =&lt;br /&gt;
&lt;br /&gt;
Business logic vulnerability is one that allows the attacker to misuse an application by circumventing the business rules, workflow or privilege manipulation. &lt;br /&gt;
&lt;br /&gt;
An electronic bulletin board system was designed to ensure that initial posts do not contain profanity based on a list that the post is compared against. If a word on the list is found the submission is not posted. But, once a submission is posted the submitter can access, edit, and change the submission contents to include words included on the profanity list since on edit the posting is never compared again. &lt;br /&gt;
&lt;br /&gt;
While there is no definitive list of possible business logic issues this section provides some guidance and common groups and generic areas to consider. The process for testing for business logic vulnerabilities requires following a process similar to those used in functional testing including: &lt;br /&gt;
# Requirements and Design Review – Understand the application – scope, features, business rules and roles and privilege levels.&lt;br /&gt;
# Test Planning – Gather data, roles and scenarios, understand workflows and approval levels.&lt;br /&gt;
# Test Case Design – Write the test cases i.e. abuse cases&lt;br /&gt;
# Test Environment Setup – Build the test bed &lt;br /&gt;
# Test Execution – Execute the tests&lt;br /&gt;
# Test Reporting – Save and report results&lt;br /&gt;
&lt;br /&gt;
Testing for business rules vulnerabilities involves developing business logic abuse cases with the goal of successfully completing the business process while not complying with any of the business rules.&lt;br /&gt;
In simple words an abuse case would be – reverse of the business rule. Creating an exhaustive list of abuse cases for all the features of the application and testing for them would enumerate all the business logic errors present in the application.&lt;br /&gt;
&lt;br /&gt;
= 1. Identify Business Rules and Derive Test/Abuse Cases =&lt;br /&gt;
&lt;br /&gt;
The first step is to identify the business rules that you care about and turn them into experiments designed to verify whether the application properly enforces the business rule.  For example, if the rule is that purchases over $1000 are discounted by 10%, then positive and negative tests should be designed to ensure that&lt;br /&gt;
1) the control is in place to perform the transactions,&lt;br /&gt;
2) the control is implemented correctly and cannot be bypassed or tampered with, and&lt;br /&gt;
3) the control is used properly in all the necessary places&lt;br /&gt;
&lt;br /&gt;
Business rules vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent any business rules, constraints or restrictions put in place to properly complete the business process.  &lt;br /&gt;
For example, on a stock trading application is the attacker allowed to start a trade at the beginning of the day and lock in a price, hold the transaction open until the end of the day, then complete the sale if the stock price has risen or cancel out if the price dropped.    &lt;br /&gt;
Business Logic testing uses many of the same testing tools and techniques used by functional testers. While a majority of Business Logic testing remains an art relying on the manual skills of the tester, their knowledge of the complete business process, and its rules, some testing can be automated using functional and security testing tools.&lt;br /&gt;
&lt;br /&gt;
= 2. Consider Time Related Business Rules ===&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used to change orders after they are committed, make transactions appear in the wrong sequence, etc...&lt;br /&gt;
&lt;br /&gt;
The application must be time-aware and not allow attackers to hold transactions open preventing them completing until and unless it is advantageous to do so.   &lt;br /&gt;
&lt;br /&gt;
= 3. Consider Money Related Business Rules ===&lt;br /&gt;
&lt;br /&gt;
TBD: These should cover financial limits and other undesirable transactions.  Can the application be used to create inappropriate financial transactions?  Does it allow the use of NaN or Infinity?  Are inaccuracies introduced because of the data structures used to model money?&lt;br /&gt;
&lt;br /&gt;
= 4. Consider Process Related Business Rules ===&lt;br /&gt;
&lt;br /&gt;
TBD: This is for steps in a process, approvals, communications, etc... Can the application be used to bypass or otherwise abuse the steps in a process?&lt;br /&gt;
&lt;br /&gt;
Workflow vulnerabilities involve any type of vulnerability that allows the attacker to misuse an application in a way that will allow them to circumvent the designed workflow or continue once the workflow has been broken.   For example, an ecommerce site that give loyalty points for each dollar spent should not apply points to the customer’s account until the transaction is tendered. Applying points to the account before tendering may allow the customer to cancel the transaction and incorrectly receive points.&lt;br /&gt;
&lt;br /&gt;
The application must have checks in place ensuring that the users complete each step in the process in the correct order and prevent attackers from circumventing any steps/processes in the workflow. &lt;br /&gt;
Test for workflow vulnerabilities involves attempts to execute the steps in the process in an inappropriate order. &lt;br /&gt;
&lt;br /&gt;
= 5. Consider Human Resource Business Rules&lt;br /&gt;
&lt;br /&gt;
TBD: This is for rules surrounding HR. Could the application be used to violate any HR procedures or standards&lt;br /&gt;
&lt;br /&gt;
= 6. Consider Contractual Relationship Business Rules&lt;br /&gt;
&lt;br /&gt;
TBD: Can the application be used in a manner that is inconsistent with any contractual relationships -- such as a contract with a service provider&lt;br /&gt;
&lt;br /&gt;
= 7. TBD - Let's think of some other REAL Business Rules&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related Articles  =&lt;br /&gt;
&lt;br /&gt;
WARNING: Most of the examples discussed in these articles are not actually business logic flaws&lt;br /&gt;
&lt;br /&gt;
* Seven Business Logic Flaws That Put Your Website At Risk – Jeremiah Grossman Founder and CTO, WhiteHat Security – &lt;br /&gt;
https://www.whitehatsec.com/assets/WP_bizlogic092407.pdf&lt;br /&gt;
* Top 10 Business Logic Attack Vectors Attacking and Exploiting Business Application Assets and Flaws – Vulnerability Detection to Fix - http://www.ntobjectives.com/go/business-logic-attack-vectors-white-paper/ and http://www.ntobjectives.com/files/Business_Logic_White_Paper.pdf&lt;br /&gt;
* CWE-840: Business Logic Errors - http://cwe.mitre.org/data/definitions/840.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Ashish Rao rao.ashish20[at]gmail.com&amp;lt;br/&amp;gt;&lt;br /&gt;
David Fern dfern[at]verizon.net&lt;br /&gt;
&lt;br /&gt;
== Other Cheatsheets ==&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_logic_vulnerability&amp;diff=161498</id>
		<title>Business logic vulnerability</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_logic_vulnerability&amp;diff=161498"/>
				<updated>2013-10-24T14:16:18Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: Undo revision 61074 by Ya Ali (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Vulnerability}}&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
Most security problems are weaknesses in an application that result from a broken or missing security control (authentication, access control, input validation, etc...). By contrast, business logic vulnerabilities are ways of using the legitimate processing flow of an application in a way that results in a negative consequence to the organization. For example:&lt;br /&gt;
&lt;br /&gt;
* Purchase orders are not processed before midnight&lt;br /&gt;
* Written authorization is not on file before web access is granted&lt;br /&gt;
* Transactions in excess of $2000 are not reviewed by a person&lt;br /&gt;
&lt;br /&gt;
Many articles that describe business logic problems simply take an existing and well understood web application security problem and discuss the business consequence of the vulnerability. True business logic problems are actually different from the typical security vulnerability. Here are some examples of problems that are not business logic vulnerabilities:&lt;br /&gt;
&lt;br /&gt;
* Performing a denial of service by locking an auction user's account&lt;br /&gt;
* Posting unvalidated input publically&lt;br /&gt;
* Cracking MD5 hashes&lt;br /&gt;
* Brute forcing a password recovery scheme&lt;br /&gt;
&lt;br /&gt;
Too often, the business logic category is used for vulnerabilities that can't be scanned for automatically. This makes it very difficult to apply any kind of categorization scheme. Business logic problems are different from authentication problems and every other category. There are many signficant business logic vulnerabilities, but they are far less common than the type of items in the OWASP Top Ten for example.&lt;br /&gt;
&lt;br /&gt;
A nice rule-of-thumb to use is that if you need to truly understand the business to understand the vulnerability, you might have a business-logic problem on your hands. If you don't understand the business, you can't see business logic flaws.&lt;br /&gt;
&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
&lt;br /&gt;
The likelihood of business logic problems really depends on the circumstances. You'll need to evaluate the threat agents who could possibly exploit the problem and whether it would be detected. Again, this will take a strong understanding of the business.  The vulnerabilities themselves are often quite easy to discover and exploit without any special tools or techniques, as they are a supported part of the application.&lt;br /&gt;
&lt;br /&gt;
Business logic flaws are often the most critical in terms of consequences, as they are deeply tied into the company's process.&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
&lt;br /&gt;
Fraud&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
&lt;br /&gt;
==Related [[Technical Impacts]]==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
[[Category:Vulnerability]]&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Business_logic_vulnerability&amp;diff=161497</id>
		<title>Business logic vulnerability</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Business_logic_vulnerability&amp;diff=161497"/>
				<updated>2013-10-24T14:16:08Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: Undo revision 61075 by Ya Ali (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Vulnerability}}&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
==Brief Summary of Business Logic Vulnerability==&lt;br /&gt;
&lt;br /&gt;
The most recent research represented about the concept Business Logic vulnerability by Jr.Scientist Faisal Nabi in the 24th Annual Computer Security Application Conference (ACSAC, 08)California, Dec 8-12 ,2008. &lt;br /&gt;
&lt;br /&gt;
(ACSAC,08)work in progress session: &lt;br /&gt;
&lt;br /&gt;
Designing a Secure Framework Method for Business Application Logic Integrity in e-Commerce Systems,Faisal Nabi, Distributed System Research Group, Department of Computer Science, Victoria University of Wellington, Wellington, New Zealand. http://www.acsac.org/2008/program/wip/ &lt;br /&gt;
&lt;br /&gt;
Business-level- Process Integration is based on business components integration, which takes part to process a certain job/task event, which comes into being because of business logic inside a component. When we talk about business process integration, which means integrating business component’s business processing logic,this integration completely rely upon that Business component’s Interface. A component interface is self descriptor which provides specification, which defines that which component offers, what service (such as,Account service provided by Account Component interface, this is called Component interface specification,which reflects component’s business process functionality, which indicates a component offer a particular service)Integration of components is limited through only the interface. Therefore, business process integration, which depends on component’s interface specification in business component, it refers to business function / processing logic, specification of that business component (Components are reusable units for composition. This statement captures the very fundamental concept of component-based development, that an application is made up and composed of a number of individual parts,and that these parts are specifically designed for integration in a number of different applications. It also captures the “idea that one component may be part of another component” , or part of a sub-system or system, both of which represent components in their own right), and integration of all this process, then develop overall business processing logic for a business component-based software to develop an application in the middle-tier, which connected with information system in the back-end systems of organization. &lt;br /&gt;
&lt;br /&gt;
Since, this business process integration is made on the base of business functional concern; it can not be dealt with technological point of view, because problem is not based on technical or technological specific principle of Integration, which is based on related to some particular component model, but as it is stated above, issue identifies that business processing designed solution based on business components and their business processing integration. This is a point , where the focus is set to the logical structure of the “business solution”, this is the stage where logical problems occurs due to lack of paying attention to the design-based testing environment for Logical structure of the business solution , are known as Business Logic Vulnerabilities (Faisal Nabi, 2008). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most security problems are weaknesses in an application that result from a broken or missing security control (authentication, access control, input validation, etc...). By contrast, business logic vulnerabilities are ways of using the legitimate processing flow of an application in a way that results in a negative consequence to the organization. For example:&lt;br /&gt;
&lt;br /&gt;
* Purchase orders are not processed before midnight&lt;br /&gt;
* Written authorization is not on file before web access is granted&lt;br /&gt;
* Transactions in excess of $2000 are not reviewed by a person&lt;br /&gt;
&lt;br /&gt;
Many articles that describe business logic problems simply take an existing and well understood web application security problem and discuss the business consequence of the vulnerability. True business logic problems are actually different from the typical security vulnerability. Here are some examples of problems that are not business logic vulnerabilities:&lt;br /&gt;
&lt;br /&gt;
* Performing a denial of service by locking an auction user's account&lt;br /&gt;
* Posting unvalidated input publically&lt;br /&gt;
* Cracking MD5 hashes&lt;br /&gt;
* Brute forcing a password recovery scheme&lt;br /&gt;
&lt;br /&gt;
Too often, the business logic category is used for vulnerabilities that can't be scanned for automatically. This makes it very difficult to apply any kind of categorization scheme. Business logic problems are different from authentication problems and every other category. There are many signficant business logic vulnerabilities, but they are far less common than the type of items in the OWASP Top Ten for example.&lt;br /&gt;
&lt;br /&gt;
A nice rule-of-thumb to use is that if you need to truly understand the business to understand the vulnerability, you might have a business-logic problem on your hands. If you don't understand the business, you can't see business logic flaws.&lt;br /&gt;
&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
&lt;br /&gt;
The likelihood of business logic problems really depends on the circumstances. You'll need to evaluate the threat agents who could possibly exploit the problem and whether it would be detected. Again, this will take a strong understanding of the business.  The vulnerabilities themselves are often quite easy to discover and exploit without any special tools or techniques, as they are a supported part of the application.&lt;br /&gt;
&lt;br /&gt;
Business logic flaws are often the most critical in terms of consequences, as they are deeply tied into the company's process.&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
&lt;br /&gt;
Fraud&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
&lt;br /&gt;
==Related [[Technical Impacts]]==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
[[Category:Vulnerability]]&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Asldkjaslfdasdfasf&amp;diff=157440</id>
		<title>Asldkjaslfdasdfasf</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Asldkjaslfdasdfasf&amp;diff=157440"/>
				<updated>2013-08-27T20:58:49Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: Created page with &amp;quot;Using this test page.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Using this test page.&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=155386</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=155386"/>
				<updated>2013-07-11T19:38:31Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the [[XSS Filter Evasion Cheat Sheet]]. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
Before reading this cheatsheet, it is important to have a fundamental understanding of [[Injection Theory]].&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
Microsoft provides an encoding library named the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] for the .NET platform and ASP.NET Framework has built-in [http://msdn.microsoft.com/en-us/library/ms972969.aspx#securitybarriers_topic6 ValidateRequest] function that provides '''limited''' sanitization.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library for Java. OWASP also provides the [[OWASP Java Encoder Project]] for high-performance encoding.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; not recommended because its not in the HTML spec (See: [http://www.w3.org/TR/html4/sgml/entities.html section 24.4.1]) &amp;amp;amp;apos; is in the XML and XHTML specs.&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
=== RULE #3.1 - HTML escape JSON values in an HTML context and read the data with JSON.parse ===&lt;br /&gt;
&lt;br /&gt;
In a Web 2.0 world, the need for having data dynamically generated by an application in a javascript context is common.  One strategy is to make an AJAX call to get the values, but this isn't always performant.  Often, an initial block of JSON is loaded into the page to act as a single place to store multiple values.  This data is tricky, though not impossible, to escape correctly without breaking the format and content of the values.&lt;br /&gt;
&lt;br /&gt;
'''Ensure returned ''Content-Type'' header is application/json and not text/html. &lt;br /&gt;
This shall instruct the browser not misunderstand the contect and execute injected script'''&lt;br /&gt;
&lt;br /&gt;
'''Bad HTTP response:'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: text/html; charset=utf-8''' &amp;lt;-- bad&lt;br /&gt;
    ....&lt;br /&gt;
    Content-Length: 373&lt;br /&gt;
    Keep-Alive: timeout=5, max=100&lt;br /&gt;
    Connection: Keep-Alive&lt;br /&gt;
    {&amp;quot;Message&amp;quot;:&amp;quot;No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&amp;amp;AddressLine&lt;br /&gt;
    =The+Gardens'''&amp;amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;'''&amp;amp;AddressLine2=foxlodge+woods&amp;amp;TownName=Meath'.&amp;quot;,&amp;quot;MessageDetail&amp;quot;:&amp;quot;No type was found&lt;br /&gt;
    that matches the controller named 'pay'.&amp;quot;}   &amp;lt;-- this script will pop!!&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
'''Good HTTP response'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: application/json; charset=utf-8''' &amp;lt;--good&lt;br /&gt;
    .....&lt;br /&gt;
    .....&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A common '''anti-pattern''' one would see:&lt;br /&gt;
&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      var initData = &amp;lt;%= data.to_json %&amp;gt;; // '''Do NOT do this.'''&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, consider placing the JSON block on the page as a normal element and then parsing the innerHTML to get the contents.  The javascript that reads the span can live in an external file, thus making the implementation of CSP enforcement easier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script id=&amp;quot;init_data&amp;quot; type=&amp;quot;application/json&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;amp;lt;%= data.to_json %&amp;gt;  &amp;amp;lt;-- data is HTML escaped, or at least json entity escaped --&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
    var jsonText = document.getElementById('init_data').innerHTML;  // unescapes the content of the span&lt;br /&gt;
    var initData = JSON.parse(jsonText); &lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The data is added to the page and is HTML entity escaped so it won't pop in the HTML context.  The data is then read by innerHTML, which unescapes the value.  The unescaped text from the page is then parsed with JSON.parse.&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/span&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Sanitize HTML Markup with a Library Designed for the Job ==&lt;br /&gt;
&lt;br /&gt;
If your application handles markup -- untrusted input that is supposed to contain HTML -- it can be very difficult to validate. Encoding is also difficult, since it would break all the tags that are supposed to be in the input. Therefore, you need a library that can parse and clean HTML formatted text.  There are several available at OWASP that are simple to use:&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy''' - https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer''' - https://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
'''Other libraries that provide HTML Sanitization include:'''&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP Html Purifier - http://htmlpurifier.org/&amp;lt;br/&amp;gt;&lt;br /&gt;
JavaScript/Node.JS Bleach - https://github.com/ecto/bleach&amp;lt;br/&amp;gt;&lt;br /&gt;
Python Bleach - https://pypi.python.org/pypi/bleach&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The following snippets of HTML demonstrate how to safely render untrusted data in a variety of different contexts. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable nowraplinks&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Data Type&lt;br /&gt;
! Context&lt;br /&gt;
! Code Sample&lt;br /&gt;
! Defense&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;span&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;amp;lt;/span&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Safe HTML Attributes&lt;br /&gt;
| &amp;amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;fname&amp;quot; value=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes Aggressive HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Only place untrusted data into a whitelist of safe attributes (listed below).&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Strictly validate unsafe attributes such as background, id and name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| GET Parameter&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;/site/search?value=&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.235_-_URL_Escape_Before_Inserting_Untrusted_Data_into_HTML_URL_Parameter_Values URL Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Untrusted URL in a SRC or HREF attribute&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;iframe src=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Cannonicalize input&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;URL Validation&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Safe URL verification&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Whitelist http and https URL's only ([[Avoid the JavaScript Protocol to Open a new Window]])&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Attribute encoder&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| CSS Value&lt;br /&gt;
| &amp;amp;lt;div style=&amp;quot;width: &amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;;&amp;quot;&amp;gt;Selection&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values Strict structural validation]&amp;lt;li&amp;gt;CSS Hex encoding&amp;lt;li&amp;gt;Good design of CSS Features&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| JavaScript Variable&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;var currentValue='&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;';&amp;amp;lt;/script&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;script&amp;gt;someFunction('&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;');&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Ensure JavaScript variables are quoted&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Hex Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Unicode Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Avoid backslash encoding (\&amp;quot; or \' or \\)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| HTML&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;div&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED HTML&amp;lt;/span&amp;gt;&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Use_an_HTML_Policy_engine_to_validate_or_clean_user-driven_HTML_in_an_outbound_way HTML Validation (JSoup, AntiSamy, HTML Sanitizer)]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| DOM XSS&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;document.write(&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;quot;UNTRUSTED INPUT: &amp;quot; + document.location.hash&amp;lt;/span&amp;gt;);&amp;amp;lt;script/&amp;amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[[DOM based XSS Prevention Cheat Sheet]]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''''Safe HTML Attributes include:''''' align, alink, alt, bgcolor, border, cellpadding, cellspacing, class, color, cols, colspan, coords, dir, face, height, hspace, ismap, lang, marginheight, marginwidth, multiple, nohref, noresize, noshade, nowrap, ref, rel, rev, rows, rowspan, scrolling, shape, span, summary, tabindex, title, usemap, valign, value, vlink, vspace, width&lt;br /&gt;
&lt;br /&gt;
= Output Encoding Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The purpose of output encoding (as it relates to Cross Site Scripting) is to convert untrusted input into a safe form where the input is displayed as '''data''' to the user without executing as '''code''' in the browser. The following charts details a list of critical output encoding methods needed to stop Cross Site Scripting.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Encoding Type&lt;br /&gt;
! Encoding Mechanism&lt;br /&gt;
|-&lt;br /&gt;
| HTML Entity Encoding&lt;br /&gt;
|   Convert &amp;amp; to &amp;amp;amp;amp;&amp;lt;br/&amp;gt;Convert &amp;lt; to &amp;amp;amp;lt;&amp;lt;br/&amp;gt;Convert &amp;gt; to &amp;amp;amp;gt;&amp;lt;br/&amp;gt;Convert &amp;quot; to &amp;amp;amp;quot;&amp;lt;br/&amp;gt;Convert ' to &amp;amp;amp;#x27;&amp;lt;br/&amp;gt;Convert / to &amp;amp;amp;#x2F;&lt;br /&gt;
|-&lt;br /&gt;
| HTML Attribute Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the HTML Entity &amp;amp;amp;#xHH; format, including spaces. (HH = Hex Value)&lt;br /&gt;
|-&lt;br /&gt;
| URL Encoding&lt;br /&gt;
| Standard percent encoding, see: [http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp]&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the \uXXXX unicode escaping format (X = Integer).&lt;br /&gt;
|-&lt;br /&gt;
| CSS Hex Encoding&lt;br /&gt;
| CSS escaping supports \XX and \XXXXXX. Using a two character escape can cause problems if the next character continues the escape sequence. There are two solutions (a) Add a space after the CSS escape (will be ignored by the CSS parser) (b) use the full amount of CSS escaping possible by zero padding the value.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* [[XSS Experimental Minimal Encoding Rules]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Eoin Keary - eoin.keary[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=155322</id>
		<title>OWASP Testing Guide v4 Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=155322"/>
				<updated>2013-07-10T18:42:54Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
'''This is the DRAFT of the table of content of the New Testing Guide v4.'''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;You can download the stable version v3 [http://www.owasp.org/images/5/56/OWASP_Testing_Guide_v3.pdf here] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the OWASP Testing Guide Project:&lt;br /&gt;
http://www.owasp.org/index.php/OWASP_Testing_Project&lt;br /&gt;
&lt;br /&gt;
'''Updated: 15th February 2013'''&lt;br /&gt;
&lt;br /&gt;
[[ OWTGv4 Contributors list|'''Contributors List]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a DRAFT of the Toc based on the feedback already received.&lt;br /&gt;
&lt;br /&gt;
== Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Foreword|Foreword by Eoin Keary]]== &lt;br /&gt;
[To review--&amp;gt; Eoin Keary -&amp;gt; Done!!]&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Frontispiece |1. Frontispiece]]== &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[Testing Guide Frontispiece|1.1 About the OWASP Testing Guide Project]]''' &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[About The Open Web Application Security Project|1.2 About The Open Web Application Security Project]]''' &lt;br /&gt;
[To review--&amp;gt; ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Introduction|2. Introduction]]==&lt;br /&gt;
&lt;br /&gt;
'''2.1 The OWASP Testing Project'''&lt;br /&gt;
&lt;br /&gt;
'''2.2 Principles of Testing'''&lt;br /&gt;
&lt;br /&gt;
'''2.3 Testing Techniques Explained''' &lt;br /&gt;
&lt;br /&gt;
2.4 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Requirements_Test_Derivation Security requirements test derivation],[https://www.owasp.org/index.php/Testing_Guide_Introduction#Functional_and_Non_Functional_Test_Requirements functional and non functional test requirements], and [https://www.owasp.org/index.php/Testing_Guide_Introduction#Test_Cases_Through_Use_and_Misuse_Cases test cases through use and misuse cases]&lt;br /&gt;
&lt;br /&gt;
2.5 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Test_Data_Analysis_and_Reporting Security test data analysis and reporting: root cause identification and business/role case test data reporting]&lt;br /&gt;
&lt;br /&gt;
==[[The OWASP Testing Framework|3. The OWASP Testing Framework]]==&lt;br /&gt;
&lt;br /&gt;
'''3.1. Overview'''&lt;br /&gt;
&lt;br /&gt;
'''3.2. Phase 1: Before Development Begins '''&lt;br /&gt;
&lt;br /&gt;
'''3.3. Phase 2: During Definition and Design'''&lt;br /&gt;
&lt;br /&gt;
'''3.4. Phase 3: During Development'''&lt;br /&gt;
&lt;br /&gt;
'''3.5. Phase 4: During Deployment'''&lt;br /&gt;
&lt;br /&gt;
'''3.6. Phase 5: Maintenance and Operations'''&lt;br /&gt;
&lt;br /&gt;
'''3.7. A Typical SDLC Testing Workflow '''&lt;br /&gt;
&lt;br /&gt;
==[[Web Application Penetration Testing |4. Web Application Penetration Testing ]]==&lt;br /&gt;
&lt;br /&gt;
[[Testing: Introduction and objectives|'''4.1 Introduction and Objectives''']] [To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
[[Testing Checklist| 4.1.1 Testing Checklist]] [To review at the end of brainstorming --&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing Information Gathering|'''4.2 Information Gathering ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Search engine discovery/reconnaissance (OWASP-IG-002)|4.2.1 Conduct Search Engine Discovery and Reconnaissance for Information Leakage (OTG-INFO-001) ]] formerly &amp;quot;Search Engine Discovery/Reconnaissance (OWASP-IG-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-004)|4.2.2 Fingerprint Web Server (OTG-INFO-002) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing: Spiders, Robots, and Crawlers (OWASP-IG-001)|4.2.3 Review Webserver Metafiles for Information Leakage (OTG-INFO-003) ]] formerly &amp;quot;Spiders, Robots and Crawlers (OWASP-IG-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Application Discovery (OWASP-IG-005)|4.2.4 Enumerate Applications on Webserver (OTG-INFO-004) ]] formerly &amp;quot;Application Discovery (OWASP-IG-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Review webpage comments and metadata(OWASP-IG-007)|4.2.5 Review Webpage Comments and Metadata for Information Leakage (OTG-INFO-005) ]] formerly &amp;quot;Review webpage comments and metadata(OWASP-IG-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing: Identify application entry points (OWASP-IG-003)|4.2.6 Identify application entry points (OTG-INFO-006) ]] formerly &amp;quot;Identify application entry points (OWASP-IG-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Identify application exit/handover points (OWASP-IG-008)|4.2.7 Identify application exit/handover points (OTG-INFO-007) ]] formerly &amp;quot;Identify application exit/handover points (OWASP-IG-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Map execution paths through application (OWASP-IG-009)|4.2.8 Map execution paths through application (OTG-INFO-008)]] formerly &amp;quot;Map execution paths through application (OWASP-IG-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-010)|4.2.9 Fingerprint Web Application Framework (OTG-INFO-009) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application (OTG-INFO-011)|4.2.10 Fingerprint Web Application (OTG-INFO-010) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Map Network and Application Architecture (OTG-INFO-012)|4.2.11 Map Network and Application Architecture (OTG-INFO-011) ]] formerly &amp;quot;Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for configuration management|'''4.3 Configuration and Deploy Management Testing ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for infrastructure configuration management (OWASP-CM-003)|4.3.1 Test Network/Infrastructure Configuration (OTG-CONFIG-001) ]] formerly &amp;quot;Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for application configuration management (OWASP-CM-004)|4.3.2 Test Application Platform Configuration (OTG-CONFIG-002 ]] formerly &amp;quot;Testing for Application Configuration Management weakness (OWASP-CM-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for file extensions handling  (OWASP-CM-005)|4.3.3 Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003) ]] formerly &amp;quot;Testing for File Extensions Handling  (OWASP-CM-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Old, Backup and Unreferenced Files (OWASP-CM-006)|4.3.4 Review Old, Backup and Unreferenced Files for Sensitive Information (OTG-CONFIG-004) ]] formerly &amp;quot;Old, Backup and Unreferenced Files (OWASP-CM-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Admin Interfaces  (OWASP-CM-007)|4.3.5 Enumerate Infrastructure and Application Admin Interfaces (OTG-CONFIG-005) ]] formerly &amp;quot;Infrastructure and Application Admin Interfaces  (OWASP-CM-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Methods and XST  (OWASP-CM-008)|4.3.6 Test HTTP Methods (OTG-CONFIG-006) ]] formerly &amp;quot;Testing for Bad HTTP Methods (OWASP-CM-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Database credentials/connection strings available|4.3.7 Testing for Database credentials/connection strings available (OTG-CONFIG-007) ]] formerly &amp;quot;Testing for Database credentials/connection strings available (OWASP-CM-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Security Policy weakness|4.3.8 Test Content Security Policy (OTG-CONFIG-008) ]] formerly &amp;quot;Testing for Content Security Policy weakness (OWASP-CM-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Missing HSTS header|4.3.9 Test HTTP Strict Transport Security (OTG-CONFIG-009) ]] formerly &amp;quot;Testing for Missing HSTS header (OWASP-CM-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Frame Options|4.3.10 Test Frame Options (OTG-CONFIG-010) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for RIA policy files weakness|4.3.11 Test RIA cross domain policy (OTG-CONFIG-011) ]] formerly &amp;quot;Testing for RIA policy files weakness (OWASP-CM-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Type Options|4.3.12 Test Content Type Options (OTG-CONFIG-012) ]] new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing Identity Management|'''4.4 Identity Management Testing''']]&lt;br /&gt;
&lt;br /&gt;
[[Test Role Definitions (OTG-IDENT-001)|4.4.1 Test Role Definitions (OTG-IDENT-001)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test User Registration Process (OTG-IDENT-002)|4.4.2 Test User Registration Process (OTG-IDENT-002)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Provisioning Process (OTG-IDENT-003)|4.4.3 Test Account Provisioning Process (OTG-IDENT-003)]] New&lt;br /&gt;
&lt;br /&gt;
[[Testing for Account Enumeration and Guessable User Account (OWASP-AT-002)|4.4.4 Testing for Account Enumeration and Guessable User Account (OTG-IDENT-004) ]] formerly &amp;quot;Testing for Account Enumeration and Guessable User Account (OWASP-AT-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak or unenforced username policy (OWASP-AT-009)| 4.4.5 Testing for Weak or unenforced username policy (OTG-IDENT-005)]] formerly &amp;quot;Testing for Weak or unenforced username policy (OWASP-AT-009)&lt;br /&gt;
&lt;br /&gt;
[[Test Permissions of Guest/Training Accounts (OTG-IDENT-006)|4.4.6 Test Permissions of Guest/Training Accounts (OTG-IDENT-006)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Suspension/Resumption Process (OTG-IDENT-007)|4.4.7 Test Account Suspension/Resumption Process (OTG-IDENT-007)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test User Deregistration Process (OTG-IDENT-008)|4.4.8 Test User Deregistration Process (OTG-IDENT-008)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Deregistration Process (OTG-IDENT-009)|4.4.9 Test Account Deregistration Process (OTG-IDENT-009)]] New&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for authentication|'''4.5 Authentication Testing ''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Credentials Transported over an Encrypted Channel (OWASP-AT-001)|4.5.1 Testing for Credentials Transported over an Encrypted Channel  (OTG-AUTHN-001)]] formerly &amp;quot;Testing for Credentials Transported over an Encrypted Channel  (OWASP-AT-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for default credentials (OWASP-AT-003)|4.5.2 Testing for default credentials (OTG-AUTHN-002)]] formerly &amp;quot;Testing for default credentials (OWASP-AT-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak lock out mechanism (OWASP-AT-004)|4.5.3 Testing for Weak lock out mechanism (OTG-AUTHN-003)]] formerly &amp;quot;Testing for Weak lock out mechanism (OWASP-AT-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authentication Schema (OWASP-AT-005)|4.5.4 Testing for bypassing authentication schema (OTG-AUTHN-004)]] formerly &amp;quot;Testing for bypassing authentication schema (OWASP-AT-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Vulnerable Remember Password (OWASP-AT-006)|4.5.5 Test remember password functionality (OTG-AUTHN-005)]] formerly &amp;quot;Testing for vulnerable remember password functionality (OWASP-AT-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Browser cache weakness (OWASP-AT-007)|4.5.6 Testing for Browser cache weakness (OTG-AUTHN-006)]] formerly &amp;quot;Testing for Browser cache weakness (OWASP-AT-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak password policy (OWASP-AT-008)|4.5.7 Testing for Weak password policy (OTG-AUTHN-007)]] formerly &amp;quot;Testing for Weak password policy (OWASP-AT-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak security question/answer (OTG-AUTHN-008)|4.5.8 Testing for Weak security question/answer (OTG-AUTHN-008)]] New! - Robert Winkel&lt;br /&gt;
&lt;br /&gt;
[[Testing for weak password change or reset functionalities (OWASP-AT-011)|4.5.9 Testing for weak password change or reset functionalities (OTG-AUTHN-009)]] formerly &amp;quot;Testing for weak password change or reset functionalities (OWASP-AT-011)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weaker authentication in alternative channel (OTG-AUTHN-010)|4.5.10 Testing for Weaker authentication in alternative channel (OTG-AUTHN-010)]] (e.g. mobile app, IVR, help desk)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Authorization|'''4.6 Authorization Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Test Management of Account Permissions (OTG-AUTHZ-001)|4.6.1 Test Management of Account Permissions (OTG-AUTHZ-001)]] New&lt;br /&gt;
&lt;br /&gt;
[[Testing for Path Traversal  (OWASP-AZ-001)|4.6.2 Testing Directory traversal/file include (OTG-AUTHZ-002)]] formerly &amp;quot;Testing Directory traversal/file include (OWASP-AZ-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authorization Schema  (OWASP-AZ-002)|4.6.3 Testing for bypassing authorization schema (OTG-AUTHZ-003)]] formerly &amp;quot;Testing for bypassing authorization schema  (OWASP-AZ-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Privilege escalation  (OWASP-AZ-003)|4.6.4 Testing for Privilege Escalation (OTG-AUTHZ-004)]] formerly &amp;quot;Testing for Privilege Escalation  (OWASP-AZ-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Direct Object References (OWASP-AZ-004)|4.6.5 Testing for Insecure Direct Object References (OTG-AUTHZ-005)]] formerly &amp;quot;Testing for Insecure Direct Object References (OWASP-AZ-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)|4.6.6 Testing for Failure to Restrict access to authorized resource (OTG-AUTHZ-006)]] formerly &amp;quot;Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test privileges of server components (OTG-AUTHZ-007)|4.6.7 Test privileges of server components (OTG-AUTHZ-007)]] (e.g. indexing service, reporting interface, file generator)&lt;br /&gt;
&lt;br /&gt;
[[Test enforcement of application entry points (OTG-AUTHZ-008)|4.6.8 Test enforcement of application entry points (OTG-AUTHZ-008)]] (including exposure of objects)&lt;br /&gt;
&lt;br /&gt;
[[Testing for failure to restrict access to authenticated resource(OWASP-AT-010)|4.6.9 Testing for failure to restrict access to authenticated resource (OTG-AUTHZ-009)]] formerly &amp;quot;Testing for failure to restrict access to authenticated resource (OWASP-AT-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Management|'''4.7 Session Management Testing''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session_Management_Schema (OWASP-SM-001)|4.7.1 Testing for Bypassing Session Management Schema (OTG-SESS-001)]] formerly &amp;quot;Testing for Bypassing Session Management Schema (OWASP-SM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for cookies attributes  (OWASP-SM-002)|4.7.2 Testing for Cookies attributes (OTG-SESS-002)]] formerly &amp;quot;Testing for Cookies attributes (OWASP-SM-002)&amp;quot; (Cookies are set not ‘HTTP Only’, ‘Secure’,  and no time validity)&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Fixation  (OWASP-SM-003)|4.7.3 Testing for Session Fixation (OTG-SESS-003)]] formerly &amp;quot;Testing for Session Fixation  (OWASP-SM-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Exposed Session Variables  (OWASP-SM-004)|4.7.4 Testing for Exposed Session Variables (OTG-SESS-004)]] formerly &amp;quot;Testing for Exposed Session Variables (OWASP-SM-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for CSRF  (OWASP-SM-005)|4.7.5 Testing for Cross Site Request Forgery (CSRF) (OTG-SESS-005)]] formerly &amp;quot;Testing for Cross Site Request Forgery (CSRF) (OWASP-SM-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test Session Token Strength (OTG-SESS-006)|4.7.6 Test Session Token Strength (OTG-SESS-006)]]&lt;br /&gt;
 &lt;br /&gt;
[[Testing for logout functionality (OWASP-SM-007)|4.7.7 Testing for logout functionality (OTG-SESS-007)]] formerly &amp;quot;Testing for logout functionality (OWASP-SM-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session puzzling (OWASP-SM-008)|4.7.8 Testing for Session puzzling (OWASP-SM-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Session Timeout (OTG-SESS-008)|4.7.8 Test Session Timeout (OTG-SESS-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Test multiple concurrent sessions (OTG-SESS-009)|4.7.9 Test multiple concurrent sessions (OTG-SESS-009)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Data Validation|'''4.8 Data Validation Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Reflected Cross site scripting (OWASP-DV-001) |4.8.1 Testing for Reflected Cross Site Scripting (OTG-INPVAL-001)]] formerly &amp;quot;Testing for Reflected Cross Site Scripting (OWASP-DV-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stored Cross site scripting (OWASP-DV-002) |4.8.2 Testing for Stored Cross Site Scripting (OTG-INPVAL-002)]] formerly &amp;quot;Testing for Stored Cross Site Scripting (OWASP-DV-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Verb Tampering (OWASP-DV-003)|4.8.3 Testing for HTTP Verb Tampering (OTG-INPVAL-003)]] formerly &amp;quot;Testing for HTTP Verb Tampering (OWASP-DV-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Parameter pollution (OWASP-DV-004)|4.8.4 Testing for HTTP Parameter pollution (OTG-INPVAL-004) ]] formerly &amp;quot;Testing for HTTP Parameter pollution (OWASP-DV-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)|4.8.5 Testing for Unvalidated Redirects and Forwards (OTG-INPVAL-005) ]] formerly &amp;quot;Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Injection (OWASP-DV-005)| 4.8.6 Testing for SQL Injection (OTG-INPVAL-006)]] formerly &amp;quot;Testing for SQL Injection (OWASP-DV-005)&amp;quot; '''Ready to be reviewed'''&lt;br /&gt;
&lt;br /&gt;
[[Testing for Oracle|4.8.6.1 Oracle Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MySQL|4.8.6.2 MySQL Testing [Ismael Gonçalves]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Server|4.8.6.3 SQL Server Testing]]&lt;br /&gt;
&lt;br /&gt;
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.6.4 Testing PostgreSQL (from OWASP BSP) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MS Access |4.8.6.5 MS Access Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for NoSQL injection|4.8.6.6 Testing for NoSQL injection [New!]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for LDAP Injection  (OWASP-DV-006)|4.8.7 Testing for LDAP Injection  (OTG-INPVAL-007)]] formerly &amp;quot;Testing for LDAP Injection  (OWASP-DV-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for ORM Injection   (OWASP-DV-007)|4.8.8 Testing for ORM Injection   (OTG-INPVAL-008)]] formerly &amp;quot;Testing for ORM Injection   (OWASP-DV-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for XML Injection (OWASP-DV-008)|4.8.9 Testing for XML Injection (OTG-INPVAL-009)]] formerly &amp;quot;Testing for XML Injection (OWASP-DV-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for SSI Injection  (OWASP-DV-009)|4.8.10 Testing for SSI Injection  (OTG-INPVAL-010)]] formerly &amp;quot;Testing for SSI Injection  (OWASP-DV-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for XPath Injection  (OWASP-DV-010)|4.8.11 Testing for XPath Injection  (OTG-INPVAL-011)]] formerly &amp;quot;Testing for XPath Injection  (OWASP-DV-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for IMAP/SMTP Injection  (OWASP-DV-011)|4.8.12 IMAP/SMTP Injection  (OTG-INPVAL-012)]] formerly &amp;quot;IMAP/SMTP Injection  (OWASP-DV-011)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Code Injection  (OWASP-DV-012)|4.8.13 Testing for Code Injection  (OTG-INPVAL-013)]] formerly &amp;quot;Testing for Code Injection  (OWASP-DV-012)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Local File Inclusion|4.8.13.1 Testing for Local File Inclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Remote File Inclusion|4.8.13.2 Testing for Remote File Inclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Command Injection   (OWASP-DV-013)|4.8.14 Testing for Command Injection   (OTG-INPVAL-014)]] formerly &amp;quot;Testing for Command Injection   (OWASP-DV-013)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Buffer Overflow (OWASP-DV-014)|4.8.15 Testing for Buffer overflow (OTG-INPVAL-015)]] formerly &amp;quot;Testing for Buffer overflow (OWASP-DV-014)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Heap Overflow|4.8.15.1 Testing for Heap overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Overflow|4.8.15.2 Testing for Stack overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Format String|4.8.15.3 Testing for Format string]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Incubated Vulnerability (OWASP-DV-015)|4.8.16 Testing for incubated vulnerabilities (OTG-INPVAL-016)]] formerly &amp;quot;Testing for incubated vulnerabilities (OWASP-DV-015)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)|4.8.17 Testing for HTTP Splitting/Smuggling  (OTG-INPVAL-017) ]] formerly &amp;quot;Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Error Handling|'''4.9 Error Handling''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Error Code (OWASP-IG-006)|4.9.1 Analysis of Error Codes (OTG-ERR-001)]] formerly &amp;quot;Analysis of Error Codes (OWASP-IG-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Traces (OWASP-IG-XXX)|4.9.2 Analysis of Stack Traces (OTG-ERR-002)]] formerly &amp;quot;Analysis of Stack Traces&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Cryptography|'''4.10 Cryptography''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure encryption usage (OWASP-EN-001)| 4.10.1  Testing for Insecure encryption usage (OTG-CRYPST-001)]] formerly &amp;quot;Testing for Insecure encryption usage (OWASP-EN-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)| 4.10.2 Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OTG-CRYPST-002)]] formerly &amp;quot;Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Padding Oracle (OWASP-EN-003)| 4.10.3 Testing for Padding Oracle (OTG-CRYPST-003)]] formerly &amp;quot;Testing for Padding Oracle (OWASP-EN-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cacheable HTTPS Response (OTG-CRYPST-004)| 4.10.4 Testing for Cacheable HTTPS Response (OTG-CRYPST-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Cache Directives (OTG-CRYPST-005)|4.10.5 Test Cache Directives (OTG-CRYPST-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Cryptographic Storage (OTG-CRYPST-006)|4.10.6 Testing for Insecure Cryptographic Storage (OTG-CRYPST-006)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Sensitive information sent via unencrypted channels (OTG-CRYPST-007)|4.10.7 Testing for Sensitive information sent via unencrypted channels (OTG-CRYPST-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Cryptographic Key Management (OTG-CRYPST-008)|4.10.8 Test Cryptographic Key Management (OTG-CRYPST-008)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Logging|'''4.11 Logging''']] Not convinced Logging should be included as it requires access to logs to test&lt;br /&gt;
&lt;br /&gt;
[[Test time synchronisation (OTG-LOG-001)|4.11.1 Test time synchronisation (OTG-LOG-001) ]] formerly &amp;quot;Incorrect time&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test user-viewable log of authentication events (OTG-LOG-002)|4.11.2 Test user-viewable log of authentication events (OTG-LOG-002)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for business logic   (OWASP-BL-001)|'''4.12 Business Logic Testing  (OWASP-BL-001)''']] [To review--&amp;gt; David Fern]&lt;br /&gt;
Business Logic&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Test business logic data validation (OTG-BUSLOGIC-001)|4.12.1 Test business logic data validation (OTG-BUSLOGIC-001)]] [New!] NOTE MAT: to discuss this section&lt;br /&gt;
&lt;br /&gt;
[[Test Ability to forge requests (OTG-BUSLOGIC-002)|4.12.2 Test Ability to forge requests (OTG-BUSLOGIC-002)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test integrity checks (OTG-BUSLOGIC-003)|4.12.3 Test integrity checks (OTG-BUSLOGIC-003)]] (e.g. overwriting updates) [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test tamper evidence (OTG-BUSLOGIC-004)|4.12.4 Test tamper evidence (OTG-BUSLOGIC-004)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test excessive rate (speed) of use limits (OTG-BUSLOGIC-005)|4.12.5 Test excessive rate (speed) of use limits (OTG-BUSLOGIC-005)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test size of request limits (OTG-BUSLOGIC-006)|4.12.6 Test size of request limits (OTG-BUSLOGIC-006)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test number of times a function can be used limits (OTG-BUSLOGIC-007)|4.12.7 Test number of times a function can be used limits (OTG-BUSLOGIC-002)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test bypass of correct sequence (OTG-BUSLOGIC-008)|4.12.8 Test bypass of correct sequence (OTG-BUSLOGIC-008)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test self-hosted payment cardholder data processing (OTG-BUSLOGIC-009)|4.12.9 Test self-hosted payment cardholder data processing (OTG-BUSLOGIC-009)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test security incident reporting information (OTG-BUSLOGIC-010)|4.12.10 Test security incident reporting information (OTG-BUSLOGIC-010)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test defenses against application mis-use (OTG-BUSLOGIC-011)|4.12.11 Test defenses against application mis-use (OTG-BUSLOGIC-011)]] [New!]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Denial of Service|'''4.13 Denial of Service''']]&lt;br /&gt;
&lt;br /&gt;
[[Test Regular expression DoS (OTG-DOS-001)| 4.13.1 Test Regular expression DoS (OTG-DOS-001)]] [New!] note: to understand better&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Test XML DoS (OTG-DOS-002)| 4.13.2 Test XML DoS (OTG-DOS-002)]] [New! - Andrew Muller]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Captcha (OWASP-AT-012)|4.13.3 Testing for CAPTCHA (OTG-DOS-003)]] formerly &amp;quot;Testing for CAPTCHA (OWASP-AT-012)&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Web Service (XML Interpreter)|'''4.14 Web Service Testing''']] [Tom Eston] &lt;br /&gt;
&lt;br /&gt;
[[Scoping a Web Service Test (OWASP-WS-001)|4.14.1 Scoping a Web Service Test (OTG-WEBSVC-001)]] formerly &amp;quot;Scoping a Web Service Test (OWASP-WS-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Information Gathering (OWASP-WS-002)|4.14.2 WS Information Gathering (OTG-WEBSVC-002)]] formerly &amp;quot;WS Information Gathering (OWASP-WS-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Authentication Testing (OWASP-WS-003)|4.14.3 WS Authentication Testing (OTG-WEBSVC-003)]] formerly &amp;quot;WS Authentication Testing (OWASP-WS-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Management Interface Testing (OWASP-WS-004)|4.14.4 WS Management Interface Testing (OTG-WEBSVC-004)]] formerly &amp;quot;WS Management Interface Testing (OWASP-WS-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Weak XML Structure Testing (OWASP-WS-005)|4.14.5 Weak XML Structure Testing (OTG-WEBSVC-005)]] formerly &amp;quot;Weak XML Structure Testing (OWASP-WS-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[XML Content-Level Testing (OWASP-WS-006)|4.14.6 XML Content-Level Testing (OTG-WEBSVC-006)]] formerly &amp;quot;XML Content-Level Testing (OWASP-WS-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS HTTP GET Parameters/REST Testing (OWASP-WS-007)|4.14.7 WS HTTP GET Parameters/REST Testing (OTG-WEBSVC-007)]] formerly &amp;quot;WS HTTP GET Parameters/REST Testing (OWASP-WS-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Naughty SOAP Attachment Testing (OWASP-WS-008)|4.14.8 WS Naughty SOAP Attachment Testing (OTG-WEBSVC-008)]] formerly &amp;quot;WS Naughty SOAP Attachment Testing (OWASP-WS-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Replay/MiTM Testing (OWASP-WS-009)|4.14.9 WS Replay/MiTM Testing (OTG-WEBSVC-009)]] formerly &amp;quot;WS Replay/MiTM Testing (OWASP-WS-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS BEPL Testing (OWASP-WS-010)|4.14.10 WS BEPL Testing (OTG-WEBSVC-010)]] formerly &amp;quot;WS BEPL Testing (OWASP-WS-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Client Side Testing|'''4.15 Client Side Testing''']] [New!] &lt;br /&gt;
&lt;br /&gt;
[[Testing for DOM-based Cross site scripting  (OWASP-DV-003)|4.15.1 Testing for DOM based Cross Site Scripting  (OTG-CLIENT-001)]] formerly &amp;quot;Testing for DOM based Cross Site Scripting  (OWASP-CS-001)&amp;quot; [Stefano Di Paola]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTML5 (OWASP CS-002)|4.15.2 Testing for HTML5 (OTG-CLIENT-002)]] formerly &amp;quot;Testing for HTML5 (OWASP CS-002)&amp;quot; [Juan Galiana]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cross site flashing (OWASP-DV-004)|4.15.3 Testing for Cross Site Flashing   (OTG-CLIENT-003)]] formerly &amp;quot;Testing for Cross Site Flashing   (OWASP-CS-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Clickjacking (OWASP-CS-004)|4.15.4 Testing for Clickjacking (OTG-CLIENT-004)]] formerly &amp;quot;Testing for Clickjacking (OWASP-CS-004)&amp;quot; [Davide Danelon] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Writing Reports: value the real risk |5. Writing Reports: value the real risk ]]==&lt;br /&gt;
&lt;br /&gt;
[[How to value the real risk |5.1 How to value the real risk]] [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
[[How to write the report of the testing |5.2 How to write the report of the testing]] [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
==[[Appendix A: Testing Tools |Appendix A: Testing Tools ]]==&lt;br /&gt;
&lt;br /&gt;
* Black Box Testing Tools [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix B: Suggested Reading | Appendix B: Suggested Reading]]==&lt;br /&gt;
* Whitepapers [To review--&amp;gt; David Fern]&lt;br /&gt;
* Books [To review--&amp;gt; David Fern]&lt;br /&gt;
* Useful Websites [To review--&amp;gt; David Fern]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix C: Fuzz Vectors | Appendix C: Fuzz Vectors]]==&lt;br /&gt;
&lt;br /&gt;
* Fuzz Categories [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix D: Encoded Injection | Appendix D: Encoded Injection]]==&lt;br /&gt;
&lt;br /&gt;
[To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Testing Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Stack_Traces_(OTG-ERR-002)&amp;diff=155321</id>
		<title>Testing for Stack Traces (OTG-ERR-002)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Stack_Traces_(OTG-ERR-002)&amp;diff=155321"/>
				<updated>2013-07-10T18:40:32Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: Created page with &amp;quot;{{Template:OWASP Testing Guide v4}}  == Brief Summary ==  Stack traces are not vulnerabilities by themselves, but they often reveal information that is interesting to an attac...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
&lt;br /&gt;
Stack traces are not vulnerabilities by themselves, but they often reveal information that is interesting to an attacker. Attackers attempt to generate these stack traces by tampering with the input to the web application with malformed HTTP requests and other input data.&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue ==&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
There are a variety of techniques that will cause exception messages to be sent in an HTTP response. Note that in most cases this will be an HTML page, but exceptions can be sent as part of SOAP or REST responses too.&lt;br /&gt;
&lt;br /&gt;
Some tools, such as [[OWASP ZAP]] and Burp proxy will automatically detect these exceptions in the response stream as you are doing other penetration and testing work.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
Search the code for the calls that cause an exception to be rendered to a String or output stream. For example, in Java this might be code in a JSP that looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;amp;lt;% e.printStackTrace( new PrintWriter( out ) ) %&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, the stack trace will be specifically formatted into HTML, so be careful of accesses to stack trace elements.&lt;br /&gt;
&lt;br /&gt;
Search the configuration to verify error handling configuration and the use of default error pages.  For example, in Java this configuration can be found in web.xml.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [1] [[http://www.ietf.org/rfc/rfc2616.txt?number=2616 RFC2616]] Hypertext Transfer Protocol -- HTTP/1.1&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=155320</id>
		<title>OWASP Testing Guide v4 Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=155320"/>
				<updated>2013-07-10T18:24:55Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
'''This is the DRAFT of the table of content of the New Testing Guide v4.'''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;You can download the stable version v3 [http://www.owasp.org/images/5/56/OWASP_Testing_Guide_v3.pdf here] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the OWASP Testing Guide Project:&lt;br /&gt;
http://www.owasp.org/index.php/OWASP_Testing_Project&lt;br /&gt;
&lt;br /&gt;
'''Updated: 15th February 2013'''&lt;br /&gt;
&lt;br /&gt;
[[ OWTGv4 Contributors list|'''Contributors List]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a DRAFT of the Toc based on the feedback already received.&lt;br /&gt;
&lt;br /&gt;
== Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Foreword|Foreword by Eoin Keary]]== &lt;br /&gt;
[To review--&amp;gt; Eoin Keary -&amp;gt; Done!!]&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Frontispiece |1. Frontispiece]]== &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[Testing Guide Frontispiece|1.1 About the OWASP Testing Guide Project]]''' &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[About The Open Web Application Security Project|1.2 About The Open Web Application Security Project]]''' &lt;br /&gt;
[To review--&amp;gt; ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Introduction|2. Introduction]]==&lt;br /&gt;
&lt;br /&gt;
'''2.1 The OWASP Testing Project'''&lt;br /&gt;
&lt;br /&gt;
'''2.2 Principles of Testing'''&lt;br /&gt;
&lt;br /&gt;
'''2.3 Testing Techniques Explained''' &lt;br /&gt;
&lt;br /&gt;
2.4 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Requirements_Test_Derivation Security requirements test derivation],[https://www.owasp.org/index.php/Testing_Guide_Introduction#Functional_and_Non_Functional_Test_Requirements functional and non functional test requirements], and [https://www.owasp.org/index.php/Testing_Guide_Introduction#Test_Cases_Through_Use_and_Misuse_Cases test cases through use and misuse cases]&lt;br /&gt;
&lt;br /&gt;
2.5 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Test_Data_Analysis_and_Reporting Security test data analysis and reporting: root cause identification and business/role case test data reporting]&lt;br /&gt;
&lt;br /&gt;
==[[The OWASP Testing Framework|3. The OWASP Testing Framework]]==&lt;br /&gt;
&lt;br /&gt;
'''3.1. Overview'''&lt;br /&gt;
&lt;br /&gt;
'''3.2. Phase 1: Before Development Begins '''&lt;br /&gt;
&lt;br /&gt;
'''3.3. Phase 2: During Definition and Design'''&lt;br /&gt;
&lt;br /&gt;
'''3.4. Phase 3: During Development'''&lt;br /&gt;
&lt;br /&gt;
'''3.5. Phase 4: During Deployment'''&lt;br /&gt;
&lt;br /&gt;
'''3.6. Phase 5: Maintenance and Operations'''&lt;br /&gt;
&lt;br /&gt;
'''3.7. A Typical SDLC Testing Workflow '''&lt;br /&gt;
&lt;br /&gt;
==[[Web Application Penetration Testing |4. Web Application Penetration Testing ]]==&lt;br /&gt;
&lt;br /&gt;
[[Testing: Introduction and objectives|'''4.1 Introduction and Objectives''']] [To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
[[Testing Checklist| 4.1.1 Testing Checklist]] [To review at the end of brainstorming --&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing Information Gathering|'''4.2 Information Gathering ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Search engine discovery/reconnaissance (OWASP-IG-002)|4.2.1 Conduct Search Engine Discovery and Reconnaissance for Information Leakage (OTG-INFO-001) ]] formerly &amp;quot;Search Engine Discovery/Reconnaissance (OWASP-IG-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-004)|4.2.2 Fingerprint Web Server (OTG-INFO-002) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing: Spiders, Robots, and Crawlers (OWASP-IG-001)|4.2.3 Review Webserver Metafiles for Information Leakage (OTG-INFO-003) ]] formerly &amp;quot;Spiders, Robots and Crawlers (OWASP-IG-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Application Discovery (OWASP-IG-005)|4.2.4 Enumerate Applications on Webserver (OTG-INFO-004) ]] formerly &amp;quot;Application Discovery (OWASP-IG-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Review webpage comments and metadata(OWASP-IG-007)|4.2.5 Review Webpage Comments and Metadata for Information Leakage (OTG-INFO-005) ]] formerly &amp;quot;Review webpage comments and metadata(OWASP-IG-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing: Identify application entry points (OWASP-IG-003)|4.2.6 Identify application entry points (OTG-INFO-006) ]] formerly &amp;quot;Identify application entry points (OWASP-IG-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Identify application exit/handover points (OWASP-IG-008)|4.2.7 Identify application exit/handover points (OTG-INFO-007) ]] formerly &amp;quot;Identify application exit/handover points (OWASP-IG-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Map execution paths through application (OWASP-IG-009)|4.2.8 Map execution paths through application (OTG-INFO-008)]] formerly &amp;quot;Map execution paths through application (OWASP-IG-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-010)|4.2.9 Fingerprint Web Application Framework (OTG-INFO-009) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application (OTG-INFO-011)|4.2.10 Fingerprint Web Application (OTG-INFO-010) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Map Network and Application Architecture (OTG-INFO-012)|4.2.11 Map Network and Application Architecture (OTG-INFO-011) ]] formerly &amp;quot;Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for configuration management|'''4.3 Configuration and Deploy Management Testing ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for infrastructure configuration management (OWASP-CM-003)|4.3.1 Test Network/Infrastructure Configuration (OTG-CONFIG-001) ]] formerly &amp;quot;Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for application configuration management (OWASP-CM-004)|4.3.2 Test Application Platform Configuration (OTG-CONFIG-002 ]] formerly &amp;quot;Testing for Application Configuration Management weakness (OWASP-CM-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for file extensions handling  (OWASP-CM-005)|4.3.3 Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003) ]] formerly &amp;quot;Testing for File Extensions Handling  (OWASP-CM-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Old, Backup and Unreferenced Files (OWASP-CM-006)|4.3.4 Review Old, Backup and Unreferenced Files for Sensitive Information (OTG-CONFIG-004) ]] formerly &amp;quot;Old, Backup and Unreferenced Files (OWASP-CM-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Admin Interfaces  (OWASP-CM-007)|4.3.5 Enumerate Infrastructure and Application Admin Interfaces (OTG-CONFIG-005) ]] formerly &amp;quot;Infrastructure and Application Admin Interfaces  (OWASP-CM-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Methods and XST  (OWASP-CM-008)|4.3.6 Test HTTP Methods (OTG-CONFIG-006) ]] formerly &amp;quot;Testing for Bad HTTP Methods (OWASP-CM-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Database credentials/connection strings available|4.3.7 Testing for Database credentials/connection strings available (OTG-CONFIG-007) ]] formerly &amp;quot;Testing for Database credentials/connection strings available (OWASP-CM-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Security Policy weakness|4.3.8 Test Content Security Policy (OTG-CONFIG-008) ]] formerly &amp;quot;Testing for Content Security Policy weakness (OWASP-CM-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Missing HSTS header|4.3.9 Test HTTP Strict Transport Security (OTG-CONFIG-009) ]] formerly &amp;quot;Testing for Missing HSTS header (OWASP-CM-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Frame Options|4.3.10 Test Frame Options (OTG-CONFIG-010) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for RIA policy files weakness|4.3.11 Test RIA cross domain policy (OTG-CONFIG-011) ]] formerly &amp;quot;Testing for RIA policy files weakness (OWASP-CM-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Type Options|4.3.12 Test Content Type Options (OTG-CONFIG-012) ]] new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing Identity Management|'''4.4 Identity Management Testing''']]&lt;br /&gt;
&lt;br /&gt;
[[Test Role Definitions (OTG-IDENT-001)|4.4.1 Test Role Definitions (OTG-IDENT-001)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test User Registration Process (OTG-IDENT-002)|4.4.2 Test User Registration Process (OTG-IDENT-002)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Provisioning Process (OTG-IDENT-003)|4.4.3 Test Account Provisioning Process (OTG-IDENT-003)]] New&lt;br /&gt;
&lt;br /&gt;
[[Testing for Account Enumeration and Guessable User Account (OWASP-AT-002)|4.4.4 Testing for Account Enumeration and Guessable User Account (OTG-IDENT-004) ]] formerly &amp;quot;Testing for Account Enumeration and Guessable User Account (OWASP-AT-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak or unenforced username policy (OWASP-AT-009)| 4.4.5 Testing for Weak or unenforced username policy (OTG-IDENT-005)]] formerly &amp;quot;Testing for Weak or unenforced username policy (OWASP-AT-009)&lt;br /&gt;
&lt;br /&gt;
[[Test Permissions of Guest/Training Accounts (OTG-IDENT-006)|4.4.6 Test Permissions of Guest/Training Accounts (OTG-IDENT-006)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Suspension/Resumption Process (OTG-IDENT-007)|4.4.7 Test Account Suspension/Resumption Process (OTG-IDENT-007)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test User Deregistration Process (OTG-IDENT-008)|4.4.8 Test User Deregistration Process (OTG-IDENT-008)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Deregistration Process (OTG-IDENT-009)|4.4.9 Test Account Deregistration Process (OTG-IDENT-009)]] New&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for authentication|'''4.5 Authentication Testing ''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Credentials Transported over an Encrypted Channel (OWASP-AT-001)|4.5.1 Testing for Credentials Transported over an Encrypted Channel  (OTG-AUTHN-001)]] formerly &amp;quot;Testing for Credentials Transported over an Encrypted Channel  (OWASP-AT-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for default credentials (OWASP-AT-003)|4.5.2 Testing for default credentials (OTG-AUTHN-002)]] formerly &amp;quot;Testing for default credentials (OWASP-AT-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak lock out mechanism (OWASP-AT-004)|4.5.3 Testing for Weak lock out mechanism (OTG-AUTHN-003)]] formerly &amp;quot;Testing for Weak lock out mechanism (OWASP-AT-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authentication Schema (OWASP-AT-005)|4.5.4 Testing for bypassing authentication schema (OTG-AUTHN-004)]] formerly &amp;quot;Testing for bypassing authentication schema (OWASP-AT-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Vulnerable Remember Password (OWASP-AT-006)|4.5.5 Test remember password functionality (OTG-AUTHN-005)]] formerly &amp;quot;Testing for vulnerable remember password functionality (OWASP-AT-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Browser cache weakness (OWASP-AT-007)|4.5.6 Testing for Browser cache weakness (OTG-AUTHN-006)]] formerly &amp;quot;Testing for Browser cache weakness (OWASP-AT-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak password policy (OWASP-AT-008)|4.5.7 Testing for Weak password policy (OTG-AUTHN-007)]] formerly &amp;quot;Testing for Weak password policy (OWASP-AT-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak security question/answer (OTG-AUTHN-008)|4.5.8 Testing for Weak security question/answer (OTG-AUTHN-008)]] New! - Robert Winkel&lt;br /&gt;
&lt;br /&gt;
[[Testing for weak password change or reset functionalities (OWASP-AT-011)|4.5.9 Testing for weak password change or reset functionalities (OTG-AUTHN-009)]] formerly &amp;quot;Testing for weak password change or reset functionalities (OWASP-AT-011)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weaker authentication in alternative channel (OTG-AUTHN-010)|4.5.10 Testing for Weaker authentication in alternative channel (OTG-AUTHN-010)]] (e.g. mobile app, IVR, help desk)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Authorization|'''4.6 Authorization Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Test Management of Account Permissions (OTG-AUTHZ-001)|4.6.1 Test Management of Account Permissions (OTG-AUTHZ-001)]] New&lt;br /&gt;
&lt;br /&gt;
[[Testing for Path Traversal  (OWASP-AZ-001)|4.6.2 Testing Directory traversal/file include (OTG-AUTHZ-002)]] formerly &amp;quot;Testing Directory traversal/file include (OWASP-AZ-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authorization Schema  (OWASP-AZ-002)|4.6.3 Testing for bypassing authorization schema (OTG-AUTHZ-003)]] formerly &amp;quot;Testing for bypassing authorization schema  (OWASP-AZ-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Privilege escalation  (OWASP-AZ-003)|4.6.4 Testing for Privilege Escalation (OTG-AUTHZ-004)]] formerly &amp;quot;Testing for Privilege Escalation  (OWASP-AZ-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Direct Object References (OWASP-AZ-004)|4.6.5 Testing for Insecure Direct Object References (OTG-AUTHZ-005)]] formerly &amp;quot;Testing for Insecure Direct Object References (OWASP-AZ-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)|4.6.6 Testing for Failure to Restrict access to authorized resource (OTG-AUTHZ-006)]] formerly &amp;quot;Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test privileges of server components (OTG-AUTHZ-007)|4.6.7 Test privileges of server components (OTG-AUTHZ-007)]] (e.g. indexing service, reporting interface, file generator)&lt;br /&gt;
&lt;br /&gt;
[[Test enforcement of application entry points (OTG-AUTHZ-008)|4.6.8 Test enforcement of application entry points (OTG-AUTHZ-008)]] (including exposure of objects)&lt;br /&gt;
&lt;br /&gt;
[[Testing for failure to restrict access to authenticated resource(OWASP-AT-010)|4.6.9 Testing for failure to restrict access to authenticated resource (OTG-AUTHZ-009)]] formerly &amp;quot;Testing for failure to restrict access to authenticated resource (OWASP-AT-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Management|'''4.7 Session Management Testing''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session_Management_Schema (OWASP-SM-001)|4.7.1 Testing for Bypassing Session Management Schema (OTG-SESS-001)]] formerly &amp;quot;Testing for Bypassing Session Management Schema (OWASP-SM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for cookies attributes  (OWASP-SM-002)|4.7.2 Testing for Cookies attributes (OTG-SESS-002)]] formerly &amp;quot;Testing for Cookies attributes (OWASP-SM-002)&amp;quot; (Cookies are set not ‘HTTP Only’, ‘Secure’,  and no time validity)&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Fixation  (OWASP-SM-003)|4.7.3 Testing for Session Fixation (OTG-SESS-003)]] formerly &amp;quot;Testing for Session Fixation  (OWASP-SM-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Exposed Session Variables  (OWASP-SM-004)|4.7.4 Testing for Exposed Session Variables (OTG-SESS-004)]] formerly &amp;quot;Testing for Exposed Session Variables (OWASP-SM-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for CSRF  (OWASP-SM-005)|4.7.5 Testing for Cross Site Request Forgery (CSRF) (OTG-SESS-005)]] formerly &amp;quot;Testing for Cross Site Request Forgery (CSRF) (OWASP-SM-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test Session Token Strength (OTG-SESS-006)|4.7.6 Test Session Token Strength (OTG-SESS-006)]]&lt;br /&gt;
 &lt;br /&gt;
[[Testing for logout functionality (OWASP-SM-007)|4.7.7 Testing for logout functionality (OTG-SESS-007)]] formerly &amp;quot;Testing for logout functionality (OWASP-SM-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session puzzling (OWASP-SM-008)|4.7.8 Testing for Session puzzling (OWASP-SM-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Session Timeout (OTG-SESS-008)|4.7.8 Test Session Timeout (OTG-SESS-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Test multiple concurrent sessions (OTG-SESS-009)|4.7.9 Test multiple concurrent sessions (OTG-SESS-009)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Data Validation|'''4.8 Data Validation Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Reflected Cross site scripting (OWASP-DV-001) |4.8.1 Testing for Reflected Cross Site Scripting (OTG-INPVAL-001)]] formerly &amp;quot;Testing for Reflected Cross Site Scripting (OWASP-DV-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stored Cross site scripting (OWASP-DV-002) |4.8.2 Testing for Stored Cross Site Scripting (OTG-INPVAL-002)]] formerly &amp;quot;Testing for Stored Cross Site Scripting (OWASP-DV-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Verb Tampering (OWASP-DV-003)|4.8.3 Testing for HTTP Verb Tampering (OTG-INPVAL-003)]] formerly &amp;quot;Testing for HTTP Verb Tampering (OWASP-DV-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Parameter pollution (OWASP-DV-004)|4.8.4 Testing for HTTP Parameter pollution (OTG-INPVAL-004) ]] formerly &amp;quot;Testing for HTTP Parameter pollution (OWASP-DV-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)|4.8.5 Testing for Unvalidated Redirects and Forwards (OTG-INPVAL-005) ]] formerly &amp;quot;Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Injection (OWASP-DV-005)| 4.8.6 Testing for SQL Injection (OTG-INPVAL-006)]] formerly &amp;quot;Testing for SQL Injection (OWASP-DV-005)&amp;quot; '''Ready to be reviewed'''&lt;br /&gt;
&lt;br /&gt;
[[Testing for Oracle|4.8.6.1 Oracle Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MySQL|4.8.6.2 MySQL Testing [Ismael Gonçalves]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Server|4.8.6.3 SQL Server Testing]]&lt;br /&gt;
&lt;br /&gt;
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.6.4 Testing PostgreSQL (from OWASP BSP) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MS Access |4.8.6.5 MS Access Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for NoSQL injection|4.8.6.6 Testing for NoSQL injection [New!]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for LDAP Injection  (OWASP-DV-006)|4.8.7 Testing for LDAP Injection  (OTG-INPVAL-007)]] formerly &amp;quot;Testing for LDAP Injection  (OWASP-DV-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for ORM Injection   (OWASP-DV-007)|4.8.8 Testing for ORM Injection   (OTG-INPVAL-008)]] formerly &amp;quot;Testing for ORM Injection   (OWASP-DV-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for XML Injection (OWASP-DV-008)|4.8.9 Testing for XML Injection (OTG-INPVAL-009)]] formerly &amp;quot;Testing for XML Injection (OWASP-DV-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for SSI Injection  (OWASP-DV-009)|4.8.10 Testing for SSI Injection  (OTG-INPVAL-010)]] formerly &amp;quot;Testing for SSI Injection  (OWASP-DV-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for XPath Injection  (OWASP-DV-010)|4.8.11 Testing for XPath Injection  (OTG-INPVAL-011)]] formerly &amp;quot;Testing for XPath Injection  (OWASP-DV-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for IMAP/SMTP Injection  (OWASP-DV-011)|4.8.12 IMAP/SMTP Injection  (OTG-INPVAL-012)]] formerly &amp;quot;IMAP/SMTP Injection  (OWASP-DV-011)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Code Injection  (OWASP-DV-012)|4.8.13 Testing for Code Injection  (OTG-INPVAL-013)]] formerly &amp;quot;Testing for Code Injection  (OWASP-DV-012)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Local File Inclusion|4.8.13.1 Testing for Local File Inclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Remote File Inclusion|4.8.13.2 Testing for Remote File Inclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Command Injection   (OWASP-DV-013)|4.8.14 Testing for Command Injection   (OTG-INPVAL-014)]] formerly &amp;quot;Testing for Command Injection   (OWASP-DV-013)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Buffer Overflow (OWASP-DV-014)|4.8.15 Testing for Buffer overflow (OTG-INPVAL-015)]] formerly &amp;quot;Testing for Buffer overflow (OWASP-DV-014)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Heap Overflow|4.8.15.1 Testing for Heap overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Overflow|4.8.15.2 Testing for Stack overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Format String|4.8.15.3 Testing for Format string]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Incubated Vulnerability (OWASP-DV-015)|4.8.16 Testing for incubated vulnerabilities (OTG-INPVAL-016)]] formerly &amp;quot;Testing for incubated vulnerabilities (OWASP-DV-015)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)|4.8.17 Testing for HTTP Splitting/Smuggling  (OTG-INPVAL-017) ]] formerly &amp;quot;Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Error Handling|'''4.9 Error Handling''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Error Code (OWASP-IG-006)|4.9.1 Analysis of Error Codes (OTG-ERR-001)]] formerly &amp;quot;Analysis of Error Codes (OWASP-IG-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Traces (OWASP-IG-XXX)|4.9.2 Analysis of Error Codes (OTG-ERR-002)]] formerly &amp;quot;Analysis of Stack Traces&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Cryptography|'''4.10 Cryptography''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure encryption usage (OWASP-EN-001)| 4.10.1  Testing for Insecure encryption usage (OTG-CRYPST-001)]] formerly &amp;quot;Testing for Insecure encryption usage (OWASP-EN-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)| 4.10.2 Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OTG-CRYPST-002)]] formerly &amp;quot;Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Padding Oracle (OWASP-EN-003)| 4.10.3 Testing for Padding Oracle (OTG-CRYPST-003)]] formerly &amp;quot;Testing for Padding Oracle (OWASP-EN-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cacheable HTTPS Response (OTG-CRYPST-004)| 4.10.4 Testing for Cacheable HTTPS Response (OTG-CRYPST-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Cache Directives (OTG-CRYPST-005)|4.10.5 Test Cache Directives (OTG-CRYPST-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Cryptographic Storage (OTG-CRYPST-006)|4.10.6 Testing for Insecure Cryptographic Storage (OTG-CRYPST-006)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Sensitive information sent via unencrypted channels (OTG-CRYPST-007)|4.10.7 Testing for Sensitive information sent via unencrypted channels (OTG-CRYPST-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Cryptographic Key Management (OTG-CRYPST-008)|4.10.8 Test Cryptographic Key Management (OTG-CRYPST-008)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Logging|'''4.11 Logging''']] Not convinced Logging should be included as it requires access to logs to test&lt;br /&gt;
&lt;br /&gt;
[[Test time synchronisation (OTG-LOG-001)|4.11.1 Test time synchronisation (OTG-LOG-001) ]] formerly &amp;quot;Incorrect time&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test user-viewable log of authentication events (OTG-LOG-002)|4.11.2 Test user-viewable log of authentication events (OTG-LOG-002)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for business logic   (OWASP-BL-001)|'''4.12 Business Logic Testing  (OWASP-BL-001)''']] [To review--&amp;gt; David Fern]&lt;br /&gt;
Business Logic&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Test business logic data validation (OTG-BUSLOGIC-001)|4.12.1 Test business logic data validation (OTG-BUSLOGIC-001)]] [New!] NOTE MAT: to discuss this section&lt;br /&gt;
&lt;br /&gt;
[[Test Ability to forge requests (OTG-BUSLOGIC-002)|4.12.2 Test Ability to forge requests (OTG-BUSLOGIC-002)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test integrity checks (OTG-BUSLOGIC-003)|4.12.3 Test integrity checks (OTG-BUSLOGIC-003)]] (e.g. overwriting updates) [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test tamper evidence (OTG-BUSLOGIC-004)|4.12.4 Test tamper evidence (OTG-BUSLOGIC-004)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test excessive rate (speed) of use limits (OTG-BUSLOGIC-005)|4.12.5 Test excessive rate (speed) of use limits (OTG-BUSLOGIC-005)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test size of request limits (OTG-BUSLOGIC-006)|4.12.6 Test size of request limits (OTG-BUSLOGIC-006)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test number of times a function can be used limits (OTG-BUSLOGIC-007)|4.12.7 Test number of times a function can be used limits (OTG-BUSLOGIC-002)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test bypass of correct sequence (OTG-BUSLOGIC-008)|4.12.8 Test bypass of correct sequence (OTG-BUSLOGIC-008)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test self-hosted payment cardholder data processing (OTG-BUSLOGIC-009)|4.12.9 Test self-hosted payment cardholder data processing (OTG-BUSLOGIC-009)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test security incident reporting information (OTG-BUSLOGIC-010)|4.12.10 Test security incident reporting information (OTG-BUSLOGIC-010)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test defenses against application mis-use (OTG-BUSLOGIC-011)|4.12.11 Test defenses against application mis-use (OTG-BUSLOGIC-011)]] [New!]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Denial of Service|'''4.13 Denial of Service''']]&lt;br /&gt;
&lt;br /&gt;
[[Test Regular expression DoS (OTG-DOS-001)| 4.13.1 Test Regular expression DoS (OTG-DOS-001)]] [New!] note: to understand better&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Test XML DoS (OTG-DOS-002)| 4.13.2 Test XML DoS (OTG-DOS-002)]] [New! - Andrew Muller]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Captcha (OWASP-AT-012)|4.13.3 Testing for CAPTCHA (OTG-DOS-003)]] formerly &amp;quot;Testing for CAPTCHA (OWASP-AT-012)&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Web Service (XML Interpreter)|'''4.14 Web Service Testing''']] [Tom Eston] &lt;br /&gt;
&lt;br /&gt;
[[Scoping a Web Service Test (OWASP-WS-001)|4.14.1 Scoping a Web Service Test (OTG-WEBSVC-001)]] formerly &amp;quot;Scoping a Web Service Test (OWASP-WS-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Information Gathering (OWASP-WS-002)|4.14.2 WS Information Gathering (OTG-WEBSVC-002)]] formerly &amp;quot;WS Information Gathering (OWASP-WS-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Authentication Testing (OWASP-WS-003)|4.14.3 WS Authentication Testing (OTG-WEBSVC-003)]] formerly &amp;quot;WS Authentication Testing (OWASP-WS-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Management Interface Testing (OWASP-WS-004)|4.14.4 WS Management Interface Testing (OTG-WEBSVC-004)]] formerly &amp;quot;WS Management Interface Testing (OWASP-WS-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Weak XML Structure Testing (OWASP-WS-005)|4.14.5 Weak XML Structure Testing (OTG-WEBSVC-005)]] formerly &amp;quot;Weak XML Structure Testing (OWASP-WS-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[XML Content-Level Testing (OWASP-WS-006)|4.14.6 XML Content-Level Testing (OTG-WEBSVC-006)]] formerly &amp;quot;XML Content-Level Testing (OWASP-WS-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS HTTP GET Parameters/REST Testing (OWASP-WS-007)|4.14.7 WS HTTP GET Parameters/REST Testing (OTG-WEBSVC-007)]] formerly &amp;quot;WS HTTP GET Parameters/REST Testing (OWASP-WS-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Naughty SOAP Attachment Testing (OWASP-WS-008)|4.14.8 WS Naughty SOAP Attachment Testing (OTG-WEBSVC-008)]] formerly &amp;quot;WS Naughty SOAP Attachment Testing (OWASP-WS-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Replay/MiTM Testing (OWASP-WS-009)|4.14.9 WS Replay/MiTM Testing (OTG-WEBSVC-009)]] formerly &amp;quot;WS Replay/MiTM Testing (OWASP-WS-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS BEPL Testing (OWASP-WS-010)|4.14.10 WS BEPL Testing (OTG-WEBSVC-010)]] formerly &amp;quot;WS BEPL Testing (OWASP-WS-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Client Side Testing|'''4.15 Client Side Testing''']] [New!] &lt;br /&gt;
&lt;br /&gt;
[[Testing for DOM-based Cross site scripting  (OWASP-DV-003)|4.15.1 Testing for DOM based Cross Site Scripting  (OTG-CLIENT-001)]] formerly &amp;quot;Testing for DOM based Cross Site Scripting  (OWASP-CS-001)&amp;quot; [Stefano Di Paola]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTML5 (OWASP CS-002)|4.15.2 Testing for HTML5 (OTG-CLIENT-002)]] formerly &amp;quot;Testing for HTML5 (OWASP CS-002)&amp;quot; [Juan Galiana]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cross site flashing (OWASP-DV-004)|4.15.3 Testing for Cross Site Flashing   (OTG-CLIENT-003)]] formerly &amp;quot;Testing for Cross Site Flashing   (OWASP-CS-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Clickjacking (OWASP-CS-004)|4.15.4 Testing for Clickjacking (OTG-CLIENT-004)]] formerly &amp;quot;Testing for Clickjacking (OWASP-CS-004)&amp;quot; [Davide Danelon] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Writing Reports: value the real risk |5. Writing Reports: value the real risk ]]==&lt;br /&gt;
&lt;br /&gt;
[[How to value the real risk |5.1 How to value the real risk]] [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
[[How to write the report of the testing |5.2 How to write the report of the testing]] [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
==[[Appendix A: Testing Tools |Appendix A: Testing Tools ]]==&lt;br /&gt;
&lt;br /&gt;
* Black Box Testing Tools [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix B: Suggested Reading | Appendix B: Suggested Reading]]==&lt;br /&gt;
* Whitepapers [To review--&amp;gt; David Fern]&lt;br /&gt;
* Books [To review--&amp;gt; David Fern]&lt;br /&gt;
* Useful Websites [To review--&amp;gt; David Fern]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix C: Fuzz Vectors | Appendix C: Fuzz Vectors]]==&lt;br /&gt;
&lt;br /&gt;
* Fuzz Categories [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix D: Encoded Injection | Appendix D: Encoded Injection]]==&lt;br /&gt;
&lt;br /&gt;
[To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Testing Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=155319</id>
		<title>OWASP Testing Guide v4 Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=155319"/>
				<updated>2013-07-10T18:24:06Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
'''This is the DRAFT of the table of content of the New Testing Guide v4.'''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;You can download the stable version v3 [http://www.owasp.org/images/5/56/OWASP_Testing_Guide_v3.pdf here] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the OWASP Testing Guide Project:&lt;br /&gt;
http://www.owasp.org/index.php/OWASP_Testing_Project&lt;br /&gt;
&lt;br /&gt;
'''Updated: 15th February 2013'''&lt;br /&gt;
&lt;br /&gt;
[[ OWTGv4 Contributors list|'''Contributors List]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a DRAFT of the Toc based on the feedback already received.&lt;br /&gt;
&lt;br /&gt;
== Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Foreword|Foreword by Eoin Keary]]== &lt;br /&gt;
[To review--&amp;gt; Eoin Keary -&amp;gt; Done!!]&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Frontispiece |1. Frontispiece]]== &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[Testing Guide Frontispiece|1.1 About the OWASP Testing Guide Project]]''' &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[About The Open Web Application Security Project|1.2 About The Open Web Application Security Project]]''' &lt;br /&gt;
[To review--&amp;gt; ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Introduction|2. Introduction]]==&lt;br /&gt;
&lt;br /&gt;
'''2.1 The OWASP Testing Project'''&lt;br /&gt;
&lt;br /&gt;
'''2.2 Principles of Testing'''&lt;br /&gt;
&lt;br /&gt;
'''2.3 Testing Techniques Explained''' &lt;br /&gt;
&lt;br /&gt;
2.4 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Requirements_Test_Derivation Security requirements test derivation],[https://www.owasp.org/index.php/Testing_Guide_Introduction#Functional_and_Non_Functional_Test_Requirements functional and non functional test requirements], and [https://www.owasp.org/index.php/Testing_Guide_Introduction#Test_Cases_Through_Use_and_Misuse_Cases test cases through use and misuse cases]&lt;br /&gt;
&lt;br /&gt;
2.5 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Test_Data_Analysis_and_Reporting Security test data analysis and reporting: root cause identification and business/role case test data reporting]&lt;br /&gt;
&lt;br /&gt;
==[[The OWASP Testing Framework|3. The OWASP Testing Framework]]==&lt;br /&gt;
&lt;br /&gt;
'''3.1. Overview'''&lt;br /&gt;
&lt;br /&gt;
'''3.2. Phase 1: Before Development Begins '''&lt;br /&gt;
&lt;br /&gt;
'''3.3. Phase 2: During Definition and Design'''&lt;br /&gt;
&lt;br /&gt;
'''3.4. Phase 3: During Development'''&lt;br /&gt;
&lt;br /&gt;
'''3.5. Phase 4: During Deployment'''&lt;br /&gt;
&lt;br /&gt;
'''3.6. Phase 5: Maintenance and Operations'''&lt;br /&gt;
&lt;br /&gt;
'''3.7. A Typical SDLC Testing Workflow '''&lt;br /&gt;
&lt;br /&gt;
==[[Web Application Penetration Testing |4. Web Application Penetration Testing ]]==&lt;br /&gt;
&lt;br /&gt;
[[Testing: Introduction and objectives|'''4.1 Introduction and Objectives''']] [To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
[[Testing Checklist| 4.1.1 Testing Checklist]] [To review at the end of brainstorming --&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing Information Gathering|'''4.2 Information Gathering ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Search engine discovery/reconnaissance (OWASP-IG-002)|4.2.1 Conduct Search Engine Discovery and Reconnaissance for Information Leakage (OTG-INFO-001) ]] formerly &amp;quot;Search Engine Discovery/Reconnaissance (OWASP-IG-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-004)|4.2.2 Fingerprint Web Server (OTG-INFO-002) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing: Spiders, Robots, and Crawlers (OWASP-IG-001)|4.2.3 Review Webserver Metafiles for Information Leakage (OTG-INFO-003) ]] formerly &amp;quot;Spiders, Robots and Crawlers (OWASP-IG-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Application Discovery (OWASP-IG-005)|4.2.4 Enumerate Applications on Webserver (OTG-INFO-004) ]] formerly &amp;quot;Application Discovery (OWASP-IG-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Review webpage comments and metadata(OWASP-IG-007)|4.2.5 Review Webpage Comments and Metadata for Information Leakage (OTG-INFO-005) ]] formerly &amp;quot;Review webpage comments and metadata(OWASP-IG-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing: Identify application entry points (OWASP-IG-003)|4.2.6 Identify application entry points (OTG-INFO-006) ]] formerly &amp;quot;Identify application entry points (OWASP-IG-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Identify application exit/handover points (OWASP-IG-008)|4.2.7 Identify application exit/handover points (OTG-INFO-007) ]] formerly &amp;quot;Identify application exit/handover points (OWASP-IG-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing Map execution paths through application (OWASP-IG-009)|4.2.8 Map execution paths through application (OTG-INFO-008)]] formerly &amp;quot;Map execution paths through application (OWASP-IG-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-010)|4.2.9 Fingerprint Web Application Framework (OTG-INFO-009) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application (OTG-INFO-011)|4.2.10 Fingerprint Web Application (OTG-INFO-010) ]] formerly &amp;quot;Testing for Web Application Fingerprint (OWASP-IG-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Map Network and Application Architecture (OTG-INFO-012)|4.2.11 Map Network and Application Architecture (OTG-INFO-011) ]] formerly &amp;quot;Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for configuration management|'''4.3 Configuration and Deploy Management Testing ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for infrastructure configuration management (OWASP-CM-003)|4.3.1 Test Network/Infrastructure Configuration (OTG-CONFIG-001) ]] formerly &amp;quot;Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for application configuration management (OWASP-CM-004)|4.3.2 Test Application Platform Configuration (OTG-CONFIG-002 ]] formerly &amp;quot;Testing for Application Configuration Management weakness (OWASP-CM-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for file extensions handling  (OWASP-CM-005)|4.3.3 Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003) ]] formerly &amp;quot;Testing for File Extensions Handling  (OWASP-CM-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Old, Backup and Unreferenced Files (OWASP-CM-006)|4.3.4 Review Old, Backup and Unreferenced Files for Sensitive Information (OTG-CONFIG-004) ]] formerly &amp;quot;Old, Backup and Unreferenced Files (OWASP-CM-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Admin Interfaces  (OWASP-CM-007)|4.3.5 Enumerate Infrastructure and Application Admin Interfaces (OTG-CONFIG-005) ]] formerly &amp;quot;Infrastructure and Application Admin Interfaces  (OWASP-CM-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Methods and XST  (OWASP-CM-008)|4.3.6 Test HTTP Methods (OTG-CONFIG-006) ]] formerly &amp;quot;Testing for Bad HTTP Methods (OWASP-CM-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Database credentials/connection strings available|4.3.7 Testing for Database credentials/connection strings available (OTG-CONFIG-007) ]] formerly &amp;quot;Testing for Database credentials/connection strings available (OWASP-CM-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Security Policy weakness|4.3.8 Test Content Security Policy (OTG-CONFIG-008) ]] formerly &amp;quot;Testing for Content Security Policy weakness (OWASP-CM-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Missing HSTS header|4.3.9 Test HTTP Strict Transport Security (OTG-CONFIG-009) ]] formerly &amp;quot;Testing for Missing HSTS header (OWASP-CM-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Frame Options|4.3.10 Test Frame Options (OTG-CONFIG-010) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for RIA policy files weakness|4.3.11 Test RIA cross domain policy (OTG-CONFIG-011) ]] formerly &amp;quot;Testing for RIA policy files weakness (OWASP-CM-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Type Options|4.3.12 Test Content Type Options (OTG-CONFIG-012) ]] new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing Identity Management|'''4.4 Identity Management Testing''']]&lt;br /&gt;
&lt;br /&gt;
[[Test Role Definitions (OTG-IDENT-001)|4.4.1 Test Role Definitions (OTG-IDENT-001)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test User Registration Process (OTG-IDENT-002)|4.4.2 Test User Registration Process (OTG-IDENT-002)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Provisioning Process (OTG-IDENT-003)|4.4.3 Test Account Provisioning Process (OTG-IDENT-003)]] New&lt;br /&gt;
&lt;br /&gt;
[[Testing for Account Enumeration and Guessable User Account (OWASP-AT-002)|4.4.4 Testing for Account Enumeration and Guessable User Account (OTG-IDENT-004) ]] formerly &amp;quot;Testing for Account Enumeration and Guessable User Account (OWASP-AT-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak or unenforced username policy (OWASP-AT-009)| 4.4.5 Testing for Weak or unenforced username policy (OTG-IDENT-005)]] formerly &amp;quot;Testing for Weak or unenforced username policy (OWASP-AT-009)&lt;br /&gt;
&lt;br /&gt;
[[Test Permissions of Guest/Training Accounts (OTG-IDENT-006)|4.4.6 Test Permissions of Guest/Training Accounts (OTG-IDENT-006)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Suspension/Resumption Process (OTG-IDENT-007)|4.4.7 Test Account Suspension/Resumption Process (OTG-IDENT-007)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test User Deregistration Process (OTG-IDENT-008)|4.4.8 Test User Deregistration Process (OTG-IDENT-008)]] New&lt;br /&gt;
&lt;br /&gt;
[[Test Account Deregistration Process (OTG-IDENT-009)|4.4.9 Test Account Deregistration Process (OTG-IDENT-009)]] New&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for authentication|'''4.5 Authentication Testing ''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Credentials Transported over an Encrypted Channel (OWASP-AT-001)|4.5.1 Testing for Credentials Transported over an Encrypted Channel  (OTG-AUTHN-001)]] formerly &amp;quot;Testing for Credentials Transported over an Encrypted Channel  (OWASP-AT-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for default credentials (OWASP-AT-003)|4.5.2 Testing for default credentials (OTG-AUTHN-002)]] formerly &amp;quot;Testing for default credentials (OWASP-AT-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak lock out mechanism (OWASP-AT-004)|4.5.3 Testing for Weak lock out mechanism (OTG-AUTHN-003)]] formerly &amp;quot;Testing for Weak lock out mechanism (OWASP-AT-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authentication Schema (OWASP-AT-005)|4.5.4 Testing for bypassing authentication schema (OTG-AUTHN-004)]] formerly &amp;quot;Testing for bypassing authentication schema (OWASP-AT-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Vulnerable Remember Password (OWASP-AT-006)|4.5.5 Test remember password functionality (OTG-AUTHN-005)]] formerly &amp;quot;Testing for vulnerable remember password functionality (OWASP-AT-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Browser cache weakness (OWASP-AT-007)|4.5.6 Testing for Browser cache weakness (OTG-AUTHN-006)]] formerly &amp;quot;Testing for Browser cache weakness (OWASP-AT-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak password policy (OWASP-AT-008)|4.5.7 Testing for Weak password policy (OTG-AUTHN-007)]] formerly &amp;quot;Testing for Weak password policy (OWASP-AT-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak security question/answer (OTG-AUTHN-008)|4.5.8 Testing for Weak security question/answer (OTG-AUTHN-008)]] New! - Robert Winkel&lt;br /&gt;
&lt;br /&gt;
[[Testing for weak password change or reset functionalities (OWASP-AT-011)|4.5.9 Testing for weak password change or reset functionalities (OTG-AUTHN-009)]] formerly &amp;quot;Testing for weak password change or reset functionalities (OWASP-AT-011)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weaker authentication in alternative channel (OTG-AUTHN-010)|4.5.10 Testing for Weaker authentication in alternative channel (OTG-AUTHN-010)]] (e.g. mobile app, IVR, help desk)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Authorization|'''4.6 Authorization Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Test Management of Account Permissions (OTG-AUTHZ-001)|4.6.1 Test Management of Account Permissions (OTG-AUTHZ-001)]] New&lt;br /&gt;
&lt;br /&gt;
[[Testing for Path Traversal  (OWASP-AZ-001)|4.6.2 Testing Directory traversal/file include (OTG-AUTHZ-002)]] formerly &amp;quot;Testing Directory traversal/file include (OWASP-AZ-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authorization Schema  (OWASP-AZ-002)|4.6.3 Testing for bypassing authorization schema (OTG-AUTHZ-003)]] formerly &amp;quot;Testing for bypassing authorization schema  (OWASP-AZ-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Privilege escalation  (OWASP-AZ-003)|4.6.4 Testing for Privilege Escalation (OTG-AUTHZ-004)]] formerly &amp;quot;Testing for Privilege Escalation  (OWASP-AZ-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Direct Object References (OWASP-AZ-004)|4.6.5 Testing for Insecure Direct Object References (OTG-AUTHZ-005)]] formerly &amp;quot;Testing for Insecure Direct Object References (OWASP-AZ-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)|4.6.6 Testing for Failure to Restrict access to authorized resource (OTG-AUTHZ-006)]] formerly &amp;quot;Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test privileges of server components (OTG-AUTHZ-007)|4.6.7 Test privileges of server components (OTG-AUTHZ-007)]] (e.g. indexing service, reporting interface, file generator)&lt;br /&gt;
&lt;br /&gt;
[[Test enforcement of application entry points (OTG-AUTHZ-008)|4.6.8 Test enforcement of application entry points (OTG-AUTHZ-008)]] (including exposure of objects)&lt;br /&gt;
&lt;br /&gt;
[[Testing for failure to restrict access to authenticated resource(OWASP-AT-010)|4.6.9 Testing for failure to restrict access to authenticated resource (OTG-AUTHZ-009)]] formerly &amp;quot;Testing for failure to restrict access to authenticated resource (OWASP-AT-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Management|'''4.7 Session Management Testing''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session_Management_Schema (OWASP-SM-001)|4.7.1 Testing for Bypassing Session Management Schema (OTG-SESS-001)]] formerly &amp;quot;Testing for Bypassing Session Management Schema (OWASP-SM-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for cookies attributes  (OWASP-SM-002)|4.7.2 Testing for Cookies attributes (OTG-SESS-002)]] formerly &amp;quot;Testing for Cookies attributes (OWASP-SM-002)&amp;quot; (Cookies are set not ‘HTTP Only’, ‘Secure’,  and no time validity)&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Fixation  (OWASP-SM-003)|4.7.3 Testing for Session Fixation (OTG-SESS-003)]] formerly &amp;quot;Testing for Session Fixation  (OWASP-SM-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Exposed Session Variables  (OWASP-SM-004)|4.7.4 Testing for Exposed Session Variables (OTG-SESS-004)]] formerly &amp;quot;Testing for Exposed Session Variables (OWASP-SM-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for CSRF  (OWASP-SM-005)|4.7.5 Testing for Cross Site Request Forgery (CSRF) (OTG-SESS-005)]] formerly &amp;quot;Testing for Cross Site Request Forgery (CSRF) (OWASP-SM-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test Session Token Strength (OTG-SESS-006)|4.7.6 Test Session Token Strength (OTG-SESS-006)]]&lt;br /&gt;
 &lt;br /&gt;
[[Testing for logout functionality (OWASP-SM-007)|4.7.7 Testing for logout functionality (OTG-SESS-007)]] formerly &amp;quot;Testing for logout functionality (OWASP-SM-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session puzzling (OWASP-SM-008)|4.7.8 Testing for Session puzzling (OWASP-SM-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Session Timeout (OTG-SESS-008)|4.7.8 Test Session Timeout (OTG-SESS-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Test multiple concurrent sessions (OTG-SESS-009)|4.7.9 Test multiple concurrent sessions (OTG-SESS-009)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Data Validation|'''4.8 Data Validation Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Reflected Cross site scripting (OWASP-DV-001) |4.8.1 Testing for Reflected Cross Site Scripting (OTG-INPVAL-001)]] formerly &amp;quot;Testing for Reflected Cross Site Scripting (OWASP-DV-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stored Cross site scripting (OWASP-DV-002) |4.8.2 Testing for Stored Cross Site Scripting (OTG-INPVAL-002)]] formerly &amp;quot;Testing for Stored Cross Site Scripting (OWASP-DV-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Verb Tampering (OWASP-DV-003)|4.8.3 Testing for HTTP Verb Tampering (OTG-INPVAL-003)]] formerly &amp;quot;Testing for HTTP Verb Tampering (OWASP-DV-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Parameter pollution (OWASP-DV-004)|4.8.4 Testing for HTTP Parameter pollution (OTG-INPVAL-004) ]] formerly &amp;quot;Testing for HTTP Parameter pollution (OWASP-DV-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)|4.8.5 Testing for Unvalidated Redirects and Forwards (OTG-INPVAL-005) ]] formerly &amp;quot;Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Injection (OWASP-DV-005)| 4.8.6 Testing for SQL Injection (OTG-INPVAL-006)]] formerly &amp;quot;Testing for SQL Injection (OWASP-DV-005)&amp;quot; '''Ready to be reviewed'''&lt;br /&gt;
&lt;br /&gt;
[[Testing for Oracle|4.8.6.1 Oracle Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MySQL|4.8.6.2 MySQL Testing [Ismael Gonçalves]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Server|4.8.6.3 SQL Server Testing]]&lt;br /&gt;
&lt;br /&gt;
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.6.4 Testing PostgreSQL (from OWASP BSP) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MS Access |4.8.6.5 MS Access Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for NoSQL injection|4.8.6.6 Testing for NoSQL injection [New!]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for LDAP Injection  (OWASP-DV-006)|4.8.7 Testing for LDAP Injection  (OTG-INPVAL-007)]] formerly &amp;quot;Testing for LDAP Injection  (OWASP-DV-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for ORM Injection   (OWASP-DV-007)|4.8.8 Testing for ORM Injection   (OTG-INPVAL-008)]] formerly &amp;quot;Testing for ORM Injection   (OWASP-DV-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for XML Injection (OWASP-DV-008)|4.8.9 Testing for XML Injection (OTG-INPVAL-009)]] formerly &amp;quot;Testing for XML Injection (OWASP-DV-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for SSI Injection  (OWASP-DV-009)|4.8.10 Testing for SSI Injection  (OTG-INPVAL-010)]] formerly &amp;quot;Testing for SSI Injection  (OWASP-DV-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for XPath Injection  (OWASP-DV-010)|4.8.11 Testing for XPath Injection  (OTG-INPVAL-011)]] formerly &amp;quot;Testing for XPath Injection  (OWASP-DV-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for IMAP/SMTP Injection  (OWASP-DV-011)|4.8.12 IMAP/SMTP Injection  (OTG-INPVAL-012)]] formerly &amp;quot;IMAP/SMTP Injection  (OWASP-DV-011)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Code Injection  (OWASP-DV-012)|4.8.13 Testing for Code Injection  (OTG-INPVAL-013)]] formerly &amp;quot;Testing for Code Injection  (OWASP-DV-012)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Local File Inclusion|4.8.13.1 Testing for Local File Inclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Remote File Inclusion|4.8.13.2 Testing for Remote File Inclusion]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Command Injection   (OWASP-DV-013)|4.8.14 Testing for Command Injection   (OTG-INPVAL-014)]] formerly &amp;quot;Testing for Command Injection   (OWASP-DV-013)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Buffer Overflow (OWASP-DV-014)|4.8.15 Testing for Buffer overflow (OTG-INPVAL-015)]] formerly &amp;quot;Testing for Buffer overflow (OWASP-DV-014)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Heap Overflow|4.8.15.1 Testing for Heap overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Overflow|4.8.15.2 Testing for Stack overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Format String|4.8.15.3 Testing for Format string]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Incubated Vulnerability (OWASP-DV-015)|4.8.16 Testing for incubated vulnerabilities (OTG-INPVAL-016)]] formerly &amp;quot;Testing for incubated vulnerabilities (OWASP-DV-015)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)|4.8.17 Testing for HTTP Splitting/Smuggling  (OTG-INPVAL-017) ]] formerly &amp;quot;Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Error Handling|'''4.9 Error Handling''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Error Code (OWASP-IG-006)|4.9.1 Analysis of Error Codes (OTG-ERR-001)]] formerly &amp;quot;Analysis of Error Codes (OWASP-IG-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Traces (OWASP-IG-006)|4.9.1 Analysis of Error Codes (OTG-ERR-002)]] formerly &amp;quot;Analysis of Stack Traces (OWASP-IG-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Cryptography|'''4.10 Cryptography''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure encryption usage (OWASP-EN-001)| 4.10.1  Testing for Insecure encryption usage (OTG-CRYPST-001)]] formerly &amp;quot;Testing for Insecure encryption usage (OWASP-EN-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)| 4.10.2 Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OTG-CRYPST-002)]] formerly &amp;quot;Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Padding Oracle (OWASP-EN-003)| 4.10.3 Testing for Padding Oracle (OTG-CRYPST-003)]] formerly &amp;quot;Testing for Padding Oracle (OWASP-EN-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cacheable HTTPS Response (OTG-CRYPST-004)| 4.10.4 Testing for Cacheable HTTPS Response (OTG-CRYPST-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Cache Directives (OTG-CRYPST-005)|4.10.5 Test Cache Directives (OTG-CRYPST-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Cryptographic Storage (OTG-CRYPST-006)|4.10.6 Testing for Insecure Cryptographic Storage (OTG-CRYPST-006)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Sensitive information sent via unencrypted channels (OTG-CRYPST-007)|4.10.7 Testing for Sensitive information sent via unencrypted channels (OTG-CRYPST-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Test Cryptographic Key Management (OTG-CRYPST-008)|4.10.8 Test Cryptographic Key Management (OTG-CRYPST-008)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Logging|'''4.11 Logging''']] Not convinced Logging should be included as it requires access to logs to test&lt;br /&gt;
&lt;br /&gt;
[[Test time synchronisation (OTG-LOG-001)|4.11.1 Test time synchronisation (OTG-LOG-001) ]] formerly &amp;quot;Incorrect time&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Test user-viewable log of authentication events (OTG-LOG-002)|4.11.2 Test user-viewable log of authentication events (OTG-LOG-002)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for business logic   (OWASP-BL-001)|'''4.12 Business Logic Testing  (OWASP-BL-001)''']] [To review--&amp;gt; David Fern]&lt;br /&gt;
Business Logic&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Test business logic data validation (OTG-BUSLOGIC-001)|4.12.1 Test business logic data validation (OTG-BUSLOGIC-001)]] [New!] NOTE MAT: to discuss this section&lt;br /&gt;
&lt;br /&gt;
[[Test Ability to forge requests (OTG-BUSLOGIC-002)|4.12.2 Test Ability to forge requests (OTG-BUSLOGIC-002)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test integrity checks (OTG-BUSLOGIC-003)|4.12.3 Test integrity checks (OTG-BUSLOGIC-003)]] (e.g. overwriting updates) [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test tamper evidence (OTG-BUSLOGIC-004)|4.12.4 Test tamper evidence (OTG-BUSLOGIC-004)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test excessive rate (speed) of use limits (OTG-BUSLOGIC-005)|4.12.5 Test excessive rate (speed) of use limits (OTG-BUSLOGIC-005)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test size of request limits (OTG-BUSLOGIC-006)|4.12.6 Test size of request limits (OTG-BUSLOGIC-006)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test number of times a function can be used limits (OTG-BUSLOGIC-007)|4.12.7 Test number of times a function can be used limits (OTG-BUSLOGIC-002)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test bypass of correct sequence (OTG-BUSLOGIC-008)|4.12.8 Test bypass of correct sequence (OTG-BUSLOGIC-008)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test self-hosted payment cardholder data processing (OTG-BUSLOGIC-009)|4.12.9 Test self-hosted payment cardholder data processing (OTG-BUSLOGIC-009)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test security incident reporting information (OTG-BUSLOGIC-010)|4.12.10 Test security incident reporting information (OTG-BUSLOGIC-010)]] [New!]&lt;br /&gt;
&lt;br /&gt;
[[Test defenses against application mis-use (OTG-BUSLOGIC-011)|4.12.11 Test defenses against application mis-use (OTG-BUSLOGIC-011)]] [New!]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Denial of Service|'''4.13 Denial of Service''']]&lt;br /&gt;
&lt;br /&gt;
[[Test Regular expression DoS (OTG-DOS-001)| 4.13.1 Test Regular expression DoS (OTG-DOS-001)]] [New!] note: to understand better&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Test XML DoS (OTG-DOS-002)| 4.13.2 Test XML DoS (OTG-DOS-002)]] [New! - Andrew Muller]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Captcha (OWASP-AT-012)|4.13.3 Testing for CAPTCHA (OTG-DOS-003)]] formerly &amp;quot;Testing for CAPTCHA (OWASP-AT-012)&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Web Service (XML Interpreter)|'''4.14 Web Service Testing''']] [Tom Eston] &lt;br /&gt;
&lt;br /&gt;
[[Scoping a Web Service Test (OWASP-WS-001)|4.14.1 Scoping a Web Service Test (OTG-WEBSVC-001)]] formerly &amp;quot;Scoping a Web Service Test (OWASP-WS-001)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Information Gathering (OWASP-WS-002)|4.14.2 WS Information Gathering (OTG-WEBSVC-002)]] formerly &amp;quot;WS Information Gathering (OWASP-WS-002)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Authentication Testing (OWASP-WS-003)|4.14.3 WS Authentication Testing (OTG-WEBSVC-003)]] formerly &amp;quot;WS Authentication Testing (OWASP-WS-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Management Interface Testing (OWASP-WS-004)|4.14.4 WS Management Interface Testing (OTG-WEBSVC-004)]] formerly &amp;quot;WS Management Interface Testing (OWASP-WS-004)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Weak XML Structure Testing (OWASP-WS-005)|4.14.5 Weak XML Structure Testing (OTG-WEBSVC-005)]] formerly &amp;quot;Weak XML Structure Testing (OWASP-WS-005)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[XML Content-Level Testing (OWASP-WS-006)|4.14.6 XML Content-Level Testing (OTG-WEBSVC-006)]] formerly &amp;quot;XML Content-Level Testing (OWASP-WS-006)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS HTTP GET Parameters/REST Testing (OWASP-WS-007)|4.14.7 WS HTTP GET Parameters/REST Testing (OTG-WEBSVC-007)]] formerly &amp;quot;WS HTTP GET Parameters/REST Testing (OWASP-WS-007)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Naughty SOAP Attachment Testing (OWASP-WS-008)|4.14.8 WS Naughty SOAP Attachment Testing (OTG-WEBSVC-008)]] formerly &amp;quot;WS Naughty SOAP Attachment Testing (OWASP-WS-008)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS Replay/MiTM Testing (OWASP-WS-009)|4.14.9 WS Replay/MiTM Testing (OTG-WEBSVC-009)]] formerly &amp;quot;WS Replay/MiTM Testing (OWASP-WS-009)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[WS BEPL Testing (OWASP-WS-010)|4.14.10 WS BEPL Testing (OTG-WEBSVC-010)]] formerly &amp;quot;WS BEPL Testing (OWASP-WS-010)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Client Side Testing|'''4.15 Client Side Testing''']] [New!] &lt;br /&gt;
&lt;br /&gt;
[[Testing for DOM-based Cross site scripting  (OWASP-DV-003)|4.15.1 Testing for DOM based Cross Site Scripting  (OTG-CLIENT-001)]] formerly &amp;quot;Testing for DOM based Cross Site Scripting  (OWASP-CS-001)&amp;quot; [Stefano Di Paola]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTML5 (OWASP CS-002)|4.15.2 Testing for HTML5 (OTG-CLIENT-002)]] formerly &amp;quot;Testing for HTML5 (OWASP CS-002)&amp;quot; [Juan Galiana]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cross site flashing (OWASP-DV-004)|4.15.3 Testing for Cross Site Flashing   (OTG-CLIENT-003)]] formerly &amp;quot;Testing for Cross Site Flashing   (OWASP-CS-003)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Clickjacking (OWASP-CS-004)|4.15.4 Testing for Clickjacking (OTG-CLIENT-004)]] formerly &amp;quot;Testing for Clickjacking (OWASP-CS-004)&amp;quot; [Davide Danelon] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Writing Reports: value the real risk |5. Writing Reports: value the real risk ]]==&lt;br /&gt;
&lt;br /&gt;
[[How to value the real risk |5.1 How to value the real risk]] [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
[[How to write the report of the testing |5.2 How to write the report of the testing]] [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
==[[Appendix A: Testing Tools |Appendix A: Testing Tools ]]==&lt;br /&gt;
&lt;br /&gt;
* Black Box Testing Tools [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix B: Suggested Reading | Appendix B: Suggested Reading]]==&lt;br /&gt;
* Whitepapers [To review--&amp;gt; David Fern]&lt;br /&gt;
* Books [To review--&amp;gt; David Fern]&lt;br /&gt;
* Useful Websites [To review--&amp;gt; David Fern]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix C: Fuzz Vectors | Appendix C: Fuzz Vectors]]==&lt;br /&gt;
&lt;br /&gt;
* Fuzz Categories [To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix D: Encoded Injection | Appendix D: Encoded Injection]]==&lt;br /&gt;
&lt;br /&gt;
[To review--&amp;gt; Amro AlOlaqi]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Testing Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=154229</id>
		<title>Injection Theory</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=154229"/>
				<updated>2013-06-21T17:35:12Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Injection Flaws|Injection]] is an attacker's attempt to send data to an application in a way that will change the meaning of commands being sent to an interpreter.  For example, the most common example is SQL injection, where an attacker sends &amp;quot;101 OR 1=1&amp;quot; instead of just &amp;quot;101&amp;quot;.  When included in a SQL query, this data changes the meaning to return ALL records instead of just one.  There are lots of interpreters in the typical web environment, such as SQL, LDAP, Operating System, XPath, XQuery, Expression Language, and many more.  Anything with a &amp;quot;command interface&amp;quot; that combines data into a command is susceptible.  Even XSS is really just a form of HTML injection.&lt;br /&gt;
&lt;br /&gt;
Frequently these interpreters run with a lot of access, so a successful attack can easily result in significant data breaches, or even loss of control of a browser, application, or server. Taken together, injection attacks are a huge percentage of the serious application security risk. Many organizations have poorly thought through security controls in place to prevent injection attacks.  Vague recommendations for input validation and output encoding are not going to prevent these flaws.  Instead, we recommend a strong set of controls integrated into your application frameworks.  The goal is to make injections impossible for developers.&lt;br /&gt;
&lt;br /&gt;
=Why Injection Happens to Good Developers=&lt;br /&gt;
&lt;br /&gt;
Injection can be complex. The subtleties of data flow, parsers, contexts, capabilities, and escaping are overwhelming even for security specialists.  In the following sections we will outline these topics to make it clear how injection can happen in a variety of different technologies.&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
First we need to consider the vehicle for injection attacks -- untrusted data.&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, untrusted data is input that can be manipulated to contain a web attack payload. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
As untrusted data flows through an application, it is frequently split into parts, combined with safe data, transformed, validated, and encoded in a variety of ways. A single piece of data could go through dozens of these steps before it gets to an interpreter.  This makes identifying injection problems very difficult.  Tools have a difficult time tracing the entire data flow and understanding exactly what data can run the gauntlet and what cannot.&lt;br /&gt;
&lt;br /&gt;
== Injection Context ==&lt;br /&gt;
&lt;br /&gt;
When untrusted data is used by an application, it is often inserted into a command, document, or other structure.  We will call this the '''injection context'''.  For example, consider a SQL statement constructed with &amp;quot;SELECT * FROM users WHERE name='&amp;quot; + request.getParameter( &amp;quot;name&amp;quot; ) + &amp;quot;'&amp;quot;;  In this example, the name is data from a potentially hostile user, and so could contain an attack.  But the attack is constrained by the injection context.  In this case, inside single quotes (').  That's why single quotes are so important for SQL injection.&lt;br /&gt;
&lt;br /&gt;
Consider a few of the types of commands and documents that might allow for injection...&lt;br /&gt;
* SQL queries&lt;br /&gt;
* LDAP queries&lt;br /&gt;
* Operating system command interpreters&lt;br /&gt;
* Any program invocation&lt;br /&gt;
* XML documents&lt;br /&gt;
* HTML documents&lt;br /&gt;
* JSON structures&lt;br /&gt;
* HTTP headers&lt;br /&gt;
* File paths&lt;br /&gt;
* URLs&lt;br /&gt;
* A variety of expresson languages&lt;br /&gt;
* etc...&lt;br /&gt;
&lt;br /&gt;
In all of these cases, if the attacker can &amp;quot;break out&amp;quot; of the intended injection context and modify the meaning of the command or document, they might be able to cause significant harm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Parsers ==&lt;br /&gt;
&lt;br /&gt;
TBD.  Describe different types of parsers, tokens (particularly control characters), BNF.&lt;br /&gt;
&lt;br /&gt;
== Injection into References ==&lt;br /&gt;
&lt;br /&gt;
TBD. This is for URLs, paths, and other simple forms.  Focus on the parser.  Could be as simple as Double.parseDouble (mark of the beast)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection into Commands ==&lt;br /&gt;
&lt;br /&gt;
TBD. Recursive descent or LALR parsers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injecting in Hierarchical Documents ==&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection with Multiple Nested Parsers ==&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=DEFENSES=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Validation ==&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
== Using Safe Interfaces ==&lt;br /&gt;
&lt;br /&gt;
TBD - parameterized interfaces with strong typing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
&lt;br /&gt;
[[User:Jeff Williams]] : jeff.williams[at]aspectsecurity.com&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=153922</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=153922"/>
				<updated>2013-06-17T04:38:20Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: /* RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the [[XSS Filter Evasion Cheat Sheet]]. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
Before reading this cheatsheet, it is important to have a fundamental understanding of [[Injection Theory]].&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
Microsoft provides an encoding library named the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] for the .NET platform and ASP.NET Framework has built-in [http://msdn.microsoft.com/en-us/library/ms972969.aspx#securitybarriers_topic6 ValidateRequest] function that provides '''limited''' sanitization.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library for Java. OWASP also provides the [[OWASP Java Encoder Project]] for high-performance encoding.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; not recommended because its not in the HTML spec (See: [http://www.w3.org/TR/html4/sgml/entities.html section 24.4.1]) &amp;amp;amp;apos; is in the XML and XHTML specs.&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
=== RULE #3.1 - HTML escape JSON values in an HTML context and read the data with JSON.parse ===&lt;br /&gt;
&lt;br /&gt;
In a Web 2.0 world, the need for having data dynamically generated by an application in a javascript context is common.  One strategy is to make an AJAX call to get the values, but this isn't always performant.  Often, an initial block of JSON is loaded into the page to act as a single place to store multiple values.  This data is tricky, though not impossible, to escape correctly without breaking the format and content of the values.&lt;br /&gt;
&lt;br /&gt;
'''Ensure returned ''Content-Type'' header is application/json and not text/html. &lt;br /&gt;
This shall instruct the browser not misunderstand the contect and execute injected script'''&lt;br /&gt;
&lt;br /&gt;
'''Bad HTTP response:'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: text/html; charset=utf-8''' &amp;lt;-- bad&lt;br /&gt;
    ....&lt;br /&gt;
    Content-Length: 373&lt;br /&gt;
    Keep-Alive: timeout=5, max=100&lt;br /&gt;
    Connection: Keep-Alive&lt;br /&gt;
    {&amp;quot;Message&amp;quot;:&amp;quot;No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&amp;amp;AddressLine&lt;br /&gt;
    =The+Gardens'''&amp;amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;'''&amp;amp;AddressLine2=foxlodge+woods&amp;amp;TownName=Meath'.&amp;quot;,&amp;quot;MessageDetail&amp;quot;:&amp;quot;No type was found&lt;br /&gt;
    that matches the controller named 'pay'.&amp;quot;}   &amp;lt;-- this script will pop!!&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
'''Good HTTP response'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: application/json; charset=utf-8''' &amp;lt;--good&lt;br /&gt;
    .....&lt;br /&gt;
    .....&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A common '''anti-pattern''' one would see:&lt;br /&gt;
&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      var initData = &amp;lt;%= data.to_json %&amp;gt;; // '''Do NOT do this.'''&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, consider placing the JSON block on the page as a normal element and then parsing the innerHTML to get the contents.  The javascript that reads the span can live in an external file, thus making the implementation of CSP enforcement easier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script id=&amp;quot;init_data&amp;quot; type=&amp;quot;application/json&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;amp;lt;%= data.to_json %&amp;gt;  &amp;amp;lt;-- data is HTML escaped, or at least json entity escaped --&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
    var jsonText = document.getElementById('init_data').innerHTML;  // unescapes the content of the span&lt;br /&gt;
    var initData = JSON.parse(jsonText); &lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The data is added to the page and is HTML entity escaped so it won't pop in the HTML context.  The data is then read by innerHTML, which unescapes the value.  The unescaped text from the page is then parsed with JSON.parse.&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Sanitize HTML Markup with a Library Designed for the Job ==&lt;br /&gt;
&lt;br /&gt;
If your application handles markup -- untrusted input that is supposed to contain HTML -- it can be very difficult to validate. Encoding is also difficult, since it would break all the tags that are supposed to be in the input. Therefore, you need a library that can parse and clean HTML formatted text.  There are several available at OWASP that are simple to use:&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy''' - https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The following snippets of HTML demonstrate how to safely render untrusted data in a variety of different contexts. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable nowraplinks&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Data Type&lt;br /&gt;
! Context&lt;br /&gt;
! Code Sample&lt;br /&gt;
! Defense&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;span&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;amp;lt;/span&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Safe HTML Attributes&lt;br /&gt;
| &amp;amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;fname&amp;quot; value=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes Aggressive HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Only place untrusted data into a whitelist of safe attributes (listed below).&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Strictly validate unsafe attributes such as background, id and name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| GET Parameter&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;/site/search?value=&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.235_-_URL_Escape_Before_Inserting_Untrusted_Data_into_HTML_URL_Parameter_Values URL Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Untrusted URL in a SRC or HREF attribute&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;iframe src=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Cannonicalize input&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;URL Validation&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Safe URL verification&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Whitelist http and https URL's only ([[Avoid the JavaScript Protocol to Open a new Window]])&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Attribute encoder&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| CSS Value&lt;br /&gt;
| &amp;amp;lt;div style=&amp;quot;width: &amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;;&amp;quot;&amp;gt;Selection&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values Strict structural validation]&amp;lt;li&amp;gt;CSS Hex encoding&amp;lt;li&amp;gt;Good design of CSS Features&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| JavaScript Variable&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;var currentValue='&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;';&amp;amp;lt;/script&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;script&amp;gt;someFunction('&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;');&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Ensure JavaScript variables are quoted&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Hex Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Unicode Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Avoid backslash encoding (\&amp;quot; or \' or \\)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| HTML&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;div&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED HTML&amp;lt;/span&amp;gt;&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Use_an_HTML_Policy_engine_to_validate_or_clean_user-driven_HTML_in_an_outbound_way HTML Validation (JSoup, AntiSamy, HTML Sanitizer)]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| DOM XSS&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;document.write(&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;quot;UNTRUSTED INPUT: &amp;quot; + document.location.hash&amp;lt;/span&amp;gt;);&amp;amp;lt;script/&amp;amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[[DOM based XSS Prevention Cheat Sheet]]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''''Safe HTML Attributes include:''''' align, alink, alt, bgcolor, border, cellpadding, cellspacing, class, color, cols, colspan, coords, dir, face, height, hspace, ismap, lang, marginheight, marginwidth, multiple, nohref, noresize, noshade, nowrap, ref, rel, rev, rows, rowspan, scrolling, shape, span, summary, tabindex, title, usemap, valign, value, vlink, vspace, width&lt;br /&gt;
&lt;br /&gt;
= Output Encoding Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The purpose of output encoding (as it relates to Cross Site Scripting) is to convert untrusted input into a safe form where the input is displayed as '''data''' to the user without executing as '''code''' in the browser. The following charts details a list of critical output encoding methods needed to stop Cross Site Scripting.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Encoding Type&lt;br /&gt;
! Encoding Mechanism&lt;br /&gt;
|-&lt;br /&gt;
| HTML Entity Encoding&lt;br /&gt;
|   Convert &amp;amp; to &amp;amp;amp;amp;&amp;lt;br/&amp;gt;Convert &amp;lt; to &amp;amp;amp;lt;&amp;lt;br/&amp;gt;Convert &amp;gt; to &amp;amp;amp;gt;&amp;lt;br/&amp;gt;Convert &amp;quot; to &amp;amp;amp;quot;&amp;lt;br/&amp;gt;Convert ' to &amp;amp;amp;#x27;&amp;lt;br/&amp;gt;Convert / to &amp;amp;amp;#x2F;&lt;br /&gt;
|-&lt;br /&gt;
| HTML Attribute Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the HTML Entity &amp;amp;amp;#xHH; format, including spaces. (HH = Hex Value)&lt;br /&gt;
|-&lt;br /&gt;
| URL Encoding&lt;br /&gt;
| Standard percent encoding, see: [http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp]&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the \uXXXX unicode escaping format (X = Integer).&lt;br /&gt;
|-&lt;br /&gt;
| CSS Hex Encoding&lt;br /&gt;
| CSS escaping supports \XX and \XXXXXX. Using a two character escape can cause problems if the next character continues the escape sequence. There are two solutions (a) Add a space after the CSS escape (will be ignored by the CSS parser) (b) use the full amount of CSS escaping possible by zero padding the value.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* [[XSS Experimental Minimal Encoding Rules]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Eoin Keary - eoin.keary[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=153921</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=153921"/>
				<updated>2013-06-17T04:37:03Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: /* RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the [[XSS Filter Evasion Cheat Sheet]]. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
Before reading this cheatsheet, it is important to have a fundamental understanding of [[Injection Theory]].&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
Microsoft provides an encoding library named the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] for the .NET platform and ASP.NET Framework has built-in [http://msdn.microsoft.com/en-us/library/ms972969.aspx#securitybarriers_topic6 ValidateRequest] function that provides '''limited''' sanitization.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library for Java. OWASP also provides the [[OWASP Java Encoder Project]] for high-performance encoding.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; not recommended because its not in the HTML spec (See: [http://www.w3.org/TR/html4/sgml/entities.html section 24.4.1]) &amp;amp;amp;apos; is in the XML and XHTML specs.&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
=== RULE #3.1 - HTML escape JSON values in an HTML context and read the data with JSON.parse ===&lt;br /&gt;
&lt;br /&gt;
In a Web 2.0 world, the need for having data dynamically generated by an application in a javascript context is common.  One strategy is to make an AJAX call to get the values, but this isn't always performant.  Often, an initial block of JSON is loaded into the page to act as a single place to store multiple values.  This data is tricky, though not impossible, to escape correctly without breaking the format and content of the values.&lt;br /&gt;
&lt;br /&gt;
'''Ensure returned ''Content-Type'' header is application/json and not text/html. &lt;br /&gt;
This shall instruct the browser not misunderstand the contect and execute injected script'''&lt;br /&gt;
&lt;br /&gt;
'''Bad HTTP response:'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: text/html; charset=utf-8''' &amp;lt;-- bad&lt;br /&gt;
    ....&lt;br /&gt;
    Content-Length: 373&lt;br /&gt;
    Keep-Alive: timeout=5, max=100&lt;br /&gt;
    Connection: Keep-Alive&lt;br /&gt;
    {&amp;quot;Message&amp;quot;:&amp;quot;No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&amp;amp;AddressLine&lt;br /&gt;
    =The+Gardens'''&amp;amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;'''&amp;amp;AddressLine2=foxlodge+woods&amp;amp;TownName=Meath'.&amp;quot;,&amp;quot;MessageDetail&amp;quot;:&amp;quot;No type was found&lt;br /&gt;
    that matches the controller named 'pay'.&amp;quot;}   &amp;lt;-- this script will pop!!&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
'''Good HTTP response'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: application/json; charset=utf-8''' &amp;lt;--good&lt;br /&gt;
    .....&lt;br /&gt;
    .....&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A common '''anti-pattern''' one would see:&lt;br /&gt;
&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      var initData = &amp;lt;%= data.to_json %&amp;gt;; // '''Do NOT do this.'''&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, consider placing the JSON block on the page as a normal element and then parsing the innerHTML to get the contents.  The javascript that reads the span can live in an external file, thus making the implementation of CSP enforcement easier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script id=&amp;quot;init_data&amp;quot; type=&amp;quot;application/json&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;amp;lt;%= data.to_json %&amp;gt;  &amp;amp;lt;-- data is HTML escaped, or at least json entity escaped --&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
    var jsonText = document.getElementById('init_data').innerHTML;  // unescapes the content of the span&lt;br /&gt;
    var initData = JSON.parse(jsonText); &lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The data is added to the page and is HTML entity escaped so it won't pop in the HTML context.  The data is then read by innerHTML, which unescapes the value.  The unescaped text from the page is then parsed with JSON.parse.&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
If your application handles markup -- untrusted input that is supposed to contain HTML -- it can be very difficult to validate. Encoding is also difficult, since it would break all the tags that are supposed to be in the input. Therefore, you need a library that can parse and clean HTML formatted text.  There are several available at OWASP that are simple to use:&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy''' - https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The following snippets of HTML demonstrate how to safely render untrusted data in a variety of different contexts. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable nowraplinks&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Data Type&lt;br /&gt;
! Context&lt;br /&gt;
! Code Sample&lt;br /&gt;
! Defense&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;span&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;amp;lt;/span&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Safe HTML Attributes&lt;br /&gt;
| &amp;amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;fname&amp;quot; value=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes Aggressive HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Only place untrusted data into a whitelist of safe attributes (listed below).&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Strictly validate unsafe attributes such as background, id and name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| GET Parameter&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;/site/search?value=&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.235_-_URL_Escape_Before_Inserting_Untrusted_Data_into_HTML_URL_Parameter_Values URL Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Untrusted URL in a SRC or HREF attribute&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;iframe src=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Cannonicalize input&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;URL Validation&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Safe URL verification&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Whitelist http and https URL's only ([[Avoid the JavaScript Protocol to Open a new Window]])&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Attribute encoder&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| CSS Value&lt;br /&gt;
| &amp;amp;lt;div style=&amp;quot;width: &amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;;&amp;quot;&amp;gt;Selection&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values Strict structural validation]&amp;lt;li&amp;gt;CSS Hex encoding&amp;lt;li&amp;gt;Good design of CSS Features&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| JavaScript Variable&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;var currentValue='&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;';&amp;amp;lt;/script&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;script&amp;gt;someFunction('&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;');&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Ensure JavaScript variables are quoted&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Hex Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Unicode Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Avoid backslash encoding (\&amp;quot; or \' or \\)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| HTML&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;div&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED HTML&amp;lt;/span&amp;gt;&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Use_an_HTML_Policy_engine_to_validate_or_clean_user-driven_HTML_in_an_outbound_way HTML Validation (JSoup, AntiSamy, HTML Sanitizer)]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| DOM XSS&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;document.write(&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;quot;UNTRUSTED INPUT: &amp;quot; + document.location.hash&amp;lt;/span&amp;gt;);&amp;amp;lt;script/&amp;amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[[DOM based XSS Prevention Cheat Sheet]]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''''Safe HTML Attributes include:''''' align, alink, alt, bgcolor, border, cellpadding, cellspacing, class, color, cols, colspan, coords, dir, face, height, hspace, ismap, lang, marginheight, marginwidth, multiple, nohref, noresize, noshade, nowrap, ref, rel, rev, rows, rowspan, scrolling, shape, span, summary, tabindex, title, usemap, valign, value, vlink, vspace, width&lt;br /&gt;
&lt;br /&gt;
= Output Encoding Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The purpose of output encoding (as it relates to Cross Site Scripting) is to convert untrusted input into a safe form where the input is displayed as '''data''' to the user without executing as '''code''' in the browser. The following charts details a list of critical output encoding methods needed to stop Cross Site Scripting.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Encoding Type&lt;br /&gt;
! Encoding Mechanism&lt;br /&gt;
|-&lt;br /&gt;
| HTML Entity Encoding&lt;br /&gt;
|   Convert &amp;amp; to &amp;amp;amp;amp;&amp;lt;br/&amp;gt;Convert &amp;lt; to &amp;amp;amp;lt;&amp;lt;br/&amp;gt;Convert &amp;gt; to &amp;amp;amp;gt;&amp;lt;br/&amp;gt;Convert &amp;quot; to &amp;amp;amp;quot;&amp;lt;br/&amp;gt;Convert ' to &amp;amp;amp;#x27;&amp;lt;br/&amp;gt;Convert / to &amp;amp;amp;#x2F;&lt;br /&gt;
|-&lt;br /&gt;
| HTML Attribute Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the HTML Entity &amp;amp;amp;#xHH; format, including spaces. (HH = Hex Value)&lt;br /&gt;
|-&lt;br /&gt;
| URL Encoding&lt;br /&gt;
| Standard percent encoding, see: [http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp]&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the \uXXXX unicode escaping format (X = Integer).&lt;br /&gt;
|-&lt;br /&gt;
| CSS Hex Encoding&lt;br /&gt;
| CSS escaping supports \XX and \XXXXXX. Using a two character escape can cause problems if the next character continues the escape sequence. There are two solutions (a) Add a space after the CSS escape (will be ignored by the CSS parser) (b) use the full amount of CSS escaping possible by zero padding the value.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* [[XSS Experimental Minimal Encoding Rules]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Eoin Keary - eoin.keary[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:OWASP_Legal_Project&amp;diff=153920</id>
		<title>Category:OWASP Legal Project</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:OWASP_Legal_Project&amp;diff=153920"/>
				<updated>2013-06-17T02:55:12Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Home =&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;66%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
The goal of the '''OWASP Legal Project''' is to ensure, at each stage of the life cycle, that appropriate attention has been paid to security. The cornerstone of the Legal Project is its Secure Software Development Contract Annex. The Contract Annex  helps software developers and their clients negotiate and capture important contractual terms and conditions related to the security of the software to be developed or delivered. Here are two examples:&lt;br /&gt;
&lt;br /&gt;
* '''Implementation.''' Developer agrees to provide and follow a set of secure coding guidelines and to use a set of common security control programming interfaces (such as the [http://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API OWASP ESAPI]). Guidelines will indicate how code should be formatted, structured, and commented. Common security control programming interfaces will define how security controls must be called and how security controls shall function. All security-relevant code shall be thoroughly commented. Specific guidance on avoiding common security vulnerabilities shall be included. Also, all code shall be reviewed by at least one other Developer against the security requirements and coding guideline before it is considered ready for unit test.&lt;br /&gt;
&lt;br /&gt;
* '''Security Analysis and Testing.''' Developer will perform application security analysis and testing (also called &amp;quot;verification&amp;quot;) according to the verification requirements of an agreed-upon standard (such as the [http://www.owasp.org/index.php/ASVS OWASP ASVS]). The Developer shall document verification findings according to the reporting requirements of the standard. The Developer shall provide the verification findings to Client.&lt;br /&gt;
| &lt;br /&gt;
[[Image:Esapi-sponsors.PNG]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
== Let's talk here  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-bulb.jpg]]'''Legal Communities''' &lt;br /&gt;
&lt;br /&gt;
Further development of Legal Project documents occurs through mailing list discussions and occasional workshops, and suggestions for improvement are welcome. For more information, please [mailto:jeff.williams@owasp.org contact us]. &lt;br /&gt;
&lt;br /&gt;
*[https://lists.owasp.org/mailman/listinfo/owasp-legal owasp-legal mailing list (this is the main list)]&lt;br /&gt;
&lt;br /&gt;
| &lt;br /&gt;
== Got translation cycles?  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-writing.JPG]]'''Legal Project Translations''' &lt;br /&gt;
&lt;br /&gt;
The Legal Project project is always on the lookout for volunteers who are interested in translating Legal Project documents into another language. &lt;br /&gt;
&lt;br /&gt;
*Translation Onboarding Instructions -- Coming soon!&lt;br /&gt;
&lt;br /&gt;
| &lt;br /&gt;
== Related resources ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-satellite.jpg]]'''OWASP Resources''' &lt;br /&gt;
&lt;br /&gt;
* [[Top Ten|OWASP Top Ten]]&lt;br /&gt;
* [[ASVS|OWASP Application Security Verification Standard]]&lt;br /&gt;
* [[:Category:OWASP_Enterprise_Security_API|OWASP ESAPI]] &lt;br /&gt;
* [[:Category:OWASP_Newsletter#tab=Press_releases|OWASP Press Releases]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Downloads =&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
[[Image:Asvs-step1.jpg]]'''1. About Legal Project Documents''' &lt;br /&gt;
&lt;br /&gt;
* One Page Datasheet ([http://www.owasp.org/images/a/aa/Legal_One_Page_Handout.doc Word], [http://www.owasp.org/index.php/Image:Legal_One_Page_Handout.pdf PDF]) &lt;br /&gt;
* One Page Datasheet in Japanese ([https://www.owasp.org/index.php/File:Legal_One_Page_Handout-ja.pdf PDF])&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-step2.jpg]]'''2. Get Legal Project Documents''' &lt;br /&gt;
&lt;br /&gt;
* Contract Annex in English ([http://www.owasp.org/index.php/Image:OWASP_Secure_Software_Contract_Annex.doc Word], [http://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex HTML])&lt;br /&gt;
* Contract Annex in Spanish ([http://www.owasp.org/index.php/Anexo_para_Contrato_de_Software_Seguro_de_OWASP HTML])&lt;br /&gt;
* Contract Annex in Japanese ([https://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex/ja HTML])&lt;br /&gt;
* Contract Annex in French ([https://www.owasp.org/index.php/File:OWASP_Secure_Software_Contract_Annex-FR.doc Word])&lt;br /&gt;
* Verification schedule in English ([http://www.owasp.org/index.php/Image:Sample_ASVS_Fee_Schedule_Template.xls Excel])&lt;br /&gt;
&lt;br /&gt;
{{OWASP Book|4037498}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Project Details  =&lt;br /&gt;
{{:GPC_Project_Details/OWASP_Legal_Project | OWASP Project Identification Tab}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &amp;lt;headertabs /&amp;gt; ''This project licensed under the [http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons Attribution ShareAlike 3.0].'' &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Category:OWASP_Legal_Project&amp;diff=153919</id>
		<title>Category:OWASP Legal Project</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Category:OWASP_Legal_Project&amp;diff=153919"/>
				<updated>2013-06-17T02:45:59Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Home =&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;66%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
The goal of the '''OWASP Legal Project''' is to ensure, at each stage of the life cycle, that appropriate attention has been paid to security. The cornerstone of the Legal Project is its Secure Software Development Contract Annex. The Contract Annex  helps software developers and their clients negotiate and capture important contractual terms and conditions related to the security of the software to be developed or delivered. Here are two examples:&lt;br /&gt;
&lt;br /&gt;
* '''Implementation.''' Developer agrees to provide and follow a set of secure coding guidelines and to use a set of common security control programming interfaces (such as the [http://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API OWASP ESAPI]). Guidelines will indicate how code should be formatted, structured, and commented. Common security control programming interfaces will define how security controls must be called and how security controls shall function. All security-relevant code shall be thoroughly commented. Specific guidance on avoiding common security vulnerabilities shall be included. Also, all code shall be reviewed by at least one other Developer against the security requirements and coding guideline before it is considered ready for unit test.&lt;br /&gt;
&lt;br /&gt;
* '''Security Analysis and Testing.''' Developer will perform application security analysis and testing (also called &amp;quot;verification&amp;quot;) according to the verification requirements of an agreed-upon standard (such as the [http://www.owasp.org/index.php/ASVS OWASP ASVS]). The Developer shall document verification findings according to the reporting requirements of the standard. The Developer shall provide the verification findings to Client.&lt;br /&gt;
| &lt;br /&gt;
[[Image:Esapi-sponsors.PNG]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
== Let's talk here  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-bulb.jpg]]'''Legal Communities''' &lt;br /&gt;
&lt;br /&gt;
Further development of Legal Project documents occurs through mailing list discussions and occasional workshops, and suggestions for improvement are welcome. For more information, please [mailto:jeff.williams@owasp.org contact us]. &lt;br /&gt;
&lt;br /&gt;
*[https://lists.owasp.org/mailman/listinfo/owasp-legal owasp-legal mailing list (this is the main list)]&lt;br /&gt;
&lt;br /&gt;
| &lt;br /&gt;
== Got translation cycles?  ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-writing.JPG]]'''Legal Project Translations''' &lt;br /&gt;
&lt;br /&gt;
The Legal Project project is always on the lookout for volunteers who are interested in translating Legal Project documents into another language. &lt;br /&gt;
&lt;br /&gt;
*Translation Onboarding Instructions -- Coming soon!&lt;br /&gt;
&lt;br /&gt;
| &lt;br /&gt;
== Related resources ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-satellite.jpg]]'''OWASP Resources''' &lt;br /&gt;
&lt;br /&gt;
* [[Top Ten|OWASP Top Ten]]&lt;br /&gt;
* [[ASVS|OWASP Application Security Verification Standard]]&lt;br /&gt;
* [[:Category:OWASP_Enterprise_Security_API|OWASP ESAPI]] &lt;br /&gt;
* [[:Category:OWASP_Newsletter#tab=Press_releases|OWASP Press Releases]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Downloads =&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
[[Image:Asvs-step1.jpg]]'''1. About Legal Project Documents''' &lt;br /&gt;
&lt;br /&gt;
* One Page Datasheet ([http://www.owasp.org/images/a/aa/Legal_One_Page_Handout.doc Word], [http://www.owasp.org/index.php/Image:Legal_One_Page_Handout.pdf PDF]) &lt;br /&gt;
* One Page Datasheet in Japanese ([https://www.owasp.org/index.php/File:Legal_One_Page_Handout-ja.pdf PDF])&lt;br /&gt;
&lt;br /&gt;
[[Image:Asvs-step2.jpg]]'''2. Get Legal Project Documents''' &lt;br /&gt;
&lt;br /&gt;
* Contract Annex in English ([http://www.owasp.org/index.php/Image:OWASP_Secure_Software_Contract_Annex.doc Word], [http://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex HTML])&lt;br /&gt;
* Contract Annex in Spanish ([http://www.owasp.org/index.php/Anexo_para_Contrato_de_Software_Seguro_de_OWASP HTML])&lt;br /&gt;
* Contract Annex in Japanese ([https://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex/ja HTML])&lt;br /&gt;
* Contract Annex in French ([https://www.owasp.org/index.php/File:OWASP_Secure_Software_Contract_Annex-FR.doc HTML])&lt;br /&gt;
* Verification schedule in English ([http://www.owasp.org/index.php/Image:Sample_ASVS_Fee_Schedule_Template.xls Excel])&lt;br /&gt;
&lt;br /&gt;
{{OWASP Book|4037498}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Project Details  =&lt;br /&gt;
{{:GPC_Project_Details/OWASP_Legal_Project | OWASP Project Identification Tab}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &amp;lt;headertabs /&amp;gt; ''This project licensed under the [http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons Attribution ShareAlike 3.0].'' &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=File:OWASP_Secure_Software_Contract_Annex-FR.doc&amp;diff=153918</id>
		<title>File:OWASP Secure Software Contract Annex-FR.doc</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=File:OWASP_Secure_Software_Contract_Annex-FR.doc&amp;diff=153918"/>
				<updated>2013-06-17T02:44:13Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: French translation of OWASP SSCA&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;French translation of OWASP SSCA&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Unvalidated_Redirects_and_Forwards_Cheat_Sheet&amp;diff=152890</id>
		<title>Unvalidated Redirects and Forwards Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Unvalidated_Redirects_and_Forwards_Cheat_Sheet&amp;diff=152890"/>
				<updated>2013-06-04T18:10:41Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: /* Dangerous Forward Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
Unvalidated redirects and forwards are possible when a web application accepts untrusted input that could cause the web application to redirect the request to a URL contained within untrusted input. By modifying untrusted URL input to a malicious site, an attacker may successfully launch a phishing scam and steal user credentials. Because the server name in the modified link is identical to the original site, phishing attempts may have a more trustworthy appearance. Unvalidated redirect and forward attacks can also be used to maliciously craft a URL that would pass the application’s access control check and then forward the attacker to privileged functions that they would normally not be able to access.&lt;br /&gt;
&lt;br /&gt;
= Safe URL Redirects =&lt;br /&gt;
&lt;br /&gt;
When we want to redirect a user automatically to another page (without an action of the visitor such as clicking on a hyperlink) you might implement a code such as the following:&lt;br /&gt;
&lt;br /&gt;
PHP&lt;br /&gt;
  &amp;lt;?php&lt;br /&gt;
  /* Redirect browser */&lt;br /&gt;
  header(&amp;quot;Location: http&amp;amp;#58;//www.mysite.com/&amp;quot;);&lt;br /&gt;
  ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ASP.NET&lt;br /&gt;
   Response.Redirect(&amp;quot;~/folder/Login.aspx&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Rails&lt;br /&gt;
    redirect_to login_path&lt;br /&gt;
&lt;br /&gt;
In the examples above, the URL is being explicitly declared in the code and cannot be manipulated by an attacker.&lt;br /&gt;
&lt;br /&gt;
= Dangerous URL Redirects =&lt;br /&gt;
&lt;br /&gt;
The following examples demonstrate unsafe redirect and forward code.&lt;br /&gt;
&lt;br /&gt;
== Dangerous URL Redirect Example 1 ==&lt;br /&gt;
&lt;br /&gt;
The following PHP code obtains a URL from the query string and then redirects the user to that URL.&lt;br /&gt;
  &lt;br /&gt;
  $redirect_url = $_GET['url'];&lt;br /&gt;
  header(&amp;quot;Location: &amp;quot; . $redirect_url);&lt;br /&gt;
  &lt;br /&gt;
A similar example of C# .NET Vulnerable Code:&lt;br /&gt;
	&lt;br /&gt;
  string url = request.QueryString[&amp;quot;url&amp;quot;];&lt;br /&gt;
  Response.Redirect(url);&lt;br /&gt;
&lt;br /&gt;
And in rails:&lt;br /&gt;
   redirect_to params[:url]&lt;br /&gt;
&lt;br /&gt;
The above code is vulnerable to an attack if no validation or extra method controls are applied to verify the certainty of the URL. This vulnerability could be used as part of a phishing scam by redirecting users to a malicious site. If no validation is applied, a malicious user could create a hyperlink to redirect your users to an unvalidated malicious website, for example:&lt;br /&gt;
&lt;br /&gt;
  http&amp;amp;#58;//example.com/example.php?url=http&amp;amp;#58;//malicious.example.com&lt;br /&gt;
&lt;br /&gt;
The user sees the link directing to the original trusted site (example.com) and does not realize the redirection that could take place&lt;br /&gt;
&lt;br /&gt;
== Dangerous URL Redirect Example 2 ==&lt;br /&gt;
&lt;br /&gt;
ASP.NET MVC 1 &amp;amp; 2 websites are particularly vulnerable to open redirection attacks. In order to avoid this vulnerability, you need to apply MVC 3.&lt;br /&gt;
&lt;br /&gt;
The code for the LogOn action in an ASP.NET MVC 2 application is shown below. After a successful login, the controller returns a redirect to the returnUrl. You can see that no validation is being performed against the returnUrl parameter.&lt;br /&gt;
&lt;br /&gt;
Listing 1 – ASP.NET MVC 2 LogOn action in AccountController.cs&lt;br /&gt;
&lt;br /&gt;
  [HttpPost]&lt;br /&gt;
  public ActionResult LogOn(LogOnModel model, string returnUrl)&lt;br /&gt;
  {&lt;br /&gt;
    if (ModelState.IsValid)&lt;br /&gt;
    {&lt;br /&gt;
        if (MembershipService.ValidateUser(model.UserName, model.Password))&lt;br /&gt;
        {&lt;br /&gt;
            FormsService.SignIn(model.UserName, model.RememberMe);&lt;br /&gt;
            if (!String.IsNullOrEmpty(returnUrl))&lt;br /&gt;
            {&lt;br /&gt;
                return Redirect(returnUrl);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                return RedirectToAction(&amp;quot;Index&amp;quot;, &amp;quot;Home&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            ModelState.AddModelError(&amp;quot;&amp;quot;, &amp;quot;The user name or password provided is incorrect.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // If we got this far, something failed, redisplay form&lt;br /&gt;
    return View(model);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
== Dangerous Forward Example ==&lt;br /&gt;
&lt;br /&gt;
    FIXME: This example is wrong...it doesn't even call forward().&lt;br /&gt;
    The example should include (for example) a security-constraint in web.xml that prevents access to a URL.&lt;br /&gt;
    Then the forward to that URL from within the application will bypass the constraint.&lt;br /&gt;
&lt;br /&gt;
When applications allow user input to forward requests between different parts of the site, the application must check that the user is authorized to access the url, perform the functions it provides, and it is an appropriate url request. If the application fails to perform these checks, an attacker crafted URL may pass the application’s access control check and then forward the attacker to an administrative function that is not normally permitted.&lt;br /&gt;
&lt;br /&gt;
http&amp;amp;#58;//www.example.com/function.jsp?fwd=admin.jsp&lt;br /&gt;
&lt;br /&gt;
The following code is a Java servlet that will receive a GET request with a url parameter in the request to redirect the browser to the address specified in the url parameter. The servlet will retrieve the url parameter value from the request and send a response to redirect the browser to the url address.&lt;br /&gt;
&lt;br /&gt;
   public class RedirectServlet extends HttpServlet {&lt;br /&gt;
   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {&lt;br /&gt;
      String query = request.getQueryString();&lt;br /&gt;
      if (query.contains(&amp;quot;url&amp;quot;)) {&lt;br /&gt;
       String url = request.getParameter(&amp;quot;url&amp;quot;);&lt;br /&gt;
       response.sendRedirect(url);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
= Preventing Unvalidated Redirects and Forwards =&lt;br /&gt;
&lt;br /&gt;
Safe use of redirects and forwards can be done in a number of ways:&lt;br /&gt;
&lt;br /&gt;
* Simply avoid using redirects and forwards.&lt;br /&gt;
* If used, do not allow the url as user input for the destination. This can usually be done. In this case, you should have a method to validate URL. &lt;br /&gt;
* If user input can’t be avoided, ensure that the supplied &amp;lt;strong&amp;gt;value&amp;lt;/strong&amp;gt; is valid, appropriate for the application, and is &amp;lt;strong&amp;gt;authorized&amp;lt;/strong&amp;gt; for the user.&lt;br /&gt;
* It is recommended that any such destination input be mapped to a value, rather than the actual URL or portion of the URL, and that server side code translate this value to the target URL.&lt;br /&gt;
* Sanitize input by creating a list of trusted URL's (lists of hosts or a regex).&lt;br /&gt;
* Force all redirects to first go through a page notifying users that they are going off of your site, and have them click a link to confirm.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
# OWASP Article on Open Redirects https://www.owasp.org/index.php/Open_redirect&lt;br /&gt;
# CWE Entry 601 on Open Redirects http://cwe.mitre.org/data/definitions/601.html&lt;br /&gt;
# WASC Article on URL Redirector Abuse http://projects.webappsec.org/w/page/13246981/URL%20Redirector%20Abuse&lt;br /&gt;
# Google blog article on the dangers of open redirects http://googlewebmastercentral.blogspot.com/2009/01/open-redirect-urls-is-your-site-being.html&lt;br /&gt;
# Preventing Open Redirection Attacks (C#) http://www.asp.net/mvc/tutorials/security/preventing-open-redirection-attacks&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Susanna Bezold - susanna.bezold[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Johanna Curiel - johanna.curiel[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Clickjacking_Protection_for_Java_EE&amp;diff=142867</id>
		<title>Clickjacking Protection for Java EE</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Clickjacking_Protection_for_Java_EE&amp;diff=142867"/>
				<updated>2013-01-25T20:04:53Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
&lt;br /&gt;
Released Feb 6, 2009&lt;br /&gt;
&lt;br /&gt;
==How to Stop ClickJacking==&lt;br /&gt;
&lt;br /&gt;
This article shows how to prevent the IE8+ users of your Java EE application from getting clickjacked.&lt;br /&gt;
&lt;br /&gt;
[[Clickjacking]] is an attack that tricks users by showing them an innocuous page but including the real controls from sensitive pages. These controls are disguised through the use of background frames that mask off everything except the control, so that the user can't tell that they are actually clicking on a sensitive function in some other website.&lt;br /&gt;
&lt;br /&gt;
How can web applications protect their users from this attack?  The typical defense to clickjacking is to prevent your pages from being framed. The typical approach to this is to include a &amp;quot;framebreaker&amp;quot; script in every page that ensures that the content is not framed. Here's an example of such a script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;amp;lt;script&amp;gt;if (top != self) top.location=location&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 * NOTE: this framebreaker is pretty simple. A better framebreaker will hide the entire page&lt;br /&gt;
 and only redisplay if page is not being framed. An even better framebreaker than that will&lt;br /&gt;
 not cause any change in the page-load experience. More to come soon!&lt;br /&gt;
&lt;br /&gt;
However, there's an alternative approach that may be simpler to implement. Microsoft has now included a [http://blogs.msdn.com/ie/archive/2009/01/27/ie8-security-part-vii-clickjacking-defenses.aspx defense] in IE8 that allows developers to specify that pages should not be framed. They use a new (nonstandard) X-FRAME-OPTIONS header to mark responses that shouldn't be framed. There are two options with X-FRAME-OPTIONS. The first is DENY, which prevents everyone from framing the content. The other option is SAMEORIGIN, which only allows the current site to frame the content. Currently this works in IE8, Firefox, Safari, Opera and Chrome.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Approach==&lt;br /&gt;
&lt;br /&gt;
We'd like to add the X-FRAME-OPTIONS header to any pages that shouldn't be framed. So we could go into every servlet and JSP and add one of the two following lines of code:&lt;br /&gt;
&lt;br /&gt;
  // to prevent all framing of this content&lt;br /&gt;
  response.addHeader( &amp;quot;X-FRAME-OPTIONS&amp;quot;, &amp;quot;DENY&amp;quot; );&lt;br /&gt;
  &lt;br /&gt;
  // to allow framing of this content only by this site&lt;br /&gt;
  response.addHeader( &amp;quot;X-FRAME-OPTIONS&amp;quot;, &amp;quot;SAMEORIGIN&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
However, this seems a bit intrusive and a lot of work.  In this article, we'll implement a simple JavaEE filter to add the X-FRAME-OPTIONS header to some or all parts of your application.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
&lt;br /&gt;
The source code and the compiled class file are in a single zip file.&lt;br /&gt;
&lt;br /&gt;
'''[https://www.owasp.org/images/1/15/ClickjackFilter.zip DOWNLOAD]'''&lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
The first step is to add the filter to our application. All we have to do is put the ClickjackFilter class on our application's classpath, probably by putting it in the classes folder in WEB-INF. The class file should be in a folder structure that matches the package (org -&amp;gt; owasp -&amp;gt; filters -&amp;gt; ClickjackFilter).  You can extract the class file from the zip file.&lt;br /&gt;
&lt;br /&gt;
Then we just have to add the following filter definition and mapping to our web.xml. You should paste this in right above your servlet definitions. You should set up the mapping so it applies to '''any''' page that shouldn't be framed. Using /* will apply it to everything.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;web-app id=&amp;quot;WebApp_ID&amp;quot; version=&amp;quot;2.4&amp;quot;&lt;br /&gt;
    xmlns=&amp;quot;http://java.sun.com/xml/ns/j2ee&amp;quot;&lt;br /&gt;
    xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&lt;br /&gt;
    xsi:schemaLocation=&amp;quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;display-name&amp;gt;OWASP ClickjackFilter&amp;lt;/display-name&amp;gt;&lt;br /&gt;
    &amp;lt;filter&amp;gt;&lt;br /&gt;
        &amp;lt;filter-name&amp;gt;ClickjackFilterDeny&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
        &amp;lt;filter-class&amp;gt;org.owasp.filters.ClickjackFilter&amp;lt;/filter-class&amp;gt;&lt;br /&gt;
        &amp;lt;init-param&amp;gt;&lt;br /&gt;
            &amp;lt;param-name&amp;gt;mode&amp;lt;/param-name&amp;gt;&lt;br /&gt;
            &amp;lt;param-value&amp;gt;DENY&amp;lt;/param-value&amp;gt;&lt;br /&gt;
        &amp;lt;/init-param&amp;gt;&lt;br /&gt;
    &amp;lt;/filter&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;filter&amp;gt;&lt;br /&gt;
        &amp;lt;filter-name&amp;gt;ClickjackFilterSameOrigin&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
        &amp;lt;filter-class&amp;gt;org.owasp.filters.ClickjackFilter&amp;lt;/filter-class&amp;gt;&lt;br /&gt;
        &amp;lt;init-param&amp;gt;&lt;br /&gt;
            &amp;lt;param-name&amp;gt;mode&amp;lt;/param-name&amp;gt;&lt;br /&gt;
            &amp;lt;param-value&amp;gt;SAMEORIGIN&amp;lt;/param-value&amp;gt;&lt;br /&gt;
        &amp;lt;/init-param&amp;gt;&lt;br /&gt;
    &amp;lt;/filter&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;!--  use the Deny version to prevent anyone, including yourself, from framing the page --&amp;gt;&lt;br /&gt;
    &amp;lt;filter-mapping&amp;gt; &lt;br /&gt;
        &amp;lt;filter-name&amp;gt;ClickjackFilterDeny&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
        &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
    &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;!-- use the SameOrigin version to allow your application to frame, but nobody else&lt;br /&gt;
    &amp;lt;filter-mapping&amp;gt; &lt;br /&gt;
        &amp;lt;filter-name&amp;gt;ClickjackFilterSameOrigin&amp;lt;/filter-name&amp;gt;&lt;br /&gt;
        &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;
    &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt;
    --&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&amp;lt;/web-app&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Source Code==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 *  Software published by the Open Web Application Security Project (http://www.owasp.org)&lt;br /&gt;
 *  This software is licensed under the new BSD license.&lt;br /&gt;
 *&lt;br /&gt;
 * @author     Jeff Williams &amp;lt;a href=&amp;quot;http://www.aspectsecurity.com&amp;quot;&amp;gt;Aspect Security&amp;lt;/a&amp;gt;&lt;br /&gt;
 * @created    February 6, 2009&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
package org.owasp.filters;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
public class ClickjackFilter implements Filter &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
    private String mode = &amp;quot;DENY&amp;quot;;&lt;br /&gt;
    	&lt;br /&gt;
    /**&lt;br /&gt;
     * Add X-FRAME-OPTIONS response header to tell IE8 (and any other browsers who&lt;br /&gt;
     * decide to implement) not to display this content in a frame. For details, please&lt;br /&gt;
     * refer to http://blogs.msdn.com/sdl/archive/2009/02/05/clickjacking-defense-in-ie8.aspx.&lt;br /&gt;
     */&lt;br /&gt;
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {&lt;br /&gt;
        HttpServletResponse res = (HttpServletResponse)response;&lt;br /&gt;
        res.addHeader(&amp;quot;X-FRAME-OPTIONS&amp;quot;, mode );			&lt;br /&gt;
        chain.doFilter(request, response);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void destroy() {&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void init(FilterConfig filterConfig) {&lt;br /&gt;
        String configMode = filterConfig.getInitParameter(&amp;quot;mode&amp;quot;);&lt;br /&gt;
        if ( configMode != null ) {&lt;br /&gt;
            mode = configMode;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Compile==&lt;br /&gt;
&lt;br /&gt;
There are not many dependencies here, just the standard Java EE environment. You can compile with:&lt;br /&gt;
&lt;br /&gt;
  javac -classpath servlet-api.jar -d . *.java&lt;br /&gt;
&lt;br /&gt;
Then just copy the 'org' folder that gets created to the WEB-INF/classes folder in your application. You could also jar it up and put it in the lib directory.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
First, you'll need IE8 RC1+. I downloaded a free VHD of IE8 beta from [http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&amp;amp;displaylang=en Microsoft] and then did a Windows Update to IE8 RC1. You'll need to install the free [http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx VirtualPC] to run this.&lt;br /&gt;
&lt;br /&gt;
There's a very simple test case in the WebContent directory of the zip file. It has one page with the text &amp;quot;unframeable content&amp;quot; and another page that opens the first page in a frame. When you set the filter to DENY in web.xml, the page shows an error message that the content cannot be viewed in a frame.  When you set it to SAMEORIGIN, the content is allowed.&lt;br /&gt;
&lt;br /&gt;
You may want to check out the [http://evil.hackademix.net/frameopts/ demo] page that Giorgio Maone put together.&lt;br /&gt;
&lt;br /&gt;
[[Category:How To]]&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category:Countermeasure]]&lt;br /&gt;
[[Category: Control]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=135950</id>
		<title>Injection Theory</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=135950"/>
				<updated>2012-09-17T12:15:57Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Injection Flaws|Injection]] is an attack that attempts to invoke an interpreter or change the meaning of commands sent to an interpreter.  Frequently these interpreters run with a lot of access, so a successful attack can easily result in significant data breaches, or even loss of control of a browser, application, or server.&lt;br /&gt;
&lt;br /&gt;
=Why Injection Happens to Good Developers=&lt;br /&gt;
&lt;br /&gt;
Injection can be complex. The subtleties of data flow, parsers, contexts, capabilities, and escaping are overwhelming even for security specialists.  In the following sections we will outline these topics to make it clear how injection can happen in a variety of different technologies.&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
First we need to consider the vehicle for injection attacks -- untrusted data.&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, untrusted data is input that can be manipulated to contain a web attack payload. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
TBD: Data Flow&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection Context ==&lt;br /&gt;
&lt;br /&gt;
When untrusted data is used by an application, it is often inserted into a command, document, or other structure.  We will call this the '''injection context'''.  For example, consider a SQL statement constructed with &amp;quot;SELECT * FROM users WHERE name='&amp;quot; + request.getParameter( &amp;quot;name&amp;quot; ) + &amp;quot;'&amp;quot;;  In this example, the name is data from a potentially hostile user, and so could contain an attack.  But the attack is constrained by the injection context.  In this case, inside single quotes (').  That's why single quotes are so important for SQL injection.&lt;br /&gt;
&lt;br /&gt;
Consider a few of the types of commands and documents that might allow for injection...&lt;br /&gt;
* SQL queries&lt;br /&gt;
* LDAP queries&lt;br /&gt;
* Operating system command interpreters&lt;br /&gt;
* Any program invocation&lt;br /&gt;
* XML documents&lt;br /&gt;
* HTML documents&lt;br /&gt;
* JSON structures&lt;br /&gt;
* HTTP headers&lt;br /&gt;
* File paths&lt;br /&gt;
* URLs&lt;br /&gt;
* A variety of expresson languages&lt;br /&gt;
* etc...&lt;br /&gt;
&lt;br /&gt;
In all of these cases, if the attacker can &amp;quot;break out&amp;quot; of the intended injection context and modify the meaning of the command or document, they might be able to cause significant harm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Parsers ==&lt;br /&gt;
&lt;br /&gt;
TBD.  Describe different types of parsers, tokens (particularly control characters), BNF.&lt;br /&gt;
&lt;br /&gt;
== Injection into References ==&lt;br /&gt;
&lt;br /&gt;
TBD. This is for URLs, paths, and other simple forms.  Focus on the parser.  Could be as simple as Double.parseDouble (mark of the beast)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection into Commands ==&lt;br /&gt;
&lt;br /&gt;
TBD. Recursive descent or LALR parsers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injecting in Hierarchical Documents ==&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection with Multiple Nested Parsers ==&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=DEFENSES=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Validation ==&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
== Using Safe Interfaces ==&lt;br /&gt;
&lt;br /&gt;
TBD - parameterized interfaces with strong typing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
&lt;br /&gt;
[[User:Jeff Williams]] : jeff.williams[at]aspectsecurity.com&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=135937</id>
		<title>Injection Theory</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Injection_Theory&amp;diff=135937"/>
				<updated>2012-09-16T23:18:54Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Injection Flaws|Injection]] is an attack that attempts to invoke an interpreter or change the meaning of commands sent to an interpreter.  Frequently these interpreters run with a lot of access, so a successful attack can easily result in loss of control of a browser, application, or server.&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
First we need to consider the vehicle for injection attacks -- untrusted data.&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, untrusted data is input that can be manipulated to contain a web attack payload. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
== Injection Context ==&lt;br /&gt;
&lt;br /&gt;
When untrusted data is used by an application, it is often inserted into a command, document, or other structure.  We will call this the '''injection context'''.  For example, consider a SQL statement constructed with &amp;quot;SELECT * FROM users WHERE name='&amp;quot; + request.getParameter( &amp;quot;name&amp;quot; ) + &amp;quot;'&amp;quot;;  In this example, the name is data from a potentially hostile user, and so could contain an attack.  But the attack is constrained by the injection context.  In this case, inside single quotes (').  That's why single quotes are so important for SQL injection.&lt;br /&gt;
&lt;br /&gt;
Consider a few of the types of commands and documents that might allow for injection...&lt;br /&gt;
* SQL queries&lt;br /&gt;
* LDAP queries&lt;br /&gt;
* Operating system command interpreters&lt;br /&gt;
* Any program invocation&lt;br /&gt;
* XML documents&lt;br /&gt;
* HTML documents&lt;br /&gt;
* JSON structures&lt;br /&gt;
* HTTP headers&lt;br /&gt;
* File paths&lt;br /&gt;
* URLs&lt;br /&gt;
* A variety of expresson languages&lt;br /&gt;
* etc...&lt;br /&gt;
&lt;br /&gt;
In all of these cases, if the attacker can &amp;quot;break out&amp;quot; of the intended injection context and modify the meaning of the command or document, they might be able to cause significant harm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection into References ==&lt;br /&gt;
&lt;br /&gt;
TBD. This is for URLs, paths, and other simple forms.  Focus on the parser.  Could be as simple as Double.parseDouble (mark of the beast)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection into Commands ==&lt;br /&gt;
&lt;br /&gt;
TBD. Recursive descent or LALR parsers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injecting in Hierarchical Documents ==&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection with Multiple Parsers ==&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=DEFENSES=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Validation ==&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
== Using Safe Interfaces ==&lt;br /&gt;
&lt;br /&gt;
TBD - parameterized interfaces with strong typing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
&lt;br /&gt;
[[User:Jeff Williams]] : jeff.williams[at]aspectsecurity.com&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Rugged_Software&amp;diff=135075</id>
		<title>Rugged Software</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Rugged_Software&amp;diff=135075"/>
				<updated>2012-08-30T13:31:05Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: Replaced content with &amp;quot;Moved to http://ruggedsoftware.org&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Moved to http://ruggedsoftware.org&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=WebGoat_Installation&amp;diff=126794</id>
		<title>WebGoat Installation</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=WebGoat_Installation&amp;diff=126794"/>
				<updated>2012-03-24T02:40:53Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;webgoat/&amp;gt;[[WebGoat User Guide Table of Contents]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
WebGoat is a platform independent environment.&lt;br /&gt;
It utilizes Apache Tomcat and the JAVA development environment.&lt;br /&gt;
Installers are provided for Microsoft Windows and UN*X environments, together with notes for installation on other platforms.&lt;br /&gt;
&lt;br /&gt;
==Installing Java and Tomcat ==&lt;br /&gt;
'''Note''': This may no longer be necessary for v5.&lt;br /&gt;
&lt;br /&gt;
===Installing Java===&lt;br /&gt;
# Install and deploy the approprite version from http://java.sun.com/downloads/ (1.4.1 or later)&lt;br /&gt;
&lt;br /&gt;
===Installing Tomcat===&lt;br /&gt;
# Install and deploy core Tomcat from http://tomcat.apache.org/download-55.cgi&lt;br /&gt;
&lt;br /&gt;
  NOTE: WebGoat includes a very old version of catalina-4.1.9.jar.&lt;br /&gt;
  To run WebGoat on Tomcat 7, you'll need to expand the war file&lt;br /&gt;
  and delete this file from WEB-INF/lib&lt;br /&gt;
&lt;br /&gt;
==Installing to Windows ==&lt;br /&gt;
# Unzip WebGoat-OWASP_Standard-5.2.zip to your working environment.&lt;br /&gt;
# To start Tomcat, browse to the WebGoat directory unzipped above and double click &amp;quot;webgoat.bat&amp;quot;&lt;br /&gt;
# Start your browser and browse to: &amp;lt;u&amp;gt;http://localhost/WebGoat/attack&amp;lt;/u&amp;gt; This link is case-sensitive. Make sure to use a large ‘W’ and ‘G’.&lt;br /&gt;
&lt;br /&gt;
==Installing to Linux ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unzip WebGoat-OWASP_Standard-x.x.zip to your working directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Change &amp;quot;1.5&amp;quot; on lines 17, 19, and 23 of webgoat.sh to &amp;quot;1.6&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since the latest version runs on a privileged port, you will need to start/stop WebGoat &amp;amp; Tomcat either:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ol type=&amp;quot;a&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;on port 80 as root:&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo sh webgoat.sh start80&lt;br /&gt;
sudo sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;or on port 8080:&amp;lt;pre&amp;gt;&lt;br /&gt;
sh webgoat.sh start8080&lt;br /&gt;
sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing to OS X (Tiger 10.4+) ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unzip WebGoat-OWASP_Standard-x.x.zip to your working directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Change &amp;quot;1.5&amp;quot; on line 10 of webgoat.sh to &amp;quot;1.6&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since the latest version runs on a privileged port, you will need to start/stop WebGoat &amp;amp; Tomcat either:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ol type=&amp;quot;a&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;on port 80 as root:&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo sh webgoat.sh start80&lt;br /&gt;
sudo sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;or on port 8080:&amp;lt;pre&amp;gt;&lt;br /&gt;
sh webgoat.sh start8080&lt;br /&gt;
sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing on FreeBSD ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Tomcat and Java from the ports collection:&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /usr/ports/www/tomcat55&lt;br /&gt;
sudo make install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will be required to manually [http://www.FreeBSDFoundation.org/cgi-bin/download?download=diablo-caffe-freebsd6-i386-1.5.0_07-b01.tar.bz2 download the Java JDK] to install it.  Instructions are given by the ports system about when and how to do this.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unzip WebGoat-OWASP_Standard-x.x.zip to your working directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Change &amp;quot;1.5&amp;quot; on lines 17, 19, and 23 of webgoat.sh to &amp;quot;1.6&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since the latest version runs on a privileged port, you will need to start/stop WebGoat &amp;amp; Tomcat either:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ol type=&amp;quot;a&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;on port 80 as root:&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo sh webgoat.sh start80&lt;br /&gt;
sudo sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;or on port 8080:&amp;lt;pre&amp;gt;&lt;br /&gt;
sh webgoat.sh start8080&lt;br /&gt;
sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running ==&lt;br /&gt;
# Start your browser and browse to: &amp;lt;u&amp;gt;http://localhost/WebGoat/attack&amp;lt;/u&amp;gt;. Notice the capital 'W' and 'G'&lt;br /&gt;
&lt;br /&gt;
 Warning: The &amp;quot;WebGoat&amp;quot; part of the path (the &amp;quot;context root&amp;quot;) should exactly match (case-sensitive) the &lt;br /&gt;
 war (web archive) that gets deployed. When you launch WebGoat, the console will have a line like:&lt;br /&gt;
 &lt;br /&gt;
 INFO: Deploying web application archive webgoat.war&lt;br /&gt;
 &lt;br /&gt;
 This means that your URL will be &amp;lt;u&amp;gt;http://localhost/webgoat/attack&amp;lt;/u&amp;gt; -- note the lowercase &amp;quot;webgoat&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Login in as: user = guest, password = guest&lt;br /&gt;
&lt;br /&gt;
==Building ==&lt;br /&gt;
Skip these instructions if you are only interested in running WebGoat.&lt;br /&gt;
&lt;br /&gt;
WebGoat is built using eclipse WTP 1.5.x.  Please read the instructions at [http://webgoat.googlecode.com/svn/trunk/webgoat/README.txt Goodle code] to build the WebGoat application.&lt;br /&gt;
&lt;br /&gt;
==Installing WAR file to existing Tomcat server==&lt;br /&gt;
Place the .war file in your Tomcat webapps directory (it will self extract).  You'll need to resolve several issues that are outlined in the [http://code.google.com/p/webgoat/wiki/FAQ Webgoat FAQ].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Return to the [[WebGoat User Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP WebGoat Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=126389</id>
		<title>User:Jeff Williams</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Jeff_Williams&amp;diff=126389"/>
				<updated>2012-03-16T05:25:47Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm Jeff Williams, I work as CEO of [http://www.aspectsecurity.com Aspect] [https://www.aspectsecurity.com Security] and I served as the volunteer Chair of the OWASP Foundation from 2003 to 2012. I’ve dedicated my life to trying to make the world’s software more secure, and so I create lots of free and open tools, libraries, guidance, and standards to try to change the status quo. Thank you all for your dedication to application security and your participation in OWASP. Please send any questions or comments to me via email at [mailto:jeff.williams@aspectsecurity.com jeff.williams@aspectsecurity.com]. Or you can twitter @planetlevel.&lt;br /&gt;
&lt;br /&gt;
last revised {{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}&lt;br /&gt;
&lt;br /&gt;
Some of my work (in roughly reverse chronological order)&lt;br /&gt;
* Enterprise Java Rootkits - http://www.aspectsecurity.com/documents/EnterpriseJavaRootkits.zip&lt;br /&gt;
* XSS-Proofing Your JavaEE, JSP, and JSP Applications - http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-4374&amp;amp;yr=2009&amp;amp;track=javaee &lt;br /&gt;
   I'm an official [http://java.sun.com/javaone/2009/rockstars.jsp Java Rock Star]!&lt;br /&gt;
* XSS Prevention Cheatsheet – http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&lt;br /&gt;
* Java EE ClickJack Filter - http://www.owasp.org/index.php/ClickjackFilter_for_Java_EE &lt;br /&gt;
* Enterprise Security API – http://www.owasp.org/index.php/ESAPI &lt;br /&gt;
* Application Security Verification Standard - http://www.owasp.org/index.php/ASVS &lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java PDF Attack Filter - http://www.owasp.org/index.php/PDF_Attack_Filter_for_Java_EE &lt;br /&gt;
* Application Security Risk Rating Model - http://www.owasp.org/index.php/OWASP_Risk_Rating_Methodology &lt;br /&gt;
* CSRF Tester Tool - http://www.owasp.org/index.php/Category:OWASP_CSRFTester_Project &lt;br /&gt;
* CSRF Guard -  http://www.owasp.org/index.php/CSRF_Guard&lt;br /&gt;
* How to Write Insecure Code - http://www.owasp.org/index.php/How_to_write_insecure_code&lt;br /&gt;
* Java Stinger Validation Library - http://www.owasp.org/index.php/Category:OWASP_Stinger_Project &lt;br /&gt;
* Application Security Contract Annex - http://www.owasp.org/index.php/OWASP_Secure_Software_Contract_Annex &lt;br /&gt;
* OWASP Chapters Program - http://www.owasp.org/index.php/Category:OWASP_Chapter &lt;br /&gt;
* OWASP Foundation - http://www.owasp.org/index.php/OWASP_Foundation &lt;br /&gt;
* OWASP Top Ten – http://www.owasp.org/index.php/Topten &lt;br /&gt;
* WebGoat Application Security Learning Environment - http://www.owasp.org/index.php/Webgoat &lt;br /&gt;
* Systems Security Engineering CMM - http://sse-cmm.org/index.html &lt;br /&gt;
&lt;br /&gt;
To see my wiki contributions, [[:Special:Contributions/Jeff Williams|click here]].&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
My background, from an [http://myappsecurity.blogspot.com/2007/03/reflection-on-jeff-williams.html interview]&lt;br /&gt;
&lt;br /&gt;
I set out to be a user interface guy, but I got into security accidentally. I was working at TRW in 1992 on the user interface for a big Navy system that just happened to be highly secure – targeting B2 in the Orange Book. I took on an R&amp;amp;D project to port the user interface to the new compartmented mode workstation (what became Trusted Solaris) and I found that I really liked the challenge of securing such a complex system.&lt;br /&gt;
&lt;br /&gt;
Then Java 1.0 came along and I got NIST and NRL funding to do security research. At the time, we thought the Java sandbox was a good idea, but that there were attacks that might bypass it. So I wrote a special classloader that modified the bytecode to wrap security relevant method calls with a reference monitor. After that I spent several years developing a Java-based multilevel secure network guard on Trusted Solaris. That guard handled HTTP, FTP, TDS, and a number of other protocols – sort of a very early application firewall. But unlike the modern WAFs, we took a whitelist approach where you would define exactly the data formats and rules for allowing messages.&lt;br /&gt;
&lt;br /&gt;
In the mid-90’s, I chaired the group that authored the SSE-CMM, which is now ISO 21827. As it turns out, the processes involved in systems security engineering are quite similar to those necessary for secure software development. I’m very glad to see that the idea of assurance arguments from my work is starting to be used in the application security world.&lt;br /&gt;
&lt;br /&gt;
Then in 1998, while I was the technical director of the Global Security Practice at Exodus Communications, a Fortune 10 company approached us and said “We’d like to host our applications with you, but we have this rule – every line of code has to be reviewed before it goes on the Internet.” So I started an application security practice and started providing application assessments, developer training, and help with security requirements and architecture. We built a successful practice securing some of the biggest and most complex web applications in the world.&lt;br /&gt;
&lt;br /&gt;
In April 2002, together with Dave Wichers, Noelle Hardy, and some other great folks, I started Aspect Security to focus exclusively on application security. I just feel so fortunate to get to work with such an amazing group of consultants and customers. I’m having the most fun of my professional career.&lt;br /&gt;
&lt;br /&gt;
I first heard of OWASP in 2001 from Chuck Pfleeger (the author of Security in Computing). The idea of a free and open community for application security was an interesting idea. At the time, getting companies to focus on application security was difficult. In meetings with several government agencies, they acknowledged that it was an issue, but that they were managing to the SANS Top 20. I came home and literally in the shower said to myself, “I wish we had an application security top ten…” So a small team of us at Aspect took the lead in drafting the first OWASP Top Ten.&lt;br /&gt;
&lt;br /&gt;
Later, Aspect donated WebGoat, a hands-on training environment for application security issues that we had developed for our courses. A huge number of organizations, including Google, use WebGoat today to teach their developers about application security. We started to see that participation in OWASP allowed Aspect to demonstrate our skills in a very constructive way, and many of our customers have contacted us after seeing our participation in OWASP.&lt;br /&gt;
&lt;br /&gt;
I was honored to take over the leadership of OWASP in 2003. At that time, we had a number of great contributors, but OWASP itself was just a domain name and a few small projects. So I got us set up as a 501c3 nonprofit organization and put a management structure in place. I want the OWASP Foundation to provide a free, open, supportive community infrastructure for application security projects. We’re making the barriers to entry for contribution so low that security experts will be motivated to make the effort and share their expertise.&lt;br /&gt;
&lt;br /&gt;
One of the key challenges has been to ensure that OWASP is not influenced by commercial interests. When I set up the AppSec conference and local chapter rules, I made sure that vendors are cannot use OWASP to market their products. We’re also starting to ferret out abuse of the OWASP brand by companies that claim their products “address the OWASP Top Ten” or enable “OWASP Compliance.” The local chapters have been growing very quickly and starting to contribute back to the mothership. Our conferences have also been a great experience.&lt;br /&gt;
&lt;br /&gt;
I think the switch to the MediaWiki platform in 2006 was a major step for OWASP. Prior to that, contributing content was a difficult and painful process. Now, anyone can create an account and contribute easily. We have a team set up to review all the contributions and the number of abuses in our first year has been astoundingly low (less than 10 incidents). We’re to the point now where we get dozens of articles and contributions every day. I don’t see how a non-open approach to building an application security body of knowledge can possibly keep up with our productivity.&lt;br /&gt;
&lt;br /&gt;
We’re still a long way from the point where a company can go to OWASP for everything they need in order to build, acquire, and operate secure applications… but we’ve got an incredible process and we’re working very hard to get there.&lt;br /&gt;
&lt;br /&gt;
I have big family and absolutely love my kids. We live in the woods and spend a lot of time outside with our two Labrador retrievers. I’m very much into sports – I rowed on the crew team at UVA and still play basketball three times a week (if you meet me you'll know why). For a while I was into extreme rollerblading and then I got into mountain bike trials – I broke a lot of equipment, but never had any serious injuries :)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Articles / Presentations==&lt;br /&gt;
&lt;br /&gt;
Opening the Black Box: A Source Code Security Analysis Case Study&lt;br /&gt;
http://www.aspectsecurity.com/documents/Aspect_Opening_Black_Box.doc&lt;br /&gt;
&lt;br /&gt;
Application Security Initiatives - The Best Defense Is a Good Offense&lt;br /&gt;
http://www.aspectsecurity.com/documents/Application_Security_Initiatives.htm&lt;br /&gt;
&lt;br /&gt;
Let's Sue the Idiots -- Security, Software, Contracts, and Lawyers&lt;br /&gt;
http://www.aspectsecurity.com/article/sscl.htm&lt;br /&gt;
&lt;br /&gt;
How to Build an HTTP Request Validation Engine for Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/bld_HTTP_req_val_engine.htm&lt;br /&gt;
&lt;br /&gt;
Access Control (aka Authorization) in Your J2EE Application&lt;br /&gt;
http://www.aspectsecurity.com/article/access_control.htm&lt;br /&gt;
&lt;br /&gt;
Trustworthy Java - Are your apps bulletproof?&lt;br /&gt;
http://www.aspectsecurity.com/article/trust_java.htm&lt;br /&gt;
&lt;br /&gt;
The Ten Most Critical Web Application Security Vulnerabilities&lt;br /&gt;
http://www.aspectsecurity.com/owasp.htm&lt;br /&gt;
&lt;br /&gt;
Security Code Review - the Best Way to Eliminate Vulnerabilities in Software&amp;quot; -&lt;br /&gt;
http://www.aspectsecurity.com/documents/AspectCodeReviewWhitePaper.pdf&lt;br /&gt;
&lt;br /&gt;
Can a 'Social Protocol' Help Protect Privacy?&lt;br /&gt;
http://www.aspectsecurity.com/documents/p3p.pdf&lt;br /&gt;
&lt;br /&gt;
Jini and Mobile Agent Security - Proceedings of the Workshop on Agent Technologies (AT ‘98)&lt;br /&gt;
http://www.aspectsecurity.com/documents/jini.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Improving and Communicating Assurance - Proceedings of the 10th Canadian Information Technology Security Symposium (CITSS)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Arguing.pdf&lt;br /&gt;
&lt;br /&gt;
A Practical Approach to Measuring Assurance - Proceedings of the 1998 Security Applications Conference (ACSAC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Measuring.pdf&lt;br /&gt;
&lt;br /&gt;
System Security Engineering Capability Maturity Model (SSE-CMM) version 2.0 - Released at the 21st Annual National Information System Security Conference (NISSC)&lt;br /&gt;
http://www.aspectsecurity.com/documents/SSECMMv2Final.pdf&lt;br /&gt;
&lt;br /&gt;
Just Sick about Security - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Sick.pdf&lt;br /&gt;
&lt;br /&gt;
An Enterprise Assurance Framework - Proceedings of the 5th Workshop on Enabling Technologies&lt;br /&gt;
http://www.aspectsecurity.com/documents/WetIce.pdf&lt;br /&gt;
&lt;br /&gt;
Pretty Good Assurance - Proceedings of the New Security Paradigms Workshop&lt;br /&gt;
http://www.aspectsecurity.com/documents/Pretty.pdf&lt;br /&gt;
&lt;br /&gt;
Need for a Framework for Reasoning about Assurance - Proceedings of the International Workshop on IT Assurance and Trustworthiness (WITAT)&lt;br /&gt;
http://www.aspectsecurity.com/documents/Need.pdf&lt;br /&gt;
&lt;br /&gt;
Assurance is an N-Space (Where N is Hopefully Small) - Proceedings of the International Invitational Workshop on Developmental Assurance&lt;br /&gt;
http://www.aspectsecurity.com/documents/Nspace.pdf&lt;br /&gt;
&lt;br /&gt;
A Capability Maturity Model For Security Engineering - Proceedings of the 6th Annual Canadian Computer Security Symposium&lt;br /&gt;
http://www.aspectsecurity.com/documents/CITSS94.doc&lt;br /&gt;
&lt;br /&gt;
Unsafe at Any (CPU) Speed: Why We Keep Making the Same Mistakes - NSA High Confidence Software and Systems Conference&lt;br /&gt;
&lt;br /&gt;
Web Applications: The “Last Mile” of Internet Security&lt;br /&gt;
&lt;br /&gt;
A Constructionist Approach to Law and Society - Law and Society Seminar, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
Interpreting Anticircumvention (DMCA) - Advanced International Copyright Law, Georgetown University Law Center&lt;br /&gt;
&lt;br /&gt;
P3I – Protection Profile Process Improvement - Proceedings of the 22nd National Information System Security Conference (NISSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Security - 17th Annual National Computer Security Conference (NCSC)&lt;br /&gt;
&lt;br /&gt;
Windows NT Client Security and Windows NTAS Security - The Local Area Network Security Conference (LANSEC)&lt;br /&gt;
&lt;br /&gt;
Reusing Existing C3I Systems in a Secure Environment - Proceedings of the Application of COTS and Reusable Components Conference&lt;br /&gt;
&lt;br /&gt;
A Framework for Reasoning about Assurance - Published by the National Computer Security Center of the NSA&lt;br /&gt;
Proceedings of the 11th Annual Conference on Computer Assurance (COMPASS)&lt;br /&gt;
&lt;br /&gt;
Interconnecting MLS Command Centers - White paper for the Multilevel Security Initiative at Hanscomb AFB&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Education==&lt;br /&gt;
&lt;br /&gt;
* JD cum laude – Georgetown Law - Cyberlaw and Intellectual Property&lt;br /&gt;
* MA – George Mason - Human Factors Engineering&lt;br /&gt;
* BA – University of Virginia - Cognitive Psychology and Computer Science (Specialization in AI)&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_AppSec_DC_2012/The_Unfortunate_Reality_of_Insecure_Libraries&amp;diff=126147</id>
		<title>OWASP AppSec DC 2012/The Unfortunate Reality of Insecure Libraries</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_AppSec_DC_2012/The_Unfortunate_Reality_of_Insecure_Libraries&amp;diff=126147"/>
				<updated>2012-03-12T20:54:15Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;{{:OWASP AppSec DC 2012 Header}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
== The Presentation  ==&lt;br /&gt;
Many organizations have started application security programs to focus on finding and subsequently preventing vulnerabilities in their custom code. However, the widespread use of common libraries introduces risks that are widely ignored and unappreciated. In this study, we analyze over 113 million library downloads from the Maven Central repository of the 31 most popular Java frameworks and security libraries by over 60,000 companies. The data show that there are a surprising amount of libraries with known vulnerabilities in common use.  The data reveal some very interesting facts about our use of libraries, and we conclude that most organizations do not appear to have a strong process in place for ensuring that the libraries they rely on are up-to-date and free from known vulnerabilities.&lt;br /&gt;
== The Speakers  ==&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
===Arshan Dabirsiaghi===&lt;br /&gt;
[[Image:Owasp_logo_normal.jpg|left]]Bio TBA&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
===Jeff Williams===&lt;br /&gt;
[[Image:Owasp_logo_normal.jpg|left]]Bio TBA&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{:OWASP AppSec DC 2012 Footer}}&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=124880</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=124880"/>
				<updated>2012-02-23T01:33:24Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. The use of an escaping/encoding library like the one in [[ESAPI]] or the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] is strongly recommended as there are many special cases. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the excellent [http://ha.ckers.org/xss.html XSS Cheat Sheet] by RSnake. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, untrusted data is input that can be manipulated to contain a web attack payload. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
== Injection Theory ==&lt;br /&gt;
&lt;br /&gt;
[[Injection Flaws|Injection]] is an attack that involves breaking out of a data context and switching into a code context through the use of special characters that are significant in the interpreter being used. A data context is like &amp;amp;lt;div&amp;gt;data context&amp;lt;/div&amp;gt;. If the attacker's data gets placed into the data context, they might break out like this &amp;amp;lt;div&amp;gt;data &amp;amp;lt; script&amp;gt;alert(&amp;quot;attack&amp;quot;)&amp;lt;/script&amp;gt; context&amp;lt;/div&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library in a variety of languages including Java, PHP, Classic ASP, Cold Fusion, Python, and Haskell. Microsoft provides an encoding library named the [http://www.microsoft.com/download/en/details.aspx?id=325 Microsoft Anti-Cross Site Scripting Library] for the .NET platform.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; is not recommended&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
=Related Articles=&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
Jim Manico - jim[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=WebGoat_Installation&amp;diff=121408</id>
		<title>WebGoat Installation</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=WebGoat_Installation&amp;diff=121408"/>
				<updated>2011-12-13T00:27:38Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;webgoat/&amp;gt;[[WebGoat User Guide Table of Contents]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
WebGoat is a platform independent environment.&lt;br /&gt;
It utilizes Apache Tomcat and the JAVA development environment.&lt;br /&gt;
Installers are provided for Microsoft Windows and UN*X environments, together with notes for installation on other platforms.&lt;br /&gt;
&lt;br /&gt;
==Installing Java and Tomcat ==&lt;br /&gt;
'''Note''': This may no longer be necessary for v5.&lt;br /&gt;
&lt;br /&gt;
===Installing Java===&lt;br /&gt;
# Install and deploy the approprite version from http://java.sun.com/downloads/ (1.4.1 or later)&lt;br /&gt;
&lt;br /&gt;
===Installing Tomcat===&lt;br /&gt;
# Install and deploy core Tomcat from http://tomcat.apache.org/download-55.cgi&lt;br /&gt;
&lt;br /&gt;
==Installing to Windows ==&lt;br /&gt;
# Unzip WebGoat-OWASP_Standard-5.2.zip to your working environment.&lt;br /&gt;
# To start Tomcat, browse to the WebGoat directory unzipped above and double click &amp;quot;webgoat.bat&amp;quot;&lt;br /&gt;
# Start your browser and browse to: &amp;lt;u&amp;gt;http://localhost/WebGoat/attack&amp;lt;/u&amp;gt; This link is case-sensitive. Make sure to use a large ‘W’ and ‘G’.&lt;br /&gt;
&lt;br /&gt;
==Installing to Linux ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unzip WebGoat-OWASP_Standard-x.x.zip to your working directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Change &amp;quot;1.5&amp;quot; on lines 17, 19, and 23 of webgoat.sh to &amp;quot;1.6&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since the latest version runs on a privileged port, you will need to start/stop WebGoat &amp;amp; Tomcat either:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ol type=&amp;quot;a&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;on port 80 as root:&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo sh webgoat.sh start80&lt;br /&gt;
sudo sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;or on port 8080:&amp;lt;pre&amp;gt;&lt;br /&gt;
sh webgoat.sh start8080&lt;br /&gt;
sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing to OS X (Tiger 10.4+) ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unzip WebGoat-OWASP_Standard-x.x.zip to your working directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Change &amp;quot;1.5&amp;quot; on line 10 of webgoat.sh to &amp;quot;1.6&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since the latest version runs on a privileged port, you will need to start/stop WebGoat &amp;amp; Tomcat either:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ol type=&amp;quot;a&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;on port 80 as root:&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo sh webgoat.sh start80&lt;br /&gt;
sudo sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;or on port 8080:&amp;lt;pre&amp;gt;&lt;br /&gt;
sh webgoat.sh start8080&lt;br /&gt;
sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing on FreeBSD ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Install Tomcat and Java from the ports collection:&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /usr/ports/www/tomcat55&lt;br /&gt;
sudo make install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will be required to manually [http://www.FreeBSDFoundation.org/cgi-bin/download?download=diablo-caffe-freebsd6-i386-1.5.0_07-b01.tar.bz2 download the Java JDK] to install it.  Instructions are given by the ports system about when and how to do this.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unzip WebGoat-OWASP_Standard-x.x.zip to your working directory.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Change &amp;quot;1.5&amp;quot; on lines 17, 19, and 23 of webgoat.sh to &amp;quot;1.6&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Since the latest version runs on a privileged port, you will need to start/stop WebGoat &amp;amp; Tomcat either:&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ol type=&amp;quot;a&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;on port 80 as root:&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo sh webgoat.sh start80&lt;br /&gt;
sudo sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;or on port 8080:&amp;lt;pre&amp;gt;&lt;br /&gt;
sh webgoat.sh start8080&lt;br /&gt;
sh webgoat.sh stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Running ==&lt;br /&gt;
# Start your browser and browse to: &amp;lt;u&amp;gt;http://localhost/WebGoat/attack&amp;lt;/u&amp;gt;. Notice the capital 'W' and 'G'&lt;br /&gt;
&lt;br /&gt;
 Warning: The &amp;quot;WebGoat&amp;quot; part of the path (the &amp;quot;context root&amp;quot;) should exactly match (case-sensitive) the &lt;br /&gt;
 war (web archive) that gets deployed. When you launch WebGoat, the console will have a line like:&lt;br /&gt;
 &lt;br /&gt;
 INFO: Deploying web application archive webgoat.war&lt;br /&gt;
 &lt;br /&gt;
 This means that your URL will be &amp;lt;u&amp;gt;http://localhost/webgoat/attack&amp;lt;/u&amp;gt; -- note the lowercase &amp;quot;webgoat&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Login in as: user = guest, password = guest&lt;br /&gt;
&lt;br /&gt;
==Building ==&lt;br /&gt;
Skip these instructions if you are only interested in running WebGoat.&lt;br /&gt;
&lt;br /&gt;
WebGoat is built using eclipse WTP 1.5.x.  Please read the instructions at [http://webgoat.googlecode.com/svn/trunk/webgoat/README.txt Goodle code] to build the WebGoat application.&lt;br /&gt;
&lt;br /&gt;
==Installing WAR file to existing Tomcat server==&lt;br /&gt;
Place the .war file in your Tomcat webapps directory (it will self extract).  You'll need to resolve several issues that are outlined in the [http://code.google.com/p/webgoat/wiki/FAQ Webgoat FAQ].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Return to the [[WebGoat User Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP WebGoat Project]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119938</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119938"/>
				<updated>2011-11-09T15:13:20Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
These rules apply to all the different varieties of XSS. Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate escaping on the server-side. The use of an escaping/encoding library like the one in [[ESAPI]] is strongly recommended as there are many special cases. [[DOM Based XSS]] can be addressed by applying these rules on the client on untrusted data.&lt;br /&gt;
&lt;br /&gt;
For a great cheatsheet on the attack vectors related to XSS, please refer to the excellent [http://ha.ckers.org/xss.html XSS Cheat Sheet] by RSnake. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, it might not have been perfectly validated. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection Theory ==&lt;br /&gt;
&lt;br /&gt;
[[Injection Flaws|Injection]] is an attack that involves breaking out of a data context and switching into a code context through the use of special characters that are significant in the interpreter being used. A data context is like &amp;amp;lt;div&amp;gt;data context&amp;lt;/div&amp;gt;. If the attacker's data gets placed into the data context, they might break out like this &amp;amp;lt;div&amp;gt;data &amp;amp;lt; script&amp;gt;alert(&amp;quot;attack&amp;quot;)&amp;lt;/script&amp;gt; context&amp;lt;/div&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library in a variety of languages including Java, .NET, PHP, Classic ASP, Cold Fusion, Python, and Haskell. The ESAPI library can be used for escaping as described here and also for decoding (aka canonicalization), which is critical for input validation.  Microsoft provides an encoding library named [http://www.codeplex.com/AntiXSS AntiXSS].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;apos; is not recommended&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM_based_XSS_Prevention_Cheat_Sheet]].&lt;br /&gt;
&lt;br /&gt;
'''Encoding Information'''&lt;br /&gt;
[http://code.google.com/p/owasp-development-guide/wiki/WebAppSecDesignGuide_D6 OWASP Development Guide]&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
=Related Articles=&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
Jim Manico - jim[at]manico.net &lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119937</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119937"/>
				<updated>2011-11-09T15:00:39Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
These rules apply to all the different varieties of XSS. Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate escaping on the server-side. The use of an escaping/encoding library like the one in [[ESAPI]] is strongly recommended as there are many special cases. [[DOM Based XSS]] can be addressed by applying these rules on the client on untrusted data.&lt;br /&gt;
&lt;br /&gt;
For a great cheatsheet on the attack vectors related to XSS, please refer to the excellent [http://ha.ckers.org/xss.html XSS Cheat Sheet] by RSnake. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, it might not have been perfectly validated. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection Theory ==&lt;br /&gt;
&lt;br /&gt;
[[Injection Flaws|Injection]] is an attack that involves breaking out of a data context and switching into a code context through the use of special characters that are significant in the interpreter being used. A data context is like &amp;amp;lt;div&amp;gt;data context&amp;lt;/div&amp;gt;. If the attacker's data gets placed into the data context, they might break out like this &amp;amp;lt;div&amp;gt;data &amp;amp;lt; script&amp;gt;alert(&amp;quot;attack&amp;quot;)&amp;lt;/script&amp;gt; context&amp;lt;/div&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library in a variety of languages including Java, .NET, PHP, Classic ASP, Cold Fusion, Python, and Haskell. The ESAPI library can be used for escaping as described here and also for decoding (aka canonicalization), which is critical for input validation.  Microsoft provides an encoding library named [http://www.codeplex.com/AntiXSS AntiXSS].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;apos; is not recommended&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
= OWASP AntiSamy =&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
= OWASP Java HTML Sanitizer =&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM_based_XSS_Prevention_Cheat_Sheet]].&lt;br /&gt;
&lt;br /&gt;
= Encoding Information =&lt;br /&gt;
[http://code.google.com/p/owasp-development-guide/wiki/WebAppSecDesignGuide_D6 OWASP Development Guide]&lt;br /&gt;
&lt;br /&gt;
= Additional XSS Defense (HTTPOnly cookie flag)=&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.&lt;br /&gt;
&lt;br /&gt;
For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
=Related Articles=&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
Jim Manico - jim[at]manico.net &lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119936</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119936"/>
				<updated>2011-11-09T14:51:44Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: /* RULE #3 - JavaScript Escape Before Inserting Untrusted Data into HTML JavaScript Data Values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
These rules apply to all the different varieties of XSS. Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate escaping on the server-side. The use of an escaping/encoding library like the one in [[ESAPI]] is strongly recommended as there are many special cases. [[DOM Based XSS]] can be addressed by applying these rules on the client on untrusted data.&lt;br /&gt;
&lt;br /&gt;
For a great cheatsheet on the attack vectors related to XSS, please refer to the excellent [http://ha.ckers.org/xss.html XSS Cheat Sheet] by RSnake. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, it might not have been perfectly validated. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection Theory ==&lt;br /&gt;
&lt;br /&gt;
[[Injection Flaws|Injection]] is an attack that involves breaking out of a data context and switching into a code context through the use of special characters that are significant in the interpreter being used. A data context is like &amp;amp;lt;div&amp;gt;data context&amp;lt;/div&amp;gt;. If the attacker's data gets placed into the data context, they might break out like this &amp;amp;lt;div&amp;gt;data &amp;amp;lt; script&amp;gt;alert(&amp;quot;attack&amp;quot;)&amp;lt;/script&amp;gt; context&amp;lt;/div&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library in a variety of languages including Java, .NET, PHP, Classic ASP, Cold Fusion, Python, and Haskell. The ESAPI library can be used for escaping as described here and also for decoding (aka canonicalization), which is critical for input validation.  Microsoft provides an encoding library named [http://www.codeplex.com/AntiXSS AntiXSS].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;apos; is not recommended&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. Do not use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. Prevent switching out of the property value and into another property or attribute. Also prevent switching into an expression or other property value that allows scripting. If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
= OWASP AntiSamy =&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
= OWASP Java HTML Sanitizer =&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM_based_XSS_Prevention_Cheat_Sheet]].&lt;br /&gt;
&lt;br /&gt;
= Encoding Information =&lt;br /&gt;
[http://code.google.com/p/owasp-development-guide/wiki/WebAppSecDesignGuide_D6 OWASP Development Guide]&lt;br /&gt;
&lt;br /&gt;
= Additional XSS Defense (HTTPOnly cookie flag)=&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.&lt;br /&gt;
&lt;br /&gt;
For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
=Related Articles=&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
Jim Manico - jim[at]manico.net &lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119935</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=119935"/>
				<updated>2011-11-09T14:48:59Z</updated>
		
		<summary type="html">&lt;p&gt;Jeff Williams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
These rules apply to all the different varieties of XSS. Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate escaping on the server-side. The use of an escaping/encoding library like the one in [[ESAPI]] is strongly recommended as there are many special cases. [[DOM Based XSS]] can be addressed by applying these rules on the client on untrusted data.&lt;br /&gt;
&lt;br /&gt;
For a great cheatsheet on the attack vectors related to XSS, please refer to the excellent [http://ha.ckers.org/xss.html XSS Cheat Sheet] by RSnake. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Untrusted Data ==&lt;br /&gt;
&lt;br /&gt;
Untrusted data is most often data that comes from the HTTP request, in the form of URL parameters, form fields, headers, or cookies. But data that comes from databases, web services, and other sources is frequently untrusted from a security perspective.  That is, it might not have been perfectly validated. The [[Searching for Code in J2EE/Java|OWASP Code Review Guide]] has a decent list of methods that return untrusted data in various languages, but you should be careful about your own methods as well.&lt;br /&gt;
&lt;br /&gt;
Untrusted data should always be treated as though it contains an attack. That means you should not send it '''anywhere''' without taking steps to make sure that any attacks are detected and neutralized. As applications get more and more interconnected, the likelihood of a buried attack being decoded or executed by a downstream interpreter increases rapidly.&lt;br /&gt;
&lt;br /&gt;
Traditionally, [[Data Validation|input validation]] has been the preferred approach for handling untrusted data. However, input validation is not a great solution for injection attacks. First, input validation is typically done when the data is received, before the destination is known. That means that we don't know which characters might be significant in the target interpreter.  Second, and possibly even more importantly, applications must allow potentially harmful characters in. For example, should poor Mr. O'Malley be prevented from registering in the database simply because SQL considers ' a special character?&lt;br /&gt;
&lt;br /&gt;
While input validation is important and should always be performed, it is not a complete solution for injection attacks. It's better to think of input validation as [[Defense in depth|defense in depth]] and use '''escaping''' as described below as the primary defense.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Escaping (aka Output Encoding) ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;[http://www.w3.org/TR/charmod/#sec-Escaping Escaping]&amp;quot; is a technique used to ensure that characters are treated as data, not as characters that are relevant to the interpreter's parser. There are lots of different types of escaping, sometimes confusingly called output &amp;quot;encoding.&amp;quot;  Some of these techniques define a special &amp;quot;escape&amp;quot; character, and other techniques have a more sophisticated syntax that involves several characters.&lt;br /&gt;
&lt;br /&gt;
Do not confuse output escaping with the notion of Unicode character [http://www.w3.org/TR/charmod/#sec-Digital encoding], which involves mapping a Unicode character to a sequence of bits. This level of encoding is automatically decoded, and does '''not''' defuse attacks. However, if there are misunderstandings about the intended charset between the server and browser, it may cause unintended characters to be communicated, possibly enabling XSS attacks. This is why it is still important to [http://www.w3.org/TR/charmod/#sec-Encodings specify] the Unicode character encoding (charset), such as UTF-8, for all communications.&lt;br /&gt;
&lt;br /&gt;
Escaping is the primary means to make sure that untrusted data can't be used to convey an injection attack. There is '''no harm''' in escaping data properly - it will still render in the browser properly. Escaping simply lets the interpreter know that the data is not intended to be executed, and therefore prevents attacks from working.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Injection Theory ==&lt;br /&gt;
&lt;br /&gt;
[[Injection Flaws|Injection]] is an attack that involves breaking out of a data context and switching into a code context through the use of special characters that are significant in the interpreter being used. A data context is like &amp;amp;lt;div&amp;gt;data context&amp;lt;/div&amp;gt;. If the attacker's data gets placed into the data context, they might break out like this &amp;amp;lt;div&amp;gt;data &amp;amp;lt; script&amp;gt;alert(&amp;quot;attack&amp;quot;)&amp;lt;/script&amp;gt; context&amp;lt;/div&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
XSS is a form of injection where the interpreter is the browser and attacks are buried in an HTML document. HTML is easily the worst mashup of code and data of all time, as there are so many possible places to put code and so many different valid encodings. HTML is particularly difficult because it is not only hierarchical, but also contains many different parsers (XML, HTML, JavaScript, VBScript, CSS, URL, etc...).&lt;br /&gt;
&lt;br /&gt;
To really understand what's going on with XSS, you have to consider injection into the hierarchical structure of the [http://www.w3schools.com/HTMLDOM/default.asp HTML DOM]. Given a place to insert data into an HTML document (that is, a place where a developer has allowed untrusted data to be included in the DOM), there are two ways to inject code:&lt;br /&gt;
&lt;br /&gt;
;Injecting UP:The most common way is to close the current context and start a new code context.  For example, this is what you do when you close an HTML attribute with a &amp;quot;&amp;gt; and start a new &amp;amp;lt;script&amp;gt; tag. This attack closes the original context (going up in the hierarchy) and then starts a new tag that will allow script code to execute. Remember that you may be able to skip many layers up in the hierarchy when trying to break out of your current context. For example, a &amp;amp;lt;/script&amp;gt; tag may be able to terminate a script block even if it is injected inside a quoted string inside a method call inside the script. This happens because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
;Injecting DOWN:The less common way to perform XSS injection is to introduce a code subcontext without closing the current context. For example, if the attacker is able to change &amp;amp;lt;img src=&amp;quot;...UNTRUSTED DATA HERE...&amp;quot; /&amp;gt; into &amp;amp;lt; img src=&amp;quot;javascript:alert(document.cookie)&amp;quot; /&amp;gt; they do not have to break out of the HTML attribute context.  Instead, they introduce a subcontext that allows scripting within the src attribute (in this case a javascript url). Another example is the expression() functionality in CSS properties. Even though you may not be able to escape a quoted CSS property to inject up, you may be able to introduce something like xss:expression(document.write(document.cookie)) without ever leaving the current context.&lt;br /&gt;
&lt;br /&gt;
There's also the possibility of injecting directly in the current context. For example, if you take untrusted input and put it directly into a JavaScript context. While insane, accepting code from an attacker is more common than you might think in modern applications. Generally it is impossible to secure untrusted code with escaping (or anything else). If you do this, your application is just a conduit for attacker code to get running in your users' browsers.&lt;br /&gt;
&lt;br /&gt;
The rules in this document have been designed to prevent both UP and DOWN varieties of XSS injection. To prevent injecting up, you must escape the characters that would allow you to close the current context and start a new one. To prevent attacks that jump up several levels in the DOM hierarchy, you must also escape all the characters that are significant in all enclosing contexts.  To prevent injecting down, you must escape any characters that can be used to introduce a new sub-context within the current context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library in a variety of languages including Java, .NET, PHP, Classic ASP, Cold Fusion, Python, and Haskell. The ESAPI library can be used for escaping as described here and also for decoding (aka canonicalization), which is critical for input validation.  Microsoft provides an encoding library named [http://www.codeplex.com/AntiXSS AntiXSS].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;apos; is not recommended&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into HTML JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns the JavaScript event handlers that are specified on various HTML elements. The only safe place to put untrusted data into these event handlers as a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other javascript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. Do not use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. Prevent switching out of the property value and into another property or attribute. Also prevent switching into an expression or other property value that allows scripting. If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
= OWASP AntiSamy =&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
= OWASP Java HTML Sanitizer =&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM_based_XSS_Prevention_Cheat_Sheet]].&lt;br /&gt;
&lt;br /&gt;
= Encoding Information =&lt;br /&gt;
[http://code.google.com/p/owasp-development-guide/wiki/WebAppSecDesignGuide_D6 OWASP Development Guide]&lt;br /&gt;
&lt;br /&gt;
= Additional XSS Defense (HTTPOnly cookie flag)=&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.&lt;br /&gt;
&lt;br /&gt;
For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
=Related Articles=&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&lt;br /&gt;
&lt;br /&gt;
Jim Manico - jim[at]manico.net &lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Jeff Williams</name></author>	</entry>

	</feed>