<?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 for Jeroen van Doorn</title>
	<atom:link href="http://www.jeroenvandoorn.nl/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeroenvandoorn.nl</link>
	<description>On mission!</description>
	<lastBuildDate>Mon, 24 Aug 2009 06:23:00 +0000</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on ActiveRecord find and MySql &#8216;IN&#8217; gotcha by Jeroen van Doorn</title>
		<link>http://www.jeroenvandoorn.nl/2009/07/activerecord-find-and-mysql-in-gotcha/comment-page-1/#comment-10</link>
		<dc:creator>Jeroen van Doorn</dc:creator>
		<pubDate>Mon, 24 Aug 2009 06:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeroenvandoorn.nl/?p=3#comment-10</guid>
		<description>Hi Peter!

Long time no speak!

Very useful indeed! Will have a look at my code to see why I did this in the first place ... But I stand corrected :)

Hopefully I&#039;m able to post some more stuff in the near future

Speak soon!
Jeroen</description>
		<content:encoded><![CDATA[<p>Hi Peter!</p>
<p>Long time no speak!</p>
<p>Very useful indeed! Will have a look at my code to see why I did this in the first place &#8230; But I stand corrected <img src='http://www.jeroenvandoorn.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hopefully I&#8217;m able to post some more stuff in the near future</p>
<p>Speak soon!<br />
Jeroen</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on ActiveRecord find and MySql &#8216;IN&#8217; gotcha by Peter Bex</title>
		<link>http://www.jeroenvandoorn.nl/2009/07/activerecord-find-and-mysql-in-gotcha/comment-page-1/#comment-9</link>
		<dc:creator>Peter Bex</dc:creator>
		<pubDate>Sun, 23 Aug 2009 10:27:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeroenvandoorn.nl/?p=3#comment-9</guid>
		<description>Hi Jeroen,

Good to see you&#039;re back in the blogging business :)

Unfortunately, this post is giving bad advice.

&lt;code&gt;Tasks.find(:all, :conditions =&gt; [&quot;categorie_id IN (#{@categories.join(&#039;,&#039;)})&quot;])&lt;/code&gt;

is unsafe unless you are absolutely sure that categories are all
integers. If they are strings (and that includes &quot;integers&quot;
passed from HTML forms, which are actually strings and can be
manipulated by attackers) you are vulnerable to SQL injection. That&#039;s why you use the question mark syntax in the first place. Otherwise, you wouldn&#039;t need that.

A simple example:

&lt;pre&gt;
&lt;code&gt;
# The hash here is to make the rest of the statement a comment
@categories = [&#039;1)) UNION SELECT * FROM users #&#039;]
Tasks.find(:all, :conditions =&gt; [&quot;categorie_id IN (#{@categories.join(&#039;,&#039;)})&quot;])
&lt;/code&gt;
&lt;/pre&gt;

Of course, this will give an error if the number of columns do not match but it is not hard to pad in extra columns.  There are also ways to make it match if users has more columns; you would start by reading out id and name, or login, and password and pad those where needed.

There are a couple of proper ways to find tasks by category, even if the categories are uncontrolled strings:

&lt;code&gt;Tasks.find(:all, :conditions =&gt; [&quot;categorie_id IN (?)&quot;, @categories])&lt;/code&gt;
In this case, Rails will join with a comma and escape accordingly.

A simpler syntax is:

&lt;code&gt;Tasks.find(:all, :conditions =&gt; {:categorie_id =&gt; @categories})&lt;/code&gt;

You could also first fetch the categories and use the &#039;task&#039; method on those objects:

&lt;code&gt;Categorie.find(@categories).map(&amp;:tasks).flatten&lt;/code&gt;

I hope you find this comment useful!</description>
		<content:encoded><![CDATA[<p>Hi Jeroen,</p>
<p>Good to see you&#8217;re back in the blogging business <img src='http://www.jeroenvandoorn.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Unfortunately, this post is giving bad advice.</p>
<p><code>Tasks.find(:all, :conditions =&gt; ["categorie_id IN (#{@categories.join(',')})"])</code></p>
<p>is unsafe unless you are absolutely sure that categories are all<br />
integers. If they are strings (and that includes &#8220;integers&#8221;<br />
passed from HTML forms, which are actually strings and can be<br />
manipulated by attackers) you are vulnerable to SQL injection. That&#8217;s why you use the question mark syntax in the first place. Otherwise, you wouldn&#8217;t need that.</p>
<p>A simple example:</p>
<pre>
<code>
# The hash here is to make the rest of the statement a comment
@categories = ['1)) UNION SELECT * FROM users #']
Tasks.find(:all, :conditions =&gt; ["categorie_id IN (#{@categories.join(',')})"])
</code>
</pre>
<p>Of course, this will give an error if the number of columns do not match but it is not hard to pad in extra columns.  There are also ways to make it match if users has more columns; you would start by reading out id and name, or login, and password and pad those where needed.</p>
<p>There are a couple of proper ways to find tasks by category, even if the categories are uncontrolled strings:</p>
<p><code>Tasks.find(:all, :conditions =&gt; ["categorie_id IN (?)", @categories])</code><br />
In this case, Rails will join with a comma and escape accordingly.</p>
<p>A simpler syntax is:</p>
<p><code>Tasks.find(:all, :conditions =&gt; {:categorie_id =&gt; @categories})</code></p>
<p>You could also first fetch the categories and use the &#8216;task&#8217; method on those objects:</p>
<p><code>Categorie.find(@categories).map(&amp;:tasks).flatten</code></p>
<p>I hope you find this comment useful!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
