{"id":761,"date":"2013-08-30T14:48:15","date_gmt":"2013-08-30T13:48:15","guid":{"rendered":"http:\/\/www.floyd.ch\/?p=761"},"modified":"2023-05-31T08:12:35","modified_gmt":"2023-05-31T07:12:35","slug":"owasp-antisamy-project-xss","status":"publish","type":"post","link":"https:\/\/www.floyd.ch\/?p=761","title":{"rendered":"OWASP AntiSamy Project XSS"},"content":{"rendered":"<p>From the <a target=\"_blank\" href=\"https:\/\/wiki.owasp.org\/index.php\/Category:OWASP_AntiSamy_Project\" rel=\"noopener\">OWASP AntiSamy Project page&#8217;s<\/a> &#8220;What is it&#8221; section:<\/p>\n<blockquote><p>\nIt&#8217;s an API that helps you make sure that clients don&#8217;t supply malicious cargo code in the HTML they supply for their profile, comments, etc., that get persisted on the server. The term &#8220;malicious code&#8221; in regards to web applications usually mean &#8220;JavaScript.&#8221; Cascading Stylesheets are only considered malicious when they invoke the JavaScript engine. However, there are many situations where &#8220;normal&#8221; HTML and CSS can be used in a malicious manner. So we take care of that too.\n<\/p><\/blockquote>\n<p>So as far as I understand it, it is trying to prevent Cross Site Scripting (XSS). But to be fair, the user guide is a little bit more realistic:<\/p>\n<blockquote><p>\nAntiSamy does a very good job of removing malicious HTML, CSS and JavaScript, but in security, no solution is guaranteed. AntiSamy\u2019s success depends on the strictness of your policy file and the predictability of browsers\u2019 behavior. AntiSamy is a sanitization framework; it is up to the user how it does its sanitization. Using AntiSamy does not guarantee filtering of all malicious code. AntiSamy simply does what is described by the policy file.\n<\/p><\/blockquote>\n<p>Anyway, I found a XSS that worked in the case of the web application I was testing:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;a href=&quot;http:\/\/example.com&quot;&amp;\/onclick=alert(8)&gt;foo&lt;\/a&gt;\r\n<\/pre>\n<p>Version: antisamy-1.5.2.jar with all default configuration files there are.<\/p>\n<p>Browsers tested (all working): Firefox 22.0 (on Mac OSX), Safari 6.0.5 (on Mac OSX), Internet Explorer 11.0.9200 (Windows 7) and Android Browser (Android 2.2).<\/p>\n<p>Disclosure timeline:<br \/>\nJuly 16th, 2013: Wrote to Arshan (maintainer) about the issue<br \/>\nJuly 16th, 2013: Response, questions about version and browser compatiblity<br \/>\nJuly 16th, 2013: Clarification about versions\/browser and that I only tried getNumberOfErrors(), informed that I&#8217;m planning to release this blog post end of August<br \/>\nJuly 23rd, 2013: Some more E-Mails about similar issue that was just resolved (not the same issue), including Kristian who comitted a fix<br \/>\nJuly 25th, 2013: Kristian sent a mail, he will have a look at the getNumberOfErrors() logic before releasing an update<br \/>\nJuly 31st, 2013: Asked if there are any updates on the issue, no response<br \/>\nSept 09th, 2013: Asked if there are any updates on the issue, response that it should be fixed. Requested new .jar file<br \/>\nOct 21st, 2013: Tested with the newest version available for download, antisamy 1.5.3. Problem still present. Public release.<\/p>\n<p>Antisamy doesn&#8217;t give any error messages and getNumberOfErrors() is 0. Although the getCleanHTML() will give back sanitised code without the XSS, people relying only on the getNumberOfErrors() method to check if an input is valid or not will have a XSS.<\/p>\n<p>Btw. the included configuration file names are somehow misleading (the names include company names like ebay). Those names are made up, doesn&#8217;t mean the companies use those conifg files at all. I don&#8217;t even know if they are using the antisamy project at all.<\/p>\n<p>I can&#8217;t recommend relying on that project. Proper <a href=\"https:\/\/cheatsheetseries.owasp.org\/cheatsheets\/Cross_Site_Scripting_Prevention_Cheat_Sheet.html\" target=\"_blank\" rel=\"noopener\">output encoding<\/a> is important and is the real XSS prevention. And <a href=\"https:\/\/stackoverflow.com\/questions\/1732348\/regex-match-open-tags-except-xhtml-self-contained-tags\/1732454#1732454\" target=\"_blank\" rel=\"noopener\">validating HTML with regex is hard<\/a>. Very hard. Very, very hard. Don&#8217;t.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From the OWASP AntiSamy Project page&#8217;s &#8220;What is it&#8221; section: It&#8217;s an API that helps you make sure that clients don&#8217;t supply malicious cargo code in the HTML they supply for their profile, comments, etc., that get persisted on the &hellip; <a href=\"https:\/\/www.floyd.ch\/?p=761\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,39],"tags":[120,121,80,123,69,122,124,159],"class_list":["post-761","post","type-post","status-publish","format-standard","hentry","category-web-penetration-testing","category-xss","tag-antisamy","tag-html-parsing","tag-java","tag-javascript","tag-owasp","tag-regex","tag-sanitising","tag-xss"],"_links":{"self":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=761"}],"version-history":[{"count":20,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":1362,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions\/1362"}],"wp:attachment":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}