<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Bypassing OWASP ESAPI XSS Protection inside Javascript</title>
	<atom:link href="http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/</link>
	<description>Inferno&#039;s Blog on Application Security</description>
	<lastBuildDate>Fri, 02 Apr 2010 17:28:55 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: arshan</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-217</link>
		<dc:creator>arshan</dc:creator>
		<pubDate>Fri, 21 Aug 2009 17:12:18 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-217</guid>
		<description>of course i actually understood what you were saying, i was just calling you out on having a sensationalist title</description>
		<content:encoded><![CDATA[<p>of course i actually understood what you were saying, i was just calling you out on having a sensationalist title</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mcv</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-216</link>
		<dc:creator>mcv</dc:creator>
		<pubDate>Fri, 21 Aug 2009 07:00:21 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-216</guid>
		<description>Hi again,

Of course json_encode is meant to create code for JS, it does not escape for HTML, so you&#039;re right — document.write attack will work. I meant only to use json_encode instead of threating everything like strings and putting it inside &quot;&quot;.

And to prevent this attack additional HTML escaping is needed there, or XML-&gt;JSON-&gt;again-XML escaping if document is XML, or XML-&gt;JSON-&gt;CDATA escaping if script is enclosed into CDATA section. Holy God… But again, document.write does not work in XHTML (but one day one browser might support it out of the blue). And all this is the reason why I prefer to use javascript_tag method which automatically decides what escaping should be done for js code for current document type. ;-)

As for eval, since it&#039;s embedding JS code inside JS string, I&#039;d use double json_encode and concat two JS strings, NOT embed one into another:

eval(&quot;u=&quot; + );

Attack should not work then. If you add + &quot;; alert(u)&quot; at the end you will notice that whole &quot;0,x setter=alert,x=2&quot; has been assigned to variable u.

The truth is that programmer should be aware of what language in what another language is he embedding.

Regards.</description>
		<content:encoded><![CDATA[<p>Hi again,</p>
<p>Of course json_encode is meant to create code for JS, it does not escape for HTML, so you&#8217;re right — document.write attack will work. I meant only to use json_encode instead of threating everything like strings and putting it inside &#8220;&#8221;.</p>
<p>And to prevent this attack additional HTML escaping is needed there, or XML-&gt;JSON-&gt;again-XML escaping if document is XML, or XML-&gt;JSON-&gt;CDATA escaping if script is enclosed into CDATA section. Holy God… But again, document.write does not work in XHTML (but one day one browser might support it out of the blue). And all this is the reason why I prefer to use javascript_tag method which automatically decides what escaping should be done for js code for current document type. <img src='http://securethoughts.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>As for eval, since it&#8217;s embedding JS code inside JS string, I&#8217;d use double json_encode and concat two JS strings, NOT embed one into another:</p>
<p>eval(&#8220;u=&#8221; + );</p>
<p>Attack should not work then. If you add + &#8220;; alert(u)&#8221; at the end you will notice that whole &#8220;0,x setter=alert,x=2&#8243; has been assigned to variable u.</p>
<p>The truth is that programmer should be aware of what language in what another language is he embedding.</p>
<p>Regards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Inferno</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-215</link>
		<dc:creator>Inferno</dc:creator>
		<pubDate>Fri, 21 Aug 2009 01:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-215</guid>
		<description>mcv, you asked a question whether it is a good idea to use json_encode or not. i tried on my latest php 5.3 install and don&#039;t think it will provide any protection.

Json_encode uses unicode escapes which is bypassable inside document.write and eval, just like hex escapes for encodeForJavaScript.
e.x. if i use json_encode($str,JSON_HEX_TAG&#124;JSON_HEX_APOS&#124;JSON_HEX_QUOT&#124;JSON_HEX_AMP) inside document.write where malicious $str=&quot;&lt;img src=x:x onerror=alert(1)&gt;&quot;, 
Then i get this - document.write(&quot;\u003Cimg src=x:x onerror=alert(1)\u003E&quot;) on my client and XSS still executes.</description>
		<content:encoded><![CDATA[<p>mcv, you asked a question whether it is a good idea to use json_encode or not. i tried on my latest php 5.3 install and don&#8217;t think it will provide any protection.</p>
<p>Json_encode uses unicode escapes which is bypassable inside document.write and eval, just like hex escapes for encodeForJavaScript.<br />
e.x. if i use json_encode($str,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP) inside document.write where malicious $str=&#8221;<img src=x:x onerror=alert(1)/>&#8220;,<br />
Then i get this &#8211; document.write(&#8220;\u003Cimg src=x:x onerror=alert(1)\u003E&#8221;) on my client and XSS still executes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Inferno</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-214</link>
		<dc:creator>Inferno</dc:creator>
		<pubDate>Thu, 20 Aug 2009 20:10:51 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-214</guid>
		<description>Hi Arshan,

Thanks for your feedback. I can understand your confusion. What i meant to convey was esapi protection function encodeForJavaScript does not protect against all cases of javascript injection. The title essentially says that you can bypass the xss protection if you use this function for scrubbing. But, this is not a vulnerability of this function and no code fix can prevent this. It is required that people either use the correct function or don&#039;t put insecure code there at all. If you need more clarity, lets discuss this over email. 

For the low-paid programmer, i don&#039;t think he or she will even know what xss is, no point in talking about security anyways there. My main concern was for people who know XSS and have sometime seen and used the xss prevention cheat sheet. Once Jeff fixes the defense recommendation on that page, those people will have a better idea of use the esapi correctly and securely.</description>
		<content:encoded><![CDATA[<p>Hi Arshan,</p>
<p>Thanks for your feedback. I can understand your confusion. What i meant to convey was esapi protection function encodeForJavaScript does not protect against all cases of javascript injection. The title essentially says that you can bypass the xss protection if you use this function for scrubbing. But, this is not a vulnerability of this function and no code fix can prevent this. It is required that people either use the correct function or don&#8217;t put insecure code there at all. If you need more clarity, lets discuss this over email. </p>
<p>For the low-paid programmer, i don&#8217;t think he or she will even know what xss is, no point in talking about security anyways there. My main concern was for people who know XSS and have sometime seen and used the xss prevention cheat sheet. Once Jeff fixes the defense recommendation on that page, those people will have a better idea of use the esapi correctly and securely.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Inferno</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-213</link>
		<dc:creator>Inferno</dc:creator>
		<pubDate>Thu, 20 Aug 2009 19:57:15 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-213</guid>
		<description>hi mcv,

i corrected your original comments, since some of it inside &lt; and &gt; was getting stripped. i will see what i can do to fix my commenting engine.</description>
		<content:encoded><![CDATA[<p>hi mcv,</p>
<p>i corrected your original comments, since some of it inside &lt; and &gt; was getting stripped. i will see what i can do to fix my commenting engine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bypassing OWASP ESAPI XSS Protection inside Javascript &#8230;</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-212</link>
		<dc:creator>Bypassing OWASP ESAPI XSS Protection inside Javascript &#8230;</dc:creator>
		<pubDate>Thu, 20 Aug 2009 19:43:11 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-212</guid>
		<description>[...] here to read the rest:  Bypassing OWASP ESAPI XSS Protection inside Javascript &#8230;   SHARETHIS.addEntry({ title: &quot;Bypassing OWASP ESAPI XSS Protection inside Javascript &#8230;&quot;, [...]</description>
		<content:encoded><![CDATA[<p>[...] here to read the rest:  Bypassing OWASP ESAPI XSS Protection inside Javascript &#8230;   SHARETHIS.addEntry({ title: &quot;Bypassing OWASP ESAPI XSS Protection inside Javascript &#8230;&quot;, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mcv</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-211</link>
		<dc:creator>mcv</dc:creator>
		<pubDate>Thu, 20 Aug 2009 19:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-211</guid>
		<description>Since commenting system on this blog does not work properly (isn&#039;t now the time to use proper escaping instead of eating „dangerous” words? ;^)), i put my original comment here: http://mcv.mulabs.org/comment-0.txt</description>
		<content:encoded><![CDATA[<p>Since commenting system on this blog does not work properly (isn&#8217;t now the time to use proper escaping instead of eating „dangerous” words? ;^)), i put my original comment here: <a href="http://mcv.mulabs.org/comment-0.txt" rel="nofollow">http://mcv.mulabs.org/comment-0.txt</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mcv</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-210</link>
		<dc:creator>mcv</dc:creator>
		<pubDate>Thu, 20 Aug 2009 19:03:09 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-210</guid>
		<description>I think it&#039;s good idea to use json_encode/to_json functions for this, like:

var a = &lt;%= user_data.to_json %&gt;; // Note absence of quotes

Also you don&#039;t have to deal with data types, because json encoder checks for user_data type and yields string, integers, floats, etc. accordingly. Do you see any flaws in this approach?

BTW it is worth mentioning that those who use mixed HTML/XHTML and famous //&lt;![CDATA[ //]]&gt; snippets should
also &#039;escape-for-cdata&#039;, that is replace &quot;]]&gt;&quot; with &quot;]]&gt;]]&gt;&lt;![CDATA[&quot; to prevent ]]&gt; injection. Of course only when document is served as XHTML, not HTML. I use some guerilla patching of &quot;javascript_tag&quot; method in my Rails applications to make it automatic. ;-)</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s good idea to use json_encode/to_json functions for this, like:</p>
<p>var a = &lt;%= user_data.to_json %&gt;; // Note absence of quotes</p>
<p>Also you don&#8217;t have to deal with data types, because json encoder checks for user_data type and yields string, integers, floats, etc. accordingly. Do you see any flaws in this approach?</p>
<p>BTW it is worth mentioning that those who use mixed HTML/XHTML and famous //&lt;![CDATA[ //]]&gt; snippets should<br />
also &#8216;escape-for-cdata&#8217;, that is replace &quot;]]&gt;&quot; with &quot;]]&gt;]]&amp;gt;&lt;![CDATA[&quot; to prevent ]]&gt; injection. Of course only when document is served as XHTML, not HTML. I use some guerilla patching of &quot;javascript_tag&quot; method in my Rails applications to make it automatic. <img src='http://securethoughts.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: arshan</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-209</link>
		<dc:creator>arshan</dc:creator>
		<pubDate>Thu, 20 Aug 2009 17:04:37 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-209</guid>
		<description>I&#039;m trying to resolve the statement &quot;I agree that no esapi code change is required, because function themselves are not insecure&quot; with the title of the post &quot;bypassing owasp esapi xss protections&quot;

Besides that, good post. Example #2 shows HTML-within-JS-within-HTML; can anyone explain to me how a low-paid programmer (probably outsourced?) is ever going to care enough about his job to do this right?</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to resolve the statement &#8220;I agree that no esapi code change is required, because function themselves are not insecure&#8221; with the title of the post &#8220;bypassing owasp esapi xss protections&#8221;</p>
<p>Besides that, good post. Example #2 shows HTML-within-JS-within-HTML; can anyone explain to me how a low-paid programmer (probably outsourced?) is ever going to care enough about his job to do this right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Williams</title>
		<link>http://securethoughts.com/2009/08/bypassing-owasp-esapi-xss-protection-inside-javascript/comment-page-1/#comment-208</link>
		<dc:creator>Jeff Williams</dc:creator>
		<pubDate>Thu, 20 Aug 2009 14:59:37 +0000</pubDate>
		<guid isPermaLink="false">http://securethoughts.com/?p=722#comment-208</guid>
		<description>Thanks for this research!  Developers - please be very careful when putting user input into a JavaScript context (script block or event handler).  What you&#039;re doing is very dangerous and difficult to get right, even with strong JavaScript escaping.  You&#039;re basically asking the user for *code* and then running it.  I do see this very frequently in applications, which is one reason we&#039;re going to be fighting XSS for a very long time.</description>
		<content:encoded><![CDATA[<p>Thanks for this research!  Developers &#8211; please be very careful when putting user input into a JavaScript context (script block or event handler).  What you&#8217;re doing is very dangerous and difficult to get right, even with strong JavaScript escaping.  You&#8217;re basically asking the user for *code* and then running it.  I do see this very frequently in applications, which is one reason we&#8217;re going to be fighting XSS for a very long time.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
