This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Difference between revisions of "Abridged XSS Prevention Cheat Sheet"

From OWASP
Jump to: navigation, search
m
 
Line 1: Line 1:
= <b>Experimental</b> Minimal Encoding Rules =
+
#redirect [[XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet]]
 
 
The following examples demonstrate experimental minimal encoding rules for XSS prevention.
 
 
 
{| class="wikitable nowraplinks"
 
|-
 
! Context
 
! Code Sample
 
! Rules
 
|-
 
| JavaScript, quoted string in a script block
 
| &lt;script>alert("Hello "+"&lt;%= <span style="color:red;">UNTRUSTED DATA</span> %>");&lt;/script>
 
| <ul><li>Use these escapes: \\ \r \n \b \t \f \' \" \/</li><li>For any other character in range 0..0x19, use hex escapes</li><li>If using non-Unicode charset, any character above 0x7e, use '\u' encoding</li></ul>
 
|-
 
| JavaScript, quoted string in an event handler attribute
 
| onclick="alert('<%= <span style="color:red;">UNTRUSTED DATA</span> %>')";
 
| <ul><li>Use these escapes: \\ \r \n \b \t \f</li><li>Use hex escapes for these characters: ' " &</li><li>For any other character in range 0..0x19, use hex escapes</li><li>If using non-Unicode charset, any character above 0x7e, use '\u' encoding</li></ul>
 
|-
 
| HTML Body (up to HTML 4.01):
 
| &lt;div><%= <span style="color:red;">UNTRUSTED DATA</span> %>&lt;/div>
 
| <ul><li>HTML Entity encode &lt; &amp;</li><li>specify charset in metatag to avoid UTF7 XSS</li></ul>
 
|-
 
| <b>X</b>HTML Body:
 
| &lt;div><%= <span style="color:red;">UNTRUSTED DATA</span> %>&lt;/div>
 
| <ul><li>HTML Entity encode &lt; &amp; &gt;</li><li>limit input to charset http://www.w3.org/TR/2008/REC-xml-20081126/#charsets</li></ul>
 
|-
 
|}
 

Latest revision as of 17:48, 16 September 2012