<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
	<title>Comments for Perl Hacks</title>
	
	<link>http://perlhacks.com</link>
	<description>Just another Perl Hacker's blog</description>
	<lastBuildDate>Mon, 16 Jan 2012 17:03:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/PerlHacksComments" /><feedburner:info uri="perlhackscomments" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Comment on Fedora and Centos CPAN RPMs by Delicious Bookmarks for January 16th from 02:47 to 11:32 « Lâmôlabs</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/nFSLTJDMsWY/</link>
		<dc:creator>Delicious Bookmarks for January 16th from 02:47 to 11:32 « Lâmôlabs</dc:creator>
		<pubDate>Mon, 16 Jan 2012 17:03:44 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=249#comment-3104</guid>
		<description>[...] Fedora and Centos CPAN RPMs – Perl Hacks – January 16th  ( tags: perl cpan modules centos fedora rpms )     January 16th, 2012, @ 12:00 pm |  Tags: links |  Category: delicious links |  Comments are closed |  Trackback this Post |  0 views [...]</description>
		<content:encoded><![CDATA[<p>[...] Fedora and Centos CPAN RPMs &ndash; Perl Hacks &#8211; January 16th  ( tags: perl cpan modules centos fedora rpms )     January 16th, 2012, @ 12:00 pm |  Tags: links |  Category: delicious links |  Comments are closed |  Trackback this Post |  0 views [...]</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/nFSLTJDMsWY" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/03/fedora-and-centos-cpan-rpms/#comment-3104</feedburner:origLink></item>
	<item>
		<title>Comment on Public Training Courses in February by Free Training Competition in Linux Format | Perl Hacks</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/-TqLSKwJkEQ/</link>
		<dc:creator>Free Training Competition in Linux Format | Perl Hacks</dc:creator>
		<pubDate>Fri, 06 Jan 2012 15:03:26 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=394#comment-3088</guid>
		<description>[...] Training Competition in Linux Format  I’ve mentioned before that I’m running some public training courses in London next month. But how do you fancy [...]</description>
		<content:encoded><![CDATA[<p>[...] Training Competition in Linux Format  I&#8217;ve mentioned before that I&#8217;m running some public training courses in London next month. But how do you fancy [...]</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/-TqLSKwJkEQ" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/12/public-training-courses-in-february/#comment-3088</feedburner:origLink></item>
	<item>
		<title>Comment on Modern Core Perl by Dave Cross</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/dlNPzP7hvmQ/</link>
		<dc:creator>Dave Cross</dc:creator>
		<pubDate>Thu, 05 Jan 2012 07:00:17 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=353#comment-3085</guid>
		<description>I think you're probably looking for &lt;a href="http://perlhacks.com/perl-vogue/" rel="nofollow"&gt;Perl Vogue&lt;/a&gt; :-)</description>
		<content:encoded><![CDATA[<p>I think you&#8217;re probably looking for <a href="http://perlhacks.com/perl-vogue/" rel="nofollow">Perl Vogue</a> <img src='http://perlhacks.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/dlNPzP7hvmQ" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/10/modern-core-perl/#comment-3085</feedburner:origLink></item>
	<item>
		<title>Comment on Modern Core Perl by my name</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/fo0GNY-dQUM/</link>
		<dc:creator>my name</dc:creator>
		<pubDate>Wed, 04 Jan 2012 23:03:21 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=353#comment-3084</guid>
		<description>"To many people Modern Perl means big CPAN modules like Moose, DBIx::Class and Catalyst."

To me, at least, capital-m-modern Perl is about a bunch of pathetic self-promoters trying to sell their books, courses, etc.  Perl used to be about getting a job done; "Modern" Perl is a fashion show.</description>
		<content:encoded><![CDATA[<p>&#8220;To many people Modern Perl means big CPAN modules like Moose, DBIx::Class and Catalyst.&#8221;</p>
<p>To me, at least, capital-m-modern Perl is about a bunch of pathetic self-promoters trying to sell their books, courses, etc.  Perl used to be about getting a job done; &#8220;Modern&#8221; Perl is a fashion show.</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/fo0GNY-dQUM" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/10/modern-core-perl/#comment-3084</feedburner:origLink></item>
	<item>
		<title>Comment on Programming Like It’s 1999 by Name</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/nH-U43dT4-0/</link>
		<dc:creator>Name</dc:creator>
		<pubDate>Mon, 19 Dec 2011 02:30:08 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=370#comment-3058</guid>
		<description>Bobby Tables!  I don't even have to click the link</description>
		<content:encoded><![CDATA[<p>Bobby Tables!  I don&#8217;t even have to click the link</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/nH-U43dT4-0" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/11/programming-like-its-1999/#comment-3058</feedburner:origLink></item>
	<item>
		<title>Comment on Programming Like It’s 1999 by Ed Avis</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/ABFdZdxV_es/</link>
		<dc:creator>Ed Avis</dc:creator>
		<pubDate>Thu, 24 Nov 2011 19:59:41 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=370#comment-3001</guid>
		<description>Zefram gave an example of a case that your code misses.  The point is that by 'enumerating badness', you make sure that if you've overlooked something it will be a vulnerability.  Better to fail safe by rejecting anything not in a list of characters you know to be okay.  Both solutions (yours and mine) need extending to handle additional characters: yours does not handle backslash correctly, and mine doesn't do accented characters.  But the consequences of that omission are different.  You need to write the test so that even if you have missed something out (which will inevitably happen), it won't leave you with SQL injection bugs.  Losing some accented characters is a much more benign failure mode IMHO.</description>
		<content:encoded><![CDATA[<p>Zefram gave an example of a case that your code misses.  The point is that by &#8216;enumerating badness&#8217;, you make sure that if you&#8217;ve overlooked something it will be a vulnerability.  Better to fail safe by rejecting anything not in a list of characters you know to be okay.  Both solutions (yours and mine) need extending to handle additional characters: yours does not handle backslash correctly, and mine doesn&#8217;t do accented characters.  But the consequences of that omission are different.  You need to write the test so that even if you have missed something out (which will inevitably happen), it won&#8217;t leave you with SQL injection bugs.  Losing some accented characters is a much more benign failure mode IMHO.</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/ABFdZdxV_es" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/11/programming-like-its-1999/#comment-3001</feedburner:origLink></item>
	<item>
		<title>Comment on Programming Like It’s 1999 by Dave Cross</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/cFH7gDBjSuU/</link>
		<dc:creator>Dave Cross</dc:creator>
		<pubDate>Thu, 24 Nov 2011 14:20:04 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=370#comment-3000</guid>
		<description>Good idea. &lt;a href="http://perlhacks.com/code/getMovieData" rel="nofollow"&gt;See here&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Good idea. <a href="http://perlhacks.com/code/getMovieData" rel="nofollow">See here</a>.</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/cFH7gDBjSuU" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/11/programming-like-its-1999/#comment-3000</feedburner:origLink></item>
	<item>
		<title>Comment on Programming Like It’s 1999 by Alex</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/tMFuyh3KxjY/</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Thu, 24 Nov 2011 14:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=370#comment-2999</guid>
		<description>This is a good example for newbies how things should happen in modern perl. I am going to show it to my students. But can you make a copy of original script, because it can dissappear.</description>
		<content:encoded><![CDATA[<p>This is a good example for newbies how things should happen in modern perl. I am going to show it to my students. But can you make a copy of original script, because it can dissappear.</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/tMFuyh3KxjY" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/11/programming-like-its-1999/#comment-2999</feedburner:origLink></item>
	<item>
		<title>Comment on Programming Like It’s 1999 by Toby Inkster</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/dCafHrwlXks/</link>
		<dc:creator>Toby Inkster</dc:creator>
		<pubDate>Wed, 23 Nov 2011 17:07:08 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=370#comment-2997</guid>
		<description>The SQL standard way of escaping single quotes is not to backslash them, but to double them up. That is:

s{'}{''}g

Of course, many SQL databases support backslash escaping instead of or as well as the SQL standard method.</description>
		<content:encoded><![CDATA[<p>The SQL standard way of escaping single quotes is not to backslash them, but to double them up. That is:</p>
<p>s{&#8216;}{&#8221;}g</p>
<p>Of course, many SQL databases support backslash escaping instead of or as well as the SQL standard method.</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/dCafHrwlXks" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/11/programming-like-its-1999/#comment-2997</feedburner:origLink></item>
	<item>
		<title>Comment on Programming Like It’s 1999 by Zefram</title>
		<link>http://feedproxy.google.com/~r/PerlHacksComments/~3/SVjxgCeMuW0/</link>
		<dc:creator>Zefram</dc:creator>
		<pubDate>Wed, 23 Nov 2011 12:05:02 +0000</pubDate>
		<guid isPermaLink="false">http://perlhacks.com/?p=370#comment-2995</guid>
		<description>Your single-quote escaping is *not* sufficient to avoid SQL injection.  Most obviously, backslashes also need to be escaped.  Specific exploit: I give you the string &lt;code&gt;q{\');drop database imdb;-- }&lt;/code&gt;.  You escape the single quote yielding &lt;code&gt;q{\\');drop database imdb;-- }&lt;/code&gt;, and then stick it into quotes yielding &lt;code&gt;q{insert into movie (...) values ('\\');drop database imdb;-- ', ...);}&lt;/code&gt;.  The &lt;code&gt;q{'\\'}&lt;/code&gt; parses as a complete string literal, representing a string containing a single backslash.  You lose.

The right way to embed data in SQL is to have a function whose input is a data object (in whatever form you're dealing with in Perl space) and whose output is a string of SQL source constituting an expression that will evaluate to the in-database representation of the same data.  If you're dealing with a string (or anything that you represent as a string in SQL space) then you'd expect that output expression to be in the form of an SQL string literal.  The concept generalises to all SQL data types, including ones that don't have a literal syntax, and to all types of object that you deal with in Perl space.

Here's the specific logic that I developed at $ork to represent a Perl octet string as an SQL octet string:
&lt;pre&gt;
my %char_escape = ( "\0" =&gt; "\\0", "'" =&gt; "\\'", "\\" =&gt; "\\\\" );
sub sql_octetstring($) {
    my($value) = @_;
    die "not an octet string"
      unless Params::Classify::is_string($value)
      &amp;&amp; $value =~ /\A[\x00-\xff]*\z/;
    $value =~ s(([\0\'\\]))($char_escape{$1})eg;
    return "'$value'";
}
&lt;/pre&gt;
This is specifically for MySQL; you need to experiment to write the correct equivalent for your particular database.  Also, obviously, if you're dealing with general Unicode then you'll need an encoding layer on top of this.

You use it like "&lt;code&gt;where title=@{[sql_octetstring($title)]}&lt;/code&gt;" or "&lt;code&gt;values (@{[join(q(, ), map { sql_octetstring($film{$_}) } @fields)]})&lt;/code&gt;".  The babycart operator is brilliant for this sort of thing, because it gives you all the right cues about the nesting that is logically occurring.</description>
		<content:encoded><![CDATA[<p>Your single-quote escaping is *not* sufficient to avoid SQL injection.  Most obviously, backslashes also need to be escaped.  Specific exploit: I give you the string <code>q{\');drop database imdb;-- }</code>.  You escape the single quote yielding <code>q{\\');drop database imdb;-- }</code>, and then stick it into quotes yielding <code>q{insert into movie (...) values ('\\');drop database imdb;-- ', ...);}</code>.  The <code>q{'\\'}</code> parses as a complete string literal, representing a string containing a single backslash.  You lose.</p>
<p>The right way to embed data in SQL is to have a function whose input is a data object (in whatever form you&#8217;re dealing with in Perl space) and whose output is a string of SQL source constituting an expression that will evaluate to the in-database representation of the same data.  If you&#8217;re dealing with a string (or anything that you represent as a string in SQL space) then you&#8217;d expect that output expression to be in the form of an SQL string literal.  The concept generalises to all SQL data types, including ones that don&#8217;t have a literal syntax, and to all types of object that you deal with in Perl space.</p>
<p>Here&#8217;s the specific logic that I developed at $ork to represent a Perl octet string as an SQL octet string:</p>
<pre>
my %char_escape = ( "\0" =&gt; "\\0", "'" =&gt; "\\'", "\\" =&gt; "\\\\" );
sub sql_octetstring($) {
    my($value) = @_;
    die "not an octet string"
      unless Params::Classify::is_string($value)
      &amp;&amp; $value =~ /\A[\x00-\xff]*\z/;
    $value =~ s(([\0\'\\]))($char_escape{$1})eg;
    return "'$value'";
}
</pre>
<p>This is specifically for MySQL; you need to experiment to write the correct equivalent for your particular database.  Also, obviously, if you&#8217;re dealing with general Unicode then you&#8217;ll need an encoding layer on top of this.</p>
<p>You use it like &#8220;<code>where title=@{[sql_octetstring($title)]}</code>&#8221; or &#8220;<code>values (@{[join(q(, ), map { sql_octetstring($film{$_}) } @fields)]})</code>&#8220;.  The babycart operator is brilliant for this sort of thing, because it gives you all the right cues about the nesting that is logically occurring.</p>
<img src="http://feeds.feedburner.com/~r/PerlHacksComments/~4/SVjxgCeMuW0" height="1" width="1"/>]]></content:encoded>
	<feedburner:origLink>http://perlhacks.com/2011/11/programming-like-its-1999/#comment-2995</feedburner:origLink></item>
</channel>
</rss><!-- Dynamic page generated in 0.303 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-01-16 19:37:59 --><!-- Compression = gzip -->

