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 28E57CCD3B for ; Fri, 18 Jul 2003 14:46:20 +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 11463-06 for ; Fri, 18 Jul 2003 14:46:37 +0000 (GMT) Received: from webmail.muc.domues.com (webmail.muc.domeus.com [62.67.54.176]) by svr1.postgresql.org (Postfix) with ESMTP id 3FBFDCCD4A for ; Fri, 18 Jul 2003 11:46:08 -0300 (ADT) Received: from coppola.ecircle.de ([192.168.1.142]) by webmail.muc.domues.com (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) with ESMTP id h6IEkXk30860; Fri, 18 Jul 2003 16:46:33 +0200 Subject: Re: Prepared Statements From: Csaba Nagy To: Fernando Nasser Cc: Dmitry Tkach , Barry Lind , wsheldah@lexmark.com, "pgsql-jdbc @ postgresql " ". org" In-Reply-To: <3F18065A.1060406@redhat.com> References: <3F174BFF.3070704@xythos.com> <3F1801C5.9030104@openratings.com> <3F18065A.1060406@redhat.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 (1.0.8-11) Date: 18 Jul 2003 16:46:33 +0200 Message-Id: <1058539593.25132.304.camel@coppola.ecircle.de> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/126 X-Sequence-Number: 7510 I have checked, the query is indeed sent like that to the backend, I've just checked. It is a bug. Presumably for number types the parameter set is passed as it is, without any escaping. Cheers, Csaba. On Fri, 2003-07-18 at 16:38, Fernando Nasser wrote: > 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 > > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend >