X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id A3F3DCCD3B for ; Fri, 18 Jul 2003 14:42:23 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 31366-02 for ; Fri, 18 Jul 2003 14:42:40 +0000 (GMT) Received: from touchme.toronto.redhat.com (to-telus.redhat.com [207.219.125.105]) by svr1.postgresql.org (Postfix) with ESMTP id 4C825CCD47 for ; Fri, 18 Jul 2003 11:42:12 -0300 (ADT) Received: from redhat.com (sebastian-int.corp.redhat.com [172.16.52.221]) by touchme.toronto.redhat.com (Postfix) with ESMTP id C7E848000F8; Fri, 18 Jul 2003 10:42:42 -0400 (EDT) Message-ID: <3F18065A.1060406@redhat.com> Date: Fri, 18 Jul 2003 10:38:18 -0400 From: Fernando Nasser Organization: Red Hat Canada User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020607 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Dmitry Tkach Cc: Barry Lind , wsheldah@lexmark.com, "pgsql-jdbc @ postgresql . org" Subject: Re: Prepared Statements References: <3F174BFF.3070704@xythos.com> <3F1801C5.9030104@openratings.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/125 X-Sequence-Number: 7509 Dmitry Tkach wrote: > Barry Lind wrote: > >> If using a PreparedStatement the driver correctly escapes all values >> to avoid SQL injection attacks. > > > No, it doesn't :-) > For example: > > PreparedStatement s = c.prepareStatement ("select * from user where id = > ?"); > s.setObject (1, "null;drop database mydatabase", Types.INTEGER); > System.out.println (s.toString ()); > > select * from user where id=null;drop database mydb > > :-) > I don't believe this is actually being sent to the backend, maybe it is just a toString() bug. The backend should get: select * from user where id='null;drop database mydb' (If it does not it is a bug.) P.S.: The example case would only succeed if the DBA is an idiot. You program should not be accessing the database (for this queries at least) as an user who can drop databases unless it is a privileged program for privileged users (who could do the damage using plain psql anyway). Perhaps the injection of a 'DELETE FROM mytable' would be a more realistic example. -- Fernando Nasser Red Hat Canada Ltd. E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9