<?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"
	>
<channel>
	<title>Comments on: Railsconf Resources</title>
	<atom:link href="http://www.misuse.org/science/2008/05/30/railsconf-resources/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/</link>
	<description>It would be a good idea.</description>
	<pubDate>Wed, 07 Jan 2009 04:29:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: science</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-4130</link>
		<dc:creator>science</dc:creator>
		<pubDate>Thu, 14 Aug 2008 22:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-4130</guid>
		<description>Aaron: Thanks for the kind words.

My first thought about your question is "be careful!" You're playing with fire. It is very possible to sanitize your inputs but you've got to be very thoughtful about it.

There are many ways to solve the "operator in the input" problem - I think a case statement is the safest. So as you loop through your various inputs in params, you can do a regex match or something in your input names:
&lt;code&gt;&lt;pre&gt;%r{(.*)_(gt&#124;lt&#124;eq)}
&lt;/pre&gt;&lt;/code&gt;

\1 would be your field name
\2 would be your operator symbol

In Postgres (the db I use), it's possible to escape columns as well as escape values. In Pg, you use the double quote (") to signify a column name, so if your table is "property" and your field is "price" you would write sql like:

"property"."price" &gt; 500

There's lots more in this subject - keep in touch as you work on this stuff!</description>
		<content:encoded><![CDATA[<p>Aaron: Thanks for the kind words.</p>
<p>My first thought about your question is &#8220;be careful!&#8221; You&#8217;re playing with fire. It is very possible to sanitize your inputs but you&#8217;ve got to be very thoughtful about it.</p>
<p>There are many ways to solve the &#8220;operator in the input&#8221; problem - I think a case statement is the safest. So as you loop through your various inputs in params, you can do a regex match or something in your input names:<br />
<code>
<pre>%r{(.*)_(gt|lt|eq)}
</pre>
<p></code></p>
<p>\1 would be your field name<br />
\2 would be your operator symbol</p>
<p>In Postgres (the db I use), it&#8217;s possible to escape columns as well as escape values. In Pg, you use the double quote (&#8221;) to signify a column name, so if your table is &#8220;property&#8221; and your field is &#8220;price&#8221; you would write sql like:</p>
<p>&#8220;property&#8221;.&#8221;price&#8221; > 500</p>
<p>There&#8217;s lots more in this subject - keep in touch as you work on this stuff!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Reichman</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-4122</link>
		<dc:creator>Aaron Reichman</dc:creator>
		<pubDate>Wed, 13 Aug 2008 19:55:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-4122</guid>
		<description>Great presentation at RailsConf.  It's a hard enough problem to solve I sat in on both talks.  I finally have a chance now to go back and re-read the presentation to try to grasp some more info.

One thing I struggle with in my own search application....How and when do you sanitize SQL inputs when the entire input is form driven?

E.g. Normally, SQL can be escaped using syntax like:

Model.find(:all, :conditions =&#62; {"name = ?", params[:name]})

But in my case, the column name ("name" in this case), the operator ("=" in this case), and the value (params[:name) are all specified in my web form.

Trying to sanitize all of that produces a WHERE statement like this:  

... WHERE 'table.name'  '='  'value'

which isn't valid due to the presence of the quotes around the equals sign.  Likewise, the column name is sanitized as 'table.column' instead of 'table'.'column'.

The reason I have it all form driven is that I want users to be able to pick which column to include in the search, what criteria (equals, not equals, greater than, like, etc...), and then the value.

Any thoughts?</description>
		<content:encoded><![CDATA[<p>Great presentation at RailsConf.  It&#8217;s a hard enough problem to solve I sat in on both talks.  I finally have a chance now to go back and re-read the presentation to try to grasp some more info.</p>
<p>One thing I struggle with in my own search application&#8230;.How and when do you sanitize SQL inputs when the entire input is form driven?</p>
<p>E.g. Normally, SQL can be escaped using syntax like:</p>
<p>Model.find(:all, :conditions =&gt; {&#8221;name = ?&#8221;, params[:name]})</p>
<p>But in my case, the column name (&#8221;name&#8221; in this case), the operator (&#8221;=&#8221; in this case), and the value (params[:name) are all specified in my web form.</p>
<p>Trying to sanitize all of that produces a WHERE statement like this:  </p>
<p>&#8230; WHERE &#8216;table.name&#8217;  &#8216;=&#8217;  &#8216;value&#8217;</p>
<p>which isn&#8217;t valid due to the presence of the quotes around the equals sign.  Likewise, the column name is sanitized as &#8216;table.column&#8217; instead of &#8216;table&#8217;.'column&#8217;.</p>
<p>The reason I have it all form driven is that I want users to be able to pick which column to include in the search, what criteria (equals, not equals, greater than, like, etc&#8230;), and then the value.</p>
<p>Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: science</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-3826</link>
		<dc:creator>science</dc:creator>
		<pubDate>Wed, 09 Jul 2008 16:25:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-3826</guid>
		<description>mabed: The params object in Rails contains all POST and GET vars - merged together. 

From an HTTP perspective, GET vars are stored on the URL line in format http://[site]?get_var1=val1&#038;get_var2=val2

POST params are included in the HTTP payload associated with the URL - mime encoded iirc. But you don't have to worry about that difference at all in Rails.

The main difference between a GET and a POST in Rails is whether you access your controller/action via a FORM submit or a link. In general FORM tags submit via POST and anchor (&lt;A&gt;) tags submit via GET. You can alter this in various ways but that's the basics. Hope it helps.</description>
		<content:encoded><![CDATA[<p>mabed: The params object in Rails contains all POST and GET vars - merged together. </p>
<p>From an HTTP perspective, GET vars are stored on the URL line in format <a href="http://site?get_var1=val1&#038;get_var2=val2" rel="nofollow">http://site?get_var1=val1&#038;get_var2=val2</a></p>
<p>POST params are included in the HTTP payload associated with the URL - mime encoded iirc. But you don&#8217;t have to worry about that difference at all in Rails.</p>
<p>The main difference between a GET and a POST in Rails is whether you access your controller/action via a FORM submit or a link. In general FORM tags submit via POST and anchor (<a>) tags submit via GET. You can alter this in various ways but that&#8217;s the basics. Hope it helps.</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mabed</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-3825</link>
		<dc:creator>mabed</dc:creator>
		<pubDate>Wed, 09 Jul 2008 14:38:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-3825</guid>
		<description>I am new to RoR. How do you go about using POST instead of parameters in the urls?</description>
		<content:encoded><![CDATA[<p>I am new to RoR. How do you go about using POST instead of parameters in the urls?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: science</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-3383</link>
		<dc:creator>science</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:35:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-3383</guid>
		<description>Hey Ed - That's totally cool. The tricky part about my whole presentation is that I wanted to present a clear "pathway" for solving these problems, when in fact there are many many combinations that lead to valid solutions. 

My solution is to use POST to hide "supplemental" search variables, and store those variables in session. Then I merge any new incoming POST vars with anything already in session to create a picture of the current search.

Your method of storing search params on the URL line is totally valid and workable. It's also simpler, as you put the persistence where it really belongs: inside the correct tab of the client browser's application. This establishes "state" of the application correctly with no additional work (no merging in/out of session).

The potential downsides of your approach are:

1) If GET URL line is too long, your method fails.

2) If you must have a relatively "clean/tidy" URL line, your method fails.

Here's an obscure edge case for case #1 above, just as an example: What if your app gets really popular and you want to optimize your searches to store all the ID's for a given search - and then permit refining the search more narrowly over time against that initial set of ID's. That will speed your query times. But if the ID set is long, the GET line will not store them all. Session (and hidden input tags) do not have this problem.</description>
		<content:encoded><![CDATA[<p>Hey Ed - That&#8217;s totally cool. The tricky part about my whole presentation is that I wanted to present a clear &#8220;pathway&#8221; for solving these problems, when in fact there are many many combinations that lead to valid solutions. </p>
<p>My solution is to use POST to hide &#8220;supplemental&#8221; search variables, and store those variables in session. Then I merge any new incoming POST vars with anything already in session to create a picture of the current search.</p>
<p>Your method of storing search params on the URL line is totally valid and workable. It&#8217;s also simpler, as you put the persistence where it really belongs: inside the correct tab of the client browser&#8217;s application. This establishes &#8220;state&#8221; of the application correctly with no additional work (no merging in/out of session).</p>
<p>The potential downsides of your approach are:</p>
<p>1) If GET URL line is too long, your method fails.</p>
<p>2) If you must have a relatively &#8220;clean/tidy&#8221; URL line, your method fails.</p>
<p>Here&#8217;s an obscure edge case for case #1 above, just as an example: What if your app gets really popular and you want to optimize your searches to store all the ID&#8217;s for a given search - and then permit refining the search more narrowly over time against that initial set of ID&#8217;s. That will speed your query times. But if the ID set is long, the GET line will not store them all. Session (and hidden input tags) do not have this problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-3382</link>
		<dc:creator>Ed</dc:creator>
		<pubDate>Tue, 03 Jun 2008 14:13:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-3382</guid>
		<description>Great presentation, too bad it was cut off - probably the best format and style I've seen in all of the sessions (including the tutorials on Thursday, which were pretty bad).

I asked you there about the use of parameters  ( ?foo=bar) vs. URL routes (implied URL parameters ala /this/is/a/parameter on links, and we didn't get a chance to finish our conversation. 

You mentioned that you would use "javascript" or POST instead of GET parameters when adding non-SEO essential parameters to a search query, however I am a bit confused by this and it seems to be kind of hacky and alot like ASP.NET "PostBack" concepts which are not very web friendly.   Any thoughts on how to format URLs for drill-down searches on non-SEO essential parameters?

foo.com/USA/New_Jersey?type=condo

not cool?</description>
		<content:encoded><![CDATA[<p>Great presentation, too bad it was cut off - probably the best format and style I&#8217;ve seen in all of the sessions (including the tutorials on Thursday, which were pretty bad).</p>
<p>I asked you there about the use of parameters  ( ?foo=bar) vs. URL routes (implied URL parameters ala /this/is/a/parameter on links, and we didn&#8217;t get a chance to finish our conversation. </p>
<p>You mentioned that you would use &#8220;javascript&#8221; or POST instead of GET parameters when adding non-SEO essential parameters to a search query, however I am a bit confused by this and it seems to be kind of hacky and alot like ASP.NET &#8220;PostBack&#8221; concepts which are not very web friendly.   Any thoughts on how to format URLs for drill-down searches on non-SEO essential parameters?</p>
<p>foo.com/USA/New_Jersey?type=condo</p>
<p>not cool?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: science</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-3370</link>
		<dc:creator>science</dc:creator>
		<pubDate>Mon, 02 Jun 2008 16:30:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-3370</guid>
		<description>Alderete: Glad it was helpful. Thanks for the suggestion! PDF is now the primary download. With the added benefit that the file is screen rather than projection quality and so is only about a meg instead of 11mb.</description>
		<content:encoded><![CDATA[<p>Alderete: Glad it was helpful. Thanks for the suggestion! PDF is now the primary download. With the added benefit that the file is screen rather than projection quality and so is only about a meg instead of 11mb.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alderete</title>
		<link>http://www.misuse.org/science/2008/05/30/railsconf-resources/#comment-3357</link>
		<dc:creator>Alderete</dc:creator>
		<pubDate>Sun, 01 Jun 2008 03:04:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.misuse.org/science/?p=135#comment-3357</guid>
		<description>I was at the (first) talk, and enjoyed it. I hope to catch the parts that had to be skipped for lack of time. Any chance of posting the slides in PDF format, not everyone has Office installed. Thanks!</description>
		<content:encoded><![CDATA[<p>I was at the (first) talk, and enjoyed it. I hope to catch the parts that had to be skipped for lack of time. Any chance of posting the slides in PDF format, not everyone has Office installed. Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
