Received: from Overlord.anchorage-gymnastics.com (cable-75-5-237-24.anchorageak.net [24.237.5.75]) by hub.org (8.9.3/8.9.3) with ESMTP id UAA09841 for ; Mon, 11 Oct 1999 20:31:38 -0400 (EDT) (envelope-from jpu31@uhlenkott.net) Received: from uhlenkott.net (cable-161-6-237-24.anchorageak.net [24.237.6.161]) by Overlord.anchorage-gymnastics.com (8.9.3/8.9.3) with ESMTP id QAA02693 for ; Mon, 11 Oct 1999 16:31:07 -0800 Sender: jason@Overlord.anchorage-gymnastics.com Message-ID: <38028148.8066E930@uhlenkott.net> Date: Mon, 11 Oct 1999 16:31:04 -0800 From: Jason Uhlenkott X-Mailer: Mozilla 4.61 [en] (X11; I; Linux 2.3.14 i586) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: security: escaping user-supplied data Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I am writing a C program that will collect data from various untrusted sources, and put it in a postgresql database by PQexec'ing an INSERT INTO statement. 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?