<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Question about ActiveRecord and sanitizing inputs]]></title>
		<link>http://railsforum.com/viewtopic.php?id=48413</link>
		<description><![CDATA[The most recent posts in Question about ActiveRecord and sanitizing inputs.]]></description>
		<lastBuildDate>Wed, 04 Apr 2012 01:21:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151419#p151419</link>
			<description><![CDATA[<div class="quotebox"><cite>jamesw wrote:</cite><blockquote><p>sit down with a gallon of coffee, half a dozen pizzas...</p></blockquote></div><p>it&#039;s almost like you know me... <img src="http://railsforum.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Brian71)]]></author>
			<pubDate>Wed, 04 Apr 2012 01:21:20 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151419#p151419</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151418#p151418</link>
			<description><![CDATA[<p>Those railscasts are truly excellent, If you are new to Rails I would highly recommend you sit down with a gallon of coffee, half a dozen pizzas and a spare 24 hours and watch them all.</p>]]></description>
			<author><![CDATA[dummy@example.com (jamesw)]]></author>
			<pubDate>Tue, 03 Apr 2012 23:41:31 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151418#p151418</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151391#p151391</link>
			<description><![CDATA[<p>Thanks again James. I watched the first couple of railscasts, they are excellent.</p>]]></description>
			<author><![CDATA[dummy@example.com (Brian71)]]></author>
			<pubDate>Tue, 03 Apr 2012 14:20:36 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151391#p151391</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151389#p151389</link>
			<description><![CDATA[<p>Rails sanitises in different ways.<br />In forms for Rails version 2.x and below you would use a h clause to sanitise user input to prevent javascipt and html from being passed back to the server in Rails 3.x + this is on by default and you have to use a raw command in forms if you want to allow users to send html etc... back to the server.</p><p>this might help</p><p><a href="http://railscasts.com/episodes/25-sql-injection">http://railscasts.com/episodes/25-sql-injection</a><br /><a href="http://railscasts.com/episodes/26-hackers-love-mass-assignment">http://railscasts.com/episodes/26-hacke &#133; assignment</a><br /><a href="http://railscasts.com/episodes/178-seven-security-tips">http://railscasts.com/episodes/178-seven-security-tips</a><br /><a href="http://railscasts.com/episodes/26-hackers-love-mass-assignment-revised">http://railscasts.com/episodes/26-hacke &#133; nt-revised</a> (I think you will need a subscription to view this one but I&#039;m not sure).</p><p>So basically you don&#039;t need to worry about it just follow the advice and all should be good</p>]]></description>
			<author><![CDATA[dummy@example.com (jamesw)]]></author>
			<pubDate>Tue, 03 Apr 2012 13:50:15 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151389#p151389</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151388#p151388</link>
			<description><![CDATA[<p>Thanks for the reply.</p><p>So are you saying that Ruby or Rails sanitizes the inputs behind the scenes?</p><p>In Perl, I would run the inputs through a regex to clear out any punctuation, etc. to mitigate against a SQLi attack. What I&#039;m trying to determine is if Ruby or Rails does this for me. </p><p>I think I&#039;ll put together a test and see what happens.</p>]]></description>
			<author><![CDATA[dummy@example.com (Brian71)]]></author>
			<pubDate>Tue, 03 Apr 2012 13:36:55 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151388#p151388</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151386#p151386</link>
			<description><![CDATA[<p>You will see that there are 3 different examples of how to construct the where clause that will return the same result</p><p>The explanation is regarding the different ways to construct the where clause using parameters that a user has entered into some form on your website and applies to all SQL requests so basically it is saying NEVER pass in user input into a where or conditions or find clause THIS WAY<br /></p><div class="codebox"><pre><code>:user_name =&gt; user_name, :password =&gt; password</code></pre></div><p>This way is fine and secure and tends to be the way I typically construct where clauses or conditions<br /></p><div class="codebox"><pre><code>&quot;user_name = ? AND password = ?&quot;, user_name, password</code></pre></div><p>This way is just as safe but simpler to do and read<br /></p><div class="codebox"><pre><code>:user_name =&gt; user_name, :password =&gt; password</code></pre></div><p>I tend not to use this last way too much as it is not always a viable option (i.e. when I need to add my own non user input data that relies on something like a boolean value) and I like consistency in my code.</p><p>Whichever of the 2 recommended ways you choose is fine and down to personal preference just NEVER use the first way regardless of whether or not the data has come from a form and that way you will never get caught out by mistake.<br />It&#039;s just about how to get parameters safely into a where clause avoiding any sql injection attacks and applies to ANY form NOT just for authentication. e.g. a search form</p>]]></description>
			<author><![CDATA[dummy@example.com (jamesw)]]></author>
			<pubDate>Tue, 03 Apr 2012 13:26:49 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151386#p151386</guid>
		</item>
		<item>
			<title><![CDATA[Question about ActiveRecord and sanitizing inputs]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151382#p151382</link>
			<description><![CDATA[<p>I&#039;ve been reading through the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html">ActiveRecord::Base API</a>, and came across this:</p><div class="quotebox"><blockquote><p>Conditions</p><p>Conditions can either be specified as a string, array, or hash representing the WHERE-part of an SQL statement. The array form is to be used when the condition input is tainted and requires sanitization. The string form can be used for statements that don’t involve tainted data. The hash form works much like the array form, except only equality and range is possible. Examples:</p><div class="codebox"><pre><code>class User &lt; ActiveRecord::Base
  def self.authenticate_unsafely(user_name, password)
    where(&quot;user_name = &#039;#{user_name}&#039; AND password = &#039;#{password}&#039;&quot;).first
  end

  def self.authenticate_safely(user_name, password)
    where(&quot;user_name = ? AND password = ?&quot;, user_name, password).first
  end

  def self.authenticate_safely_simply(user_name, password)
    where(:user_name =&gt; user_name, :password =&gt; password).first
  end
end</code></pre></div><p>The authenticate_unsafely method inserts the parameters directly into the query and is thus susceptible to SQL-injection attacks if the user_name and password parameters come directly from an HTTP request. <strong>The authenticate_safely and authenticate_safely_simply both will sanitize the user_name and password before inserting them in the query,</strong> which will ensure that an attacker can’t escape the query and fake the login (or worse).</p></blockquote></div><p>My question is about the bolded statement towards the end: <br /></p><div class="quotebox"><blockquote><p>The authenticate_safely and authenticate_safely_simply both will sanitize the user_name and password before inserting them in the query</p></blockquote></div><p>So does this mean that Rails automatically sanitizes the inputs for me, or is this just saying that the latter two formats allow the inputs to be sanitized using code that&#039;s not shown?</p><p>Thanks.</p>]]></description>
			<author><![CDATA[dummy@example.com (Brian71)]]></author>
			<pubDate>Tue, 03 Apr 2012 01:39:13 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151382#p151382</guid>
		</item>
	</channel>
</rss>
