From: | "Jonathan Bond-Caron" <jbondc(at)gmail(dot)com> |
---|---|
To: | "'Ivan Sergio Borgonovo'" <mail(at)webthatworks(dot)it>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: SQL injection, php and queueing multiple statement |
Date: | 2008-04-12 15:11:48 |
Message-ID: | 016e01c89caf$87dff370$979fda50$@com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"My premise is that someone will do mistakes in the php code and I'd like to
mitigate the effect of these mistakes."
- Prepared statements is the only "bulletproof" technique
- You can use a database abstraction layer (there are more than many
libraries for PHP) Fast to implement, all queries goes through some form of
filter
- Recommended solution - use database abstraction & AUDIT your code / grabs
all SQL statements / create a summary and make sure then each statement is
safe
$db->Execute("select id from table1 where integer =" (int)$i);
$db->Execute("select * from table1 where string =" $db->quote($i));
Database abstractions alone often give you a false sense of security
especially if you use third part / open source solutions
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Ivan Sergio
Borgonovo
Sent: April 11, 2008 5:32 PM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] SQL injection, php and queueing multiple statement
On Fri, 11 Apr 2008 14:27:09 -0500
"Adam Rich" <adam(dot)r(at)sbcglobal(dot)net> wrote:
> > Is there a switch (php side or pg side) to avoid things like:
> >
> > pg_query("select id from table1 where a=$i");
> >
> > into becoming
> >
> > pg_query("select id from table1 where a=1 and 1=1; do something
> > nasty; -- ");
>
> Ideally, you'd use this:
>
> pg_query_params('select id from table1 where a=$1', array($i));
>
> http://us2.php.net/manual/en/function.pg-query-params.php
>
> Alternately, you can do this:
>
> $i = pg_escape_string($i);
> pg_query(" select id from table1 where a='$i' ");
I'd try to be clearer.
The purpose of my question was not how to avoid sql injection... but
how to make it harder to exploit it.
My premise is that someone will do mistakes in the php code and I'd
like to mitigate the effect of these mistakes.
I know that even if you just permit one statement for each pg_query
you can still use blind sql injection to download whole tables etc...
but permitting more than one statement make things MUCH easier.
Up to my knowledge blind sql injection requires a lot of statement
and a lot of errors that will end up in my logs so I'll have a chance
to fix the error etc...
Prepared statements does not fit with part of the framework I'm
working with. And still I'm looking for a security net even in the
case someone is not respecting the policies.
thx
--
Ivan Sergio Borgonovo
http://www.webthatworks.it
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Mason | 2008-04-12 15:22:12 | Re: Post-installation questions |
Previous Message | william wayne | 2008-04-12 15:05:41 | Post-installation questions |