Received: from frithjof.reiner (qmailr@a27.dialin.tuwien.ac.at [192.35.240.37]) by hub.org (8.9.3/8.9.3) with SMTP id MAA05286 for ; Fri, 15 Oct 1999 12:02:29 -0400 (EDT) (envelope-from areiner@tph.tuwien.ac.at) Received: (qmail 5522 invoked by uid 500); 15 Oct 1999 12:01:49 -0000 From: "Albert REINER" Date: Fri, 15 Oct 1999 14:01:49 +0200 To: PostgreSQL-SQL Subject: Re: [SQL] security: escaping user-supplied data Message-ID: <19991015140149.D598@frithjof> Mail-Followup-To: PostgreSQL-SQL References: <199910132330.QAA07020@uno.tksoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.6i In-Reply-To: <199910132330.QAA07020@uno.tksoft.com>; from tjk@tksoft.com on Wed, Oct 13, 1999 at 04:30:55PM -0700 On Wed, Oct 13, 1999 at 04:30:55PM -0700, tjk@tksoft.com wrote: > Here's a function in perl which should work for cleaning > a string which is sent in a query: Well, this obviously depends on the type of data you expect from the user; I don't really see why you would like to get rid of double backslashes (maybe the data is TeX-Code, and \\ has been assigned to something useful). Furthermore, you don't really prevent the user from storing \\, he just has to type \\\ instead --- a rather confusing behavior: $ perl -e '$a="\\\\\\"; print "$a\n"; $a =~ s/\\\\/\\/g; print "$a\n"; ' \\\ \\ But if you really want to prevent more than one \ in the string (which may be useful for some applications), consider s/\\+/\\/g. I guess it all depends on what type of data you want to store. By the way, for me the need to run the modification several times has never arisen. By the way, your clean_text() does not take care of %, which might be important in LIKE-clauses: "select field where field like '%" . clean_text('50% increase') . "'" might not do what you (or the user) want. Albert. -- --------------------------------------------------------------------------- Post an / Mail to / Skribu al: Albert Reiner ---------------------------------------------------------------------------