X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 49A1ECCA60 for ; Thu, 17 Jul 2003 16:13:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 85926-04 for ; Thu, 17 Jul 2003 16:13:37 +0000 (GMT) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by svr1.postgresql.org (Postfix) with ESMTP id CF838CCA46 for ; Thu, 17 Jul 2003 13:13:06 -0300 (ADT) Received: from tmsl-adsl.demon.co.uk ([80.177.114.181] helo=bacon.tmsl.demon.co.uk) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 19dBNw-0006ns-0U for pgsql-jdbc@postgresql.org; Thu, 17 Jul 2003 17:13:36 +0100 Date: Thu, 17 Jul 2003 17:13:33 +0100 From: Paul Thomas To: "pgsql-jdbc @ postgresql . org" Subject: Re: Prepared Statements Message-ID: <20030717171333.D28330@bacon> References: <20030717162815.A28330@bacon> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=ISO-8859-1 In-Reply-To: <20030717162815.A28330@bacon>; from paul@tmsl.demon.co.uk on Thu, Jul 17, 2003 at 16:28:15 +0100 X-Mailer: Balsa 1.2.3 Lines: 58 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/86 X-Sequence-Number: 7470 On 17/07/2003 15:47 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 :-) Guilty as charged. still it was gone midnight... Still, I hope the general meaning is still clear. >> >> 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. I've certainly seen this referred to as SQL injection. We'll just have to agree to differ on this one :-) > 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. You just need to be aware that there is some extra validation/parsing work to do when using Statement. regards -- Paul Thomas +------------------------------+---------------------------------------------+ | Thomas Micro Systems Limited | Software Solutions for the Smaller Business | | Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | +------------------------------+---------------------------------------------+