Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.9.3/8.9.3) with ESMTP id FAA13181 for ; Tue, 12 Oct 1999 05:53:53 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.8/8.8.8) with ESMTP id LAA20437; Tue, 12 Oct 1999 11:53:34 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <38028148.8066E930@uhlenkott.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Tue, 12 Oct 1999 11:53:44 +0200 To: Jason Uhlenkott , pgsql-sql@postgreSQL.org From: Herouth Maoz Subject: Re: [SQL] security: escaping user-supplied data At 02:31 +0200 on 12/10/1999, Jason Uhlenkott wrote: > The statements I generate are usually of the form: > INSERT INTO foo (bar, bas) VALUES ('abc', 'def'); > but the 'abc' and 'def' come from an untrusted source, so if they supply > a string like "def'); delete from foo; '" they can make me do this: > INSERT INTO foo (bar, bas) VALUES ('abc', 'def'); delete from foo; ''); > > What do I need to do to prevent this? My current plan is to prepend a > backslash to every single-quote, backslash, and semicolon in the > untrusted string. Are there any other special characters I should watch > out for? Is it possible to do something evil despite your special > characters being prepended with a backslash? I don't see why you would want to escape a semicolon. If you escape single quotes and backslashes, the above situation won't happen - the string won't be finished until the first unescaped quote - yours - is encountered. Semicolons are not special in strings. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma