<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - XSS and when h just ain't enough.]]></title>
		<link>http://railsforum.com/viewtopic.php?id=677</link>
		<description><![CDATA[The most recent posts in XSS and when h just ain't enough..]]></description>
		<lastBuildDate>Thu, 09 Jun 2011 21:45:45 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=141078#p141078</link>
			<description><![CDATA[<p>Thanks for the tips, there&#039;s more here than I would have hoped to find. I was mainly concerned about the security features so I found a <a href="http://cloudsecurity.trendmicro.com/">cloud security</a> resource that is supposed to cover all the information we need.</p>]]></description>
			<author><![CDATA[dummy@example.com (reggiss)]]></author>
			<pubDate>Thu, 09 Jun 2011 21:45:45 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=141078#p141078</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=88294#p88294</link>
			<description><![CDATA[<p>We use xss_terminate to sanitize user input (even from admins), and instead users can use Textile handled by RedCloth to to do some styling of any input.</p>]]></description>
			<author><![CDATA[dummy@example.com (Johnson)]]></author>
			<pubDate>Thu, 19 Feb 2009 16:22:52 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=88294#p88294</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=88291#p88291</link>
			<description><![CDATA[<div class="quotebox"><cite>marcin.urbanski wrote:</cite><blockquote><p>... further updates causes some recursion:</p><p><pre name="code" class="ruby:nogutter">&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;<br />&amp;amp;lt;script&amp;amp;gt;&amp;amp;lt;/script&amp;amp;gt;<br />&amp;amp;amp;lt;script&amp;amp;amp;gt;&amp;amp;amp;lt;/script&amp;amp;amp;gt;</pre></p></blockquote></div><p>Can you do a simple replace where <pre name="code" class="ruby:nogutter">&amp;amp;</pre><br />is replaced with <pre name="code" class="ruby:nogutter">&amp;</pre><br />wherever its found?</p><p>I&#039;m kinda new to this, so if this raises a security issue, please point it out...</p>]]></description>
			<author><![CDATA[dummy@example.com (petiepooo)]]></author>
			<pubDate>Thu, 19 Feb 2009 16:01:40 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=88291#p88291</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=77260#p77260</link>
			<description><![CDATA[<div class="quotebox"><cite>reyntjensw wrote:</cite><blockquote><p>Is this article still up to date? Or does rails has now built-in security for xss?</p></blockquote></div><p>Rails now has a little bit more security than it used to do. You can read more at <a href="http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html">http://api.rubyonrails.org/classes/Acti &#133; thods.html</a></p>]]></description>
			<author><![CDATA[dummy@example.com (standout)]]></author>
			<pubDate>Thu, 09 Oct 2008 16:08:53 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=77260#p77260</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=77255#p77255</link>
			<description><![CDATA[<p><pre name="code" class="ruby:nogutter">class XssInputObserver &lt; ActiveRecord::Observer<br />&nbsp; observe Employee, Employer</p><p>&nbsp; def before_save(model)<br />&nbsp; &nbsp; model.attribute_names.each do |attrib|<br />&nbsp; &nbsp; &nbsp; model[attrib] = CGI::escapeHTML(model[attrib]) if model[attrib].kind_of? String<br />&nbsp; &nbsp; end<br />&nbsp; end<br />end</pre><br />Unfortunately, further updates causes some recursion:</p><p><pre name="code" class="ruby:nogutter">&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;<br />&amp;amp;lt;script&amp;amp;gt;&amp;amp;lt;/script&amp;amp;gt;<br />&amp;amp;amp;lt;script&amp;amp;amp;gt;&amp;amp;amp;lt;/script&amp;amp;amp;gt;</pre></p>]]></description>
			<author><![CDATA[dummy@example.com (marcin.urbanski)]]></author>
			<pubDate>Thu, 09 Oct 2008 15:28:13 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=77255#p77255</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=70474#p70474</link>
			<description><![CDATA[<p>Is this article still up to date? Or does rails has now built-in security for xss?</p>]]></description>
			<author><![CDATA[dummy@example.com (reyntjensw)]]></author>
			<pubDate>Sat, 02 Aug 2008 20:21:13 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=70474#p70474</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=7715#p7715</link>
			<description><![CDATA[<p>That is a good point, and the controller should make sure that a delete or modify action are written to ensure the proper request type.&nbsp; Good thing rails has verify :method =&gt; :post, :only =&gt; [...]</p><p>The biggest point I&#039;m trying to make is that whitlisting tags cannot be the whole story to your security.&nbsp; As you point out, controllers must also make sure certain create/update/deletes require a post or put.&nbsp; But when you think about it, the reason why create/update/delete should not be executed on a get isn&#039;t so much about security, but about &quot;clean&quot; and &quot;good&quot; implementation style that embraces original thinking of the W3C spec.&nbsp; It&#039;s more about what can &quot;safely be cached&quot; etc.</p><p>So it&#039;s a technicality that can also make your application more secure.&nbsp; Clearly whitelisting wasn&#039;t the whole story to making your application more secure if you rely on this line of protection.</p><p>I would not be surprised that there are other attacks to consider.&nbsp; I just raised this one example because it&#039;s somewhat unexpected.&nbsp; I certainly never thought about what could be done with a simple IMG tag.&nbsp; If you look at the hackers site, it seems a good amount of attacks are used by putting unexpected things into the IMG tag.&nbsp; My point is, if you allow an IMG tag, and you care about security, can you be sure that none of these methods are going to bite you?</p>]]></description>
			<author><![CDATA[dummy@example.com (Slurpy)]]></author>
			<pubDate>Sun, 10 Dec 2006 17:01:30 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=7715#p7715</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=7712#p7712</link>
			<description><![CDATA[<p>reply to Slurpy:<br />Dontcha know that all actions that delete/edit and so fourth wants to have a method other than get (post, put, ...), and redirects can&#039;t do other than get right?</p><p>//yay, my first message in this forum, and you need to bare with my english <img src="http://railsforum.com/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Moofius)]]></author>
			<pubDate>Sun, 10 Dec 2006 16:29:35 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=7712#p7712</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=7315#p7315</link>
			<description><![CDATA[<p>The point is that an IMG tag can point to an off-site image.&nbsp; How do you know that the offsite resource really is an image and not a piece of code that injects javascript or simply a redirect back to your site, which in turn tries to activate some administrative function?</p><p>Let&#039;s say you have an admin called &quot;jeff&quot;, and a hacker called &quot;hacker&quot;.</p><p>Step 1:<br />Hacker posts a message with an img tag that goes to his own server.&nbsp; He sets up his server to not serve an image, but instead redirect the browser back to your sites administrative function to delete a user.&nbsp; You&#039;d not know this by looking at the IMG tag.</p><p>Step 2:<br />Jeff logs into the site.&nbsp; He authentiactes as usual, and evertyhing is fine.&nbsp; Jeff browses the forums, and comes across the post written by hacker.&nbsp; Jeffs&#039; browser goes off to fetch that &quot;image&quot; that hacker posted -- but instead of getting an image, your browser is redirected to the admin function.&nbsp; You&#039;d not know it, because the IMG tag looks like it&#039;s going to a normal image.&nbsp; It&#039;s hacker&#039;s server that did a bait-and-switch on you (with the specified redirect).</p><p>Step 3:&nbsp; <br />The redirect that hacker wrote goes and executes, and because jeff is authenticated as an admin, the browser and session is authenticated as an admin.&nbsp; Although jeff didn&#039;t mean to, the redirect just gone and performed some administrative function for him to delete some user (maybe even himself?).</p><p>Yes there are ways of writing your application to protect from a redirect attack, but if you sit down and read though the hacker page (<a href="http://ha.ckers.org/xss.html">http://ha.ckers.org/xss.html</a>), and spend some time really understanding the implications -- I think it will make your skin crawl.</p><p>My point is that your website is vulnerable to this kind of attack if you trust all third-party IMG tags, and allow people to embed the graphics into your website -- and you are not super careful in how you deal with admin functionality.&nbsp; Again, we&#039;re talking about a vulnerability that exploits the proper function of your website after a trusted user &amp; admin (Jeff) has been authenticated.</p><p>It is dangerous to whitelist tags in general and think you&#039;re safe.&nbsp; </p><p>Most of the time no one is going to go through the trouble of hacking your site like that.&nbsp; The issue is that when you have a website for an online game (like I do), and you have people that declare &quot;war&quot; on you because they violated your community rules, and you had to ban them -- well, some people just seem to have infinite time to think about how to attack your site and &quot;get back&quot; at you.</p><p>I&#039;m highly annoyed about all of this.&nbsp; It&#039;s not like I&#039;m some ivry-tower what-if guy that likes to theorize about highly unlikeley attacks and then spend uncountable number of hours securing something that didn&#039;t need to be secured in the first place.</p>]]></description>
			<author><![CDATA[dummy@example.com (Slurpy)]]></author>
			<pubDate>Tue, 05 Dec 2006 17:09:26 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=7315#p7315</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=5592#p5592</link>
			<description><![CDATA[<div class="quotebox"><cite>Slurpy wrote:</cite><blockquote><p>Let&#039;s say you where going to implement a simple forum.&nbsp; You most certainly would Example:<pre name="code" class="ruby:nogutter">&lt;IMG SRC=&quot;http://www.thesiteyouareon.com/somecommand.php?somevariables=maliciouscode&quot;&gt;</pre></p></blockquote></div><p>I don&#039;t get the risk here. Obviously IMG tags can include any URL, if simply accessing a url on your page can damage stuff, then surely that is your problem, not the ability to post any old url in an IMG?</p><p>-MrFunk</p>]]></description>
			<author><![CDATA[dummy@example.com (MrFunk)]]></author>
			<pubDate>Wed, 08 Nov 2006 03:05:29 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=5592#p5592</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=5165#p5165</link>
			<description><![CDATA[<p>Let&#039;s say you where going to implement a simple forum.&nbsp; You most certainly would allow somone to post an off-site image, right?&nbsp; I mean, you&#039;d not filter out &lt;img ...&gt; from a forum.&nbsp; What kind of a forum would not allow images?</p><p>I&#039;m running a very old phpBB based website, and am up to my gills in XSS, and possibly CSRF vulnerabilities.&nbsp; A good article to read is: <a href="http://shiflett.org/articles/foiling-cross-site-attacks">Foiling Cross-Site Attacks</a>.</p><p>If you look at that article, and then go to the <a href="http://ha.ckers.org/xss.html">Excellent set of XSS test cases</a>, and you&#039;ll find you&#039;ve got a pretty big mess on your hands.<br />Example:<pre name="code" class="ruby:nogutter">&lt;IMG SRC=&quot;http://www.thesiteyouareon.com/somecommand.php?somevariables=maliciouscode&quot;&gt;</pre><br />Even if you dissallow all HTML, and do something like BBCode, it&#039;s not a given that you&#039;ll be safe.&nbsp; I&#039;m just now wrapping my head around the security implications.&nbsp; Would h catch the malformed ASCII example?</p><p>I&#039;m not an expert on this by any means -- I&#039;m just starting to read up on the problem, and it&#039;s really tricky.</p><p>So the next step is to try to parse what is in the &lt;IMG...&gt; tags, right?&nbsp; Well, that is harder than one might think.&nbsp; At least it appears to me that way.&nbsp; You can&#039;t rely on anything to be as it appears.&nbsp; Null-breaks, special charcater encodings, spaces that you don&#039;t expect, and to top it off, the URL could look absoluteley correct:<pre name="code" class="ruby:nogutter">&lt;IMG SRC=&quot;http://bad.website.com/a.jpg&quot;&gt;</pre><br />The above may actually be a vulnerability if the apache server on bad.website.com is set up like so:<pre name="code" class="ruby:nogutter">Redirect 302 /a.jpg <a href="http://victimsite.com/admin.asp&amp;deleteuser">http://victimsite.com/admin.asp&amp;deleteuser</a></pre><br />So with that example, if you trust any extrenal images, you&#039;ve just opened yourself up for possibly security issue.&nbsp; Certainly the redirect will only work if (in the above example)&nbsp; admin.asp was not careful in checking things.</p><p>Security is an issue for me, and I&#039;m in the process of deciding what framework I want to start with to re-implement my website with.&nbsp; At the moment my head is spinning from all the possible attacks.&nbsp; </p><p>Please someone that knows ruby-on-rails:&nbsp; Can you read the above articles and security threat examples I provided on the links and comment.&nbsp; </p><p>I&#039;m not sure what the answer is to security... are you?&nbsp; What about session cookies and sticky logins?&nbsp; How secure are those things, if someone somehow can find a way to inject a script?</p>]]></description>
			<author><![CDATA[dummy@example.com (Slurpy)]]></author>
			<pubDate>Tue, 31 Oct 2006 19:12:20 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=5165#p5165</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=3535#p3535</link>
			<description><![CDATA[<div class="quotebox"><cite>Kelli wrote:</cite><blockquote><p>Does RoR have the equivilent of PHP&#039;s strip_tags() in which you can define certain HTML tags that <strong>are</strong> allowed, or would you just need to write out a regexp for it?</p></blockquote></div><p><a href="http://svn.techno-weenie.net/projects/plugins/white_list/">WhiteList</a> looks really nice for this kind of thing; you can filter out tags and attributes that you want/don&#039;t want displayed as HTML.</p>]]></description>
			<author><![CDATA[dummy@example.com (vin)]]></author>
			<pubDate>Thu, 21 Sep 2006 20:01:32 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=3535#p3535</guid>
		</item>
		<item>
			<title><![CDATA[Re: XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=3533#p3533</link>
			<description><![CDATA[<p>Good tip and easy to implement. I always feel more comfortable knowing that the data is secure and safe before it gets near the database. </p><p>Does RoR have the equivilent of PHP&#039;s strip_tags() in which you can define certain HTML tags that <strong>are</strong> allowed, or would you just need to write out a regexp for it?</p>]]></description>
			<author><![CDATA[dummy@example.com (Kelli)]]></author>
			<pubDate>Thu, 21 Sep 2006 19:44:08 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=3533#p3533</guid>
		</item>
		<item>
			<title><![CDATA[XSS and when h just ain't enough.]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=3528#p3528</link>
			<description><![CDATA[<p>I&#039;m just setting out developing with rails at the moment and one of the things I take a bit of an interest (as it&#039;s my day job) is website security.</p><p>Now I hope everyone will be familiar with the concepts of Cross-Site Scripting (XSS) and why it&#039;s a bad thing, but if not here&#039;s a brief overview.</p><p>Basically XSS attacks generally occur when a user of a site is able to pass code to a website which contains Javascript code, which is executed by the site when the page containing the users submission is rendered.</p><p>A classic example is a bulletin board site, if a user can enter a post which has</p><p><em>&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;</em><br /> and not have any of those characters escaped or removed, then they&#039;ll likely be able to execute any javascript as though it came from the source website.</p><p>So onto Rails.&nbsp; One of the standard pieces of advice I&#039;ve seen for dealing with this problem in rails apps is to use the <em>h()</em> function whereever your putting content supplied by the user up onto the screen, and that is good advice...</p><p>but...</p><p>What about times where you can&#039;t do that.&nbsp; A good example is the in place editor field.&nbsp; If you try using <em>h()</em> there you will usually just end up breaking the javascript that runs the control.</p><p>My advice would be to look at santizing all your input data, at the point it gets submitted to your application, not just when it&#039;s replayed to the screen, that way you can avoid running the risk of missing an <em>h()</em> off somewhere or having the data output somewhere where you can&#039;t use it.</p><p>One method I&#039;ve used to do this on a little app. I&#039;m using to teach myself rails is this.</p><p>This is the controller method I use to create a new task in my todolist program</p><p><pre name="code" class="ruby:nogutter">def create_task<br />&nbsp; params[:task].each do |key, value|<br />&nbsp; &nbsp; params[:task][key] = CGI::escapeHTML(value)<br />&nbsp; end<br />&nbsp; @task = Task.new(params[:task])<br />&nbsp; if @task.save<br />&nbsp; &nbsp; flash[:notice] = &quot;New Task Saved OK&quot;<br />&nbsp; &nbsp; redirect_to :action =&gt; :index<br />&nbsp; else<br />&nbsp; &nbsp; render :action =&gt; :new_task<br />&nbsp; end<br />end</pre><br />The key lines are the first three which essentially iterate through the values for the task and escape any HTML characters in them (by the way you&#039;ll need require &#039;cgi&#039; at the top of your controller for this to work)</p><p>Another option would be instead of escaping the characters in the form to simply strip any character classes you don&#039;t want from the data before saving it, using a similar mechanism...</p><p>hope this helps.</p>]]></description>
			<author><![CDATA[dummy@example.com (raesene)]]></author>
			<pubDate>Thu, 21 Sep 2006 17:55:32 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=3528#p3528</guid>
		</item>
	</channel>
</rss>
