<?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: Database Simplicity -&#160;Injection</title>
	<atom:link href="http://particletree.com/notebook/database-simplicity-injection/feed/" rel="self" type="application/rss+xml" />
	<link>http://particletree.com/notebook/database-simplicity-injection/</link>
	<description>Everyone needs a hug.</description>
	<pubDate>Fri, 29 Aug 2008 09:27:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Ryan Campbell</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-975</link>
		<dc:creator>Ryan Campbell</dc:creator>
		<pubDate>Fri, 30 Sep 2005 16:52:52 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-975</guid>
		<description>&lt;p&gt;Tim, I can agree with that. I do all input validation before a query is even considered except for this one function, but I can definitely see your point of view.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Tim, I can agree with that. I do all input validation before a query is even considered except for this one function, but I can definitely see your point of view.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-974</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Fri, 30 Sep 2005 13:16:52 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-974</guid>
		<description>&lt;p&gt;Having thought about it some more - perhaps the optimum solution is to do both.&lt;/p&gt;

&lt;p&gt;In any case I'll shut my big mouth and let you get on with it&#8230;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Having thought about it some more - perhaps the optimum solution is to do both.</p>

<p>In any case I&#8217;ll shut my big mouth and let you get on with it&hellip;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-973</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Fri, 30 Sep 2005 13:05:31 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-973</guid>
		<description>&lt;p&gt;Ryan - Good question. Sorry. Didn't mean that post to sound so damning! You've made me think about it though so I'll try and explain why my perspective on this is slightly different:&lt;/p&gt;

&lt;p&gt;Having created a somewhat different database class, I've been quite interested in what you've been doing with these articles as you've approached the problem from a completely different angle. Thanks to your excellent articles, I'm probably going to adapt some of my methods!&lt;/p&gt;

&lt;p&gt;My own database class only deals with the execution of a query, dealing with errors and returning relevant information to the executed query.&lt;/p&gt;

&lt;p&gt;There is no validation on the SQL before it is run simply because most of the time the SQL is created within another function or object. The only way that the SQL could therefore be broken, hacked or injected then is via the user input (whether that be POST, GET, SESSION, file input etc).&lt;/p&gt;

&lt;p&gt;In my humble opinion validation routines should be run on inputted data before ANYTHING else is done with it. For this reason I have several specific filtering and validation routines to be run on ALL input variables as soon as they are called into use. This basically adds security to your PHP no matter what you're doing - regardless of using the data for SQL generation, file manipulation, SESSION creation etc.&lt;/p&gt;

&lt;p&gt;I guess basically what I'm saying is that making sure that user-inputted data is secure should always occur well before even &lt;em&gt;considering&lt;/em&gt; using it in a query.&lt;/p&gt;

&lt;p&gt;However, I also see that SPECIFIC validation for SQL operations could be handled by the database class (as you have here).&lt;/p&gt;

&lt;p&gt;It's down to whether you have a &lt;em&gt;seperate&lt;/em&gt; validation and data security class or whether each of your classes has it's &lt;em&gt;own&lt;/em&gt; validation and data security functions built in.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ryan - Good question. Sorry. Didn&#8217;t mean that post to sound so damning! You&#8217;ve made me think about it though so I&#8217;ll try and explain why my perspective on this is slightly different:</p>

<p>Having created a somewhat different database class, I&#8217;ve been quite interested in what you&#8217;ve been doing with these articles as you&#8217;ve approached the problem from a completely different angle. Thanks to your excellent articles, I&#8217;m probably going to adapt some of my methods!</p>

<p>My own database class only deals with the execution of a query, dealing with errors and returning relevant information to the executed query.</p>

<p>There is no validation on the SQL before it is run simply because most of the time the SQL is created within another function or object. The only way that the SQL could therefore be broken, hacked or injected then is via the user input (whether that be POST, GET, SESSION, file input etc).</p>

<p>In my humble opinion validation routines should be run on inputted data before ANYTHING else is done with it. For this reason I have several specific filtering and validation routines to be run on ALL input variables as soon as they are called into use. This basically adds security to your PHP no matter what you&#8217;re doing - regardless of using the data for SQL generation, file manipulation, SESSION creation etc.</p>

<p>I guess basically what I&#8217;m saying is that making sure that user-inputted data is secure should always occur well before even <em>considering</em> using it in a query.</p>

<p>However, I also see that SPECIFIC validation for SQL operations could be handled by the database class (as you have here).</p>

<p>It&#8217;s down to whether you have a <em>seperate</em> validation and data security class or whether each of your classes has it&#8217;s <em>own</em> validation and data security functions built in.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Campbell</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-972</link>
		<dc:creator>Ryan Campbell</dc:creator>
		<pubDate>Thu, 29 Sep 2005 16:17:57 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-972</guid>
		<description>&lt;p&gt;Simon - in the function the keyword array is optional, so you have control over maintaining data like this comment. It is easy to preserve words like "or" or "like". I still agree with you about other limitations though.&lt;/p&gt;

&lt;p&gt;Tim - I could easily see this function being in my form validation class. Right now, it is in my database class because it is called from &lt;code&gt;sqlInsert()&lt;/code&gt; and &lt;code&gt;sqlUpdate()&lt;/code&gt; as the query is being built. Out of curiosity, what are your reasons for keeping this type of operation away from a database class.&lt;/p&gt;

&lt;p&gt;Jonathan - Once I change the way connections are handled with the class, this function will not be opening a new connection or adding any overhead. But I do agree with you still, and I should just go ahead and escape them myself.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Simon - in the function the keyword array is optional, so you have control over maintaining data like this comment. It is easy to preserve words like &#8220;or&#8221; or &#8220;like&#8221;. I still agree with you about other limitations though.</p>

<p>Tim - I could easily see this function being in my form validation class. Right now, it is in my database class because it is called from <code>sqlInsert()</code> and <code>sqlUpdate()</code> as the query is being built. Out of curiosity, what are your reasons for keeping this type of operation away from a database class.</p>

<p>Jonathan - Once I change the way connections are handled with the class, this function will not be opening a new connection or adding any overhead. But I do agree with you still, and I should just go ahead and escape them myself.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Willison</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-971</link>
		<dc:creator>Simon Willison</dc:creator>
		<pubDate>Thu, 29 Sep 2005 15:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-971</guid>
		<description>&lt;p&gt;I'm afraid your clean function is a terrible solution - it will corrupt data like this comment, which contains both the keywords or and like.&lt;/p&gt;

&lt;p&gt;SQL injection is an easily solved problem in practically every other language with a DB library - PHP's addslashes() and building SQL queries by gluing strings together is an unfortunate exception. Consider this example from Python:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cursor.execute("""
UPDATE animal SET name = %s
WHERE name = %s
""", (new_name, cur_name))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The DB API handles all escaping for you, adding quotes around strings and escaping nasty characters as necessary. It looks like SafeSQL takes the same approach. In fact, so does &lt;a href="http://pear.php.net/manual/en/package.database.db.intro-query.php" rel="nofollow"&gt;PEAR&lt;/a&gt;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m afraid your clean function is a terrible solution - it will corrupt data like this comment, which contains both the keywords or and like.</p>

<p>SQL injection is an easily solved problem in practically every other language with a DB library - PHP&#8217;s addslashes() and building SQL queries by gluing strings together is an unfortunate exception. Consider this example from Python:</p>

<p><code>cursor.execute("""
UPDATE animal SET name = %s
WHERE name = %s
""", (new_name, cur_name))</code></p>

<p>The DB API handles all escaping for you, adding quotes around strings and escaping nasty characters as necessary. It looks like SafeSQL takes the same approach. In fact, so does <a href="http://pear.php.net/manual/en/package.database.db.intro-query.php" rel="nofollow">PEAR</a>.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-970</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Thu, 29 Sep 2005 11:14:36 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-970</guid>
		<description>&lt;p&gt;Good point Jonathan.&lt;/p&gt;

&lt;p&gt;And why should your database class have to worry about injection? Surely you'd be better off trapping this with your form data filtering and validation routines so that your database class never HAS to deal with this kind of hacking...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Good point Jonathan.</p>

<p>And why should your database class have to worry about injection? Surely you&#8217;d be better off trapping this with your form data filtering and validation routines so that your database class never HAS to deal with this kind of hacking&#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Snook</title>
		<link>http://particletree.com/notebook/database-simplicity-injection/#comment-969</link>
		<dc:creator>Jonathan Snook</dc:creator>
		<pubDate>Thu, 29 Sep 2005 05:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://s2462.gridserver.com/wordpress/?p=133#comment-969</guid>
		<description>&lt;p&gt;I'm intrigued to as to why you wouldn't just escape single quotes for MySQL? Why go through the nuisance of connecting to the database just to use the mysql-specific function?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m intrigued to as to why you wouldn&#8217;t just escape single quotes for MySQL? Why go through the nuisance of connecting to the database just to use the mysql-specific function?</p>]]></content:encoded>
	</item>
</channel>
</rss>

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