<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>awkward silence &#187; rails</title>
	<atom:link href="http://tom.wilcoxen.org/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://tom.wilcoxen.org</link>
	<description></description>
	<lastBuildDate>Fri, 19 Mar 2010 21:39:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Preventing XSS from entering your database</title>
		<link>http://tom.wilcoxen.org/2007/06/08/preventing-xss-from-entering-your-database/</link>
		<comments>http://tom.wilcoxen.org/2007/06/08/preventing-xss-from-entering-your-database/#comments</comments>
		<pubDate>Fri, 08 Jun 2007 21:54:38 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[rails]]></category>
<category>rails</category><category>rails xss security</category><category>Uncategorized</category>
		<guid isPermaLink="false">http://tom.wilcoxen.org/2007/06/08/preventing-xss-from-entering-your-database/</guid>
		<description><![CDATA[I had all of our data being html-escaped as it was rendered to the page, but the problem is that other systems interact with ours &#8212; we send data to web analytics systems and to SalesForce.com. In that case you can&#8217;t count on escaping entities on display &#8212; you need to catch it on the [...]]]></description>
			<content:encoded><![CDATA[<p>I had all of our data being html-escaped as it was rendered to the page, but the problem is that other systems interact with ours &#8212; we send data to web analytics systems and to SalesForce.com. In that case you can&#8217;t count on escaping entities on display &#8212; you need to catch it on the way into your database.</p>
<p>I found a few sites with some fixes, though most were still focused on cleaning the data on display. I ended up taking <a href="http://weblog.techno-weenie.net/">Rick&#8217;s</a> <a href="http://weblog.techno-weenie.net/2006/9/3/white-listing-plugin-for-rails">plugin</a> and applying it at save time in the model object. I&#8217;m not sure it&#8217;s the cleanest &#8212; I&#8217;d almost certainly say there is a more elegant way to do this &#8212; but this was quick and works great.</p>
<p>It&#8217;s still basically designed to be used at output time:</p>
<p><code><%= white_list @article.body %></code></p>
<p>But instead I include the helper directly to a model and overwrite the attribute setters:</p>
<p><code><br />
class Contact < ActiveRecord::Base</p>
<p>  include WhiteListHelper</p>
<p>  def name=(text) write_attribute(:name, white_list(text)) end</p>
<p>end<br />
</code></p>
<p>I tried setting up a before_filter and stepping through the param[] object, but my data was fairly simple and the above was dead easy.</p>
<a href="http://tom.wilcoxen.org/tags/rails" rel="tag">rails</a>, <a href="http://tom.wilcoxen.org/tags/rails-xss-security" rel="tag">rails xss security</a>, <a href="http://tom.wilcoxen.org/tags/uncategorized" rel="tag">Uncategorized</a>]]></content:encoded>
			<wfw:commentRss>http://tom.wilcoxen.org/2007/06/08/preventing-xss-from-entering-your-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.169 seconds -->
