pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Csaba Nagy <nagy@ecircle-ag.com>
To: Fernando Nasser <fnasser@redhat.com>
Cc: Dmitry Tkach <dmitry@openratings.com>
Cc: Barry Lind <blind@xythos.com>
Cc: wsheldah@lexmark.com
Cc: pgsql-jdbc @ postgresql " ". org <pgsql-jdbc@postgresql.org>
Subject: Re: Prepared Statements
Date: 18 Jul 2003 16:46:33 +0200
Message-ID: <1058539593.25132.304.camel@coppola.ecircle.de> (raw)
In-Reply-To: <3F18065A.1060406@redhat.com>
References: <OFBD7C18F4.2499D62A-ON85256D66.005245AA@lexmark.com>
	<3F174BFF.3070704@xythos.com>
	<3F1801C5.9030104@openratings.com>
	<3F18065A.1060406@redhat.com>

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
> 





view thread (105+ messages)  latest in thread

Message-ID: <1058539593.25132.304.camel@coppola.ecircle.de>
Permalink:  ../1058539593.25132.304.camel@coppola.ecircle.de/
Also on:    postgresql.org/message-id/1058539593.25132.304.camel@coppola.ecircle.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: nagy@ecircle-ag.com, fnasser@redhat.com, dmitry@openratings.com, blind@xythos.com, wsheldah@lexmark.com
  Subject: Re: Prepared Statements
  In-Reply-To: <1058539593.25132.304.camel@coppola.ecircle.de>
  References: <OFBD7C18F4.2499D62A-ON85256D66.005245AA@lexmark.com> <3F174BFF.3070704@xythos.com> <3F1801C5.9030104@openratings.com> <3F18065A.1060406@redhat.com> <1058539593.25132.304.camel@coppola.ecircle.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox