pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fernando Nasser <fnasser@redhat.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: Thu, 17 Jul 2003 11:58:19 -0400
Message-ID: <3F16C79B.9040806@redhat.com> (raw)
References: <200307161624.39340.julien.legoff@laposte.net>
	<20030717002329.A26390@bacon>
	<3F16B715.4010006@openratings.com>

To solve this problem we have stored procedures, know in PostgreSQL land as 
'functions'.


Dmitry Tkach wrote:>>
>> Forget performance for a moment and consider database security. Lets 
>> imagine that you have an address book table called address_book
>>
>> CREATE TABLE address_booK
>> (
>>     name        varchar(30),
>>     address     text
>> );
>>
>> and you want to select a row by name. You might write
>>
>> String query = "SELECT * from address_book WHERE name = "+strName
>>
>> where strName was typed in by the user. What would happen if the user 
>> typed:
>>
>> joe;delete from address_book
> 
> 
> 
> 
> Either the exact same thing as what you describe below with the 
> PreparedStatement, or a syntax eror if you forget to put the user's 
> input into quotes when constracting your sql :-)
> 
>>
>> 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.
> 
> 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
> 



-- 
Fernando Nasser
Red Hat - Toronto                       E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9




view thread (105+ messages)  latest in thread

Message-ID: <3F16C79B.9040806@redhat.com>
Permalink:  ../3F16C79B.9040806@redhat.com/
Also on:    postgresql.org/message-id/3F16C79B.9040806@redhat.com

 · 

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: fnasser@redhat.com, dmitry@openratings.com, paul@tmsl.demon.co.uk
  Subject: Re: Prepared Statements
  In-Reply-To: <3F16C79B.9040806@redhat.com>
  References: <200307161624.39340.julien.legoff@laposte.net> <20030717002329.A26390@bacon> <3F16B715.4010006@openratings.com> <3F16C79B.9040806@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