Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 95CB22E004F for ; Sun, 27 Apr 2008 14:18:51 -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 75055-05 for ; Sun, 27 Apr 2008 14:18:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtp-out112.alice.it (smtp-out112.alice.it [85.37.17.112]) by developer.postgresql.org (Postfix) with ESMTP id 8FF8B2E0032 for ; Sun, 27 Apr 2008 14:18:46 -0300 (ADT) Received: from FBCMMO02.fbc.local ([192.168.68.196]) by smtp-out112.alice.it with Microsoft SMTPSVC(6.0.3790.1830); Sun, 27 Apr 2008 19:18:43 +0200 Received: from FBCMCL01B07.fbc.local ([192.168.171.45]) by FBCMMO02.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sun, 27 Apr 2008 19:18:43 +0200 Received: from kerberos.webthatworks.it ([80.117.26.143]) by FBCMCL01B07.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sun, 27 Apr 2008 19:17:36 +0200 Received: from dawn.webthatworks.it (dawn.webthatworks.it [192.168.1.12]) by kerberos.webthatworks.it (Postfix) with ESMTP id 1BA21E6A96 for ; Sun, 27 Apr 2008 19:18:42 +0200 (CEST) Received: from dawn.webthatworks.it (localhost [127.0.0.1]) by dawn.webthatworks.it (Postfix) with ESMTP id DBC5C39B26 for ; Sun, 27 Apr 2008 19:18:40 +0200 (CEST) Date: Sun, 27 Apr 2008 19:18:40 +0200 From: Ivan Sergio Borgonovo To: pgsql-sql@postgresql.org Subject: Re: Protection from SQL injection Message-ID: <20080427191840.494b6bf7@dawn.webthatworks.it> In-Reply-To: <4814A1E6.1070200@freedomcircle.net> References: <5f211bd50804260932l7a63618jca64858271ff269f@mail.gmail.com> <13670.1209267734@sss.pgh.pa.us> <20080427123848.5c841788@dawn.webthatworks.it> <20080427142253.449de600@dawn.webthatworks.it> <4814A1E6.1070200@freedomcircle.net> 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 17:17:36.0390 (UTC) FILETIME=[967EBA60:01C8A88A] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/204 X-Sequence-Number: 30743 On Sun, 27 Apr 2008 11:55:18 -0400 Joe wrote: > Ivan Sergio Borgonovo wrote: > > 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. > Python already supports something like that. See PEP 249 > (http://www.python.org/dev/peps/pep-0249/), under Module Interface, > the description of the paramstyle parameter. Psycopg2 supports both > the "format" (C printf) and "pyformat" styles. See the last section > on this page for an example using the pyformat style: > http://www.devx.com/opensource/Article/29071/0/page/3. That's better than nothing but it is still a lot of code duplication. You've to write column names in the sql statement and in the array and... column values are not contextual to the statement. That's easy... while what I wrote above does look as requiring a really special parser. Furthermore from the example it looks as if all this is going to miss the scope to prevent sql injection since it doesn't support prepared statements. -- Ivan Sergio Borgonovo http://www.webthatworks.it