pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Csaba Nagy <nagy@ecircle-ag.com>
To: Dmitry Tkach <dmitry@openratings.com>
Cc: Paul Thomas <paul@tmsl.demon.co.uk>
Cc: pgsql-jdbc @ postgresql " ". org <pgsql-jdbc@postgresql.org>
Subject: Re: Prepared Statements
Date: 17 Jul 2003 17:14:37 +0200
Message-ID: <1058454878.25132.214.camel@coppola.ecircle.de> (raw)
In-Reply-To: <3F16B715.4010006@openratings.com>
References: <200307161624.39340.julien.legoff@laposte.net>
	<20030717002329.A26390@bacon>
	<3F16B715.4010006@openratings.com>

On Thu, 2003-07-17 at 16:47, Dmitry Tkach wrote:
[snip]
> >
> > This is a security hole known as SQL injection. 
> 
> No, it isn't :-)
> The "hole" you are referring to is letting the users type in entire 
> queries, not just input parameters.
> As long as you have control over how your sql is constructed, you not 
> any less (nor any more) safe with plain Statements than you would be 
> with PreparedStatements. The do the same exact thing.

In my understanding the prepared statement will properly escape any
parameter so it can be trusted that the resulting query will not contain
something you wouldn't expect. Example (< and > are delimiters, ignore
them):

query: <SELECT * from address_book WHERE name = ?>

input: <joe';delete from address_book where 'true>

result if you just replace the <?> with <'$input'>:
SELECT * from address_book WHERE name = 'joe';delete from address_book
where 'true'
-> results in 2 statements executed

result if you use prepared statement:
SELECT * from address_book WHERE name = 'joe\';delete from address_book
where \'true'

As you can see, the "clever" injection attack is still rejected through
escaping the <'> characters. You can't possibly cause SQL injection
while using prepared statements.

Cheers,
Csaba.

> 
> Dima
> 
> > If you are using a normal Statement then your users can probably 
> > delete whole tables from the database but with a PreparedStatement you 
> > would write
> >
> > String query = "SELECT * from address_book WHERE name = ?"
> >
> > and the command actually passed over to the database would be
> >
> > SELECT * from address_book WHERE name = 'joe;delete from address_book'
> >
> > I'm sure you can see the difference. Maybe PreparedStatements will 
> > have a performance gain in some future release but at the moment they 
> > have a vital role to play in database security.
> >
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 





view thread (105+ messages)  latest in thread

Message-ID: <1058454878.25132.214.camel@coppola.ecircle.de>
Permalink:  ../1058454878.25132.214.camel@coppola.ecircle.de/
Also on:    postgresql.org/message-id/1058454878.25132.214.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, dmitry@openratings.com, paul@tmsl.demon.co.uk
  Subject: Re: Prepared Statements
  In-Reply-To: <1058454878.25132.214.camel@coppola.ecircle.de>
  References: <200307161624.39340.julien.legoff@laposte.net> <20030717002329.A26390@bacon> <3F16B715.4010006@openratings.com> <1058454878.25132.214.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