X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A4A27D1B452 for ; Mon, 22 Dec 2003 09:05:06 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 75755-10 for ; Mon, 22 Dec 2003 05:04:19 -0400 (AST) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id CDCF8D1B465 for ; Mon, 22 Dec 2003 05:04:16 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 1AYLz7-0006WG-0Y; Mon, 22 Dec 2003 09:04:17 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 3625E17DDD; Mon, 22 Dec 2003 09:04:15 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id E27BD16516; Mon, 22 Dec 2003 09:04:12 +0000 (GMT) From: Richard Huxton To: "Matt Van Mater" , tgl@sss.pgh.pa.us Subject: Re: how to preserve \n in select statement Date: Mon, 22 Dec 2003 09:04:11 +0000 User-Agent: KMail/1.5 Cc: pgsql-sql@postgresql.org References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200312220904.11730.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/140 X-Sequence-Number: 16306 On Saturday 20 December 2003 17:58, Matt Van Mater wrote: > > I readily admit that I didn't read much into it, but I think you are > mistaken. If you look at the following links you will see that postgresql > definitely had a vulnerability that allowed sql injection through the use > of escape characters. I was simply saying that this behavior might be a > way of preventing that from happening again. > http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0802 > http://cert.uni-stuttgart.de/doc/postgresql/escape/ Ah - this "vulnerability" is still there - and, in fact is in every database ever produced. The issue is that applications using untrusted data to build a query string can be duped by a malicious user. So - say you have a query template: SELECT * FROM recent_news WHERE topic='?' If a malicious user supplies the string: '; DELETE FROM user_logins; SELECT ' then you will have the resulting query string: SELECT * FROM recent_news WHERE topic=''; DELETE FROM user_logins; SELECT '' If you allow multiple queries in one string, there is no way to prevent this. If you disallow multiple queries, there are still attacks that are possible. This is why it is vital to parse and validate user input. If you are asking for an integer, check that it is. If you are asking for a string, quotes etc. need to be escaped (AFAICT the stuttgart url describes a function that lets you do this - you still need to call it). The first URL seems to deal with an old bug that meant a cunning attacker could bypass your escaping. It is still vital that the application (or some middle layer) validates and checks all untrusted (and preferably all trusted) input. All standard database layers (Perl/PHP/Java, whatever) supply tools for this. Your particular issue with \n is just down to PG's standard string parsing - not really related. -- Richard Huxton Archonet Ltd