From: Fernando Nasser <fnasser@redhat.com>
To: 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: Fri, 18 Jul 2003 10:38:18 -0400
Message-ID: <3F18065A.1060406@redhat.com> (raw)
References: <OFBD7C18F4.2499D62A-ON85256D66.005245AA@lexmark.com>
<3F174BFF.3070704@xythos.com>
<3F1801C5.9030104@openratings.com>
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
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: fnasser@redhat.com, dmitry@openratings.com, blind@xythos.com, wsheldah@lexmark.com
Subject: Re: Prepared Statements
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>
* 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