Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id F36AB2E0081 for ; Sun, 27 Apr 2008 09:23:03 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 96437-08 for ; Sun, 27 Apr 2008 09:22:59 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtp-out25.alice.it (smtp-out25.alice.it [85.33.2.25]) by developer.postgresql.org (Postfix) with ESMTP id DDA642E004D for ; Sun, 27 Apr 2008 09:22:58 -0300 (ADT) Received: from FBCMMO02.fbc.local ([192.168.68.196]) by smtp-out25.alice.it with Microsoft SMTPSVC(6.0.3790.1830); Sun, 27 Apr 2008 14:22:56 +0200 Received: from FBCMCL01B02.fbc.local ([192.168.69.83]) by FBCMMO02.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sun, 27 Apr 2008 14:22:56 +0200 Received: from kerberos.webthatworks.it ([80.117.26.143]) by FBCMCL01B02.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sun, 27 Apr 2008 14:22:56 +0200 Received: from dawn.webthatworks.it (dawn.webthatworks.it [192.168.1.12]) by kerberos.webthatworks.it (Postfix) with ESMTP id C2B91E6A96 for ; Sun, 27 Apr 2008 14:22:55 +0200 (CEST) Received: from dawn.webthatworks.it (localhost [127.0.0.1]) by dawn.webthatworks.it (Postfix) with ESMTP id 184AC39B26 for ; Sun, 27 Apr 2008 14:22:54 +0200 (CEST) Date: Sun, 27 Apr 2008 14:22:53 +0200 From: Ivan Sergio Borgonovo To: pgsql-sql@postgresql.org Subject: Re: Protection from SQL injection Message-ID: <20080427142253.449de600@dawn.webthatworks.it> In-Reply-To: <20080427123848.5c841788@dawn.webthatworks.it> References: <5f211bd50804260932l7a63618jca64858271ff269f@mail.gmail.com> <13670.1209267734@sss.pgh.pa.us> <20080427123848.5c841788@dawn.webthatworks.it> Organization: http://www.webthatworks.it X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 27 Apr 2008 12:22:56.0916 (UTC) FILETIME=[6CB51540:01C8A861] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/198 X-Sequence-Number: 30737 On Sun, 27 Apr 2008 12:38:48 +0200 Ivan Sergio Borgonovo wrote: > Once you've developers that are so patient to write stuff like: > > "select a.id, b.name from a join b on b.id=a.id where > a.status='pending' and b.id>7 and b.status='logged'" > > into > > "select a.id, b.name from a join b on b.id=a.id where > a.status=? and b.id>? and b.status=?", 'pending', 7, 'logged' > > there are high chances they will prefer to spend some of their time > actually thinking about what they are writing. [snipped here and there] > Prepared statements force you to match input with position and it is > definitively error prone. It'd be nice to have a wrapper that let you write prepared statements this way: "select a.id, b.name from a join b on a.id=b.id where a.status=$variable1 and b.id>$variable2 etc... but that's a pretty good change to any language parser. Maybe it could be obtained by use of macro... That will turn new_query("select a.id, b.name from a join b on a.id=b.id where a.status=$variable1 and b.id>$variable2"); into pg_prepare('anonymous', 'select a.id, b.name from a join b on a.id=b.id where a.status=$1 and b.id>$2'); pg_execute('anonymous',array($variable1,$variable2)); but aren't macro evil Still it would be handy. -- Ivan Sergio Borgonovo http://www.webthatworks.it