Re: to_tsquery, plainto_... avoiding bad input, injections. Is there a builtin function for this ? Escaping?

Поиск
Список
Период
Сортировка
От Christopher Swingley
Тема Re: to_tsquery, plainto_... avoiding bad input, injections. Is there a builtin function for this ? Escaping?
Дата
Msg-id 20090108162022.GA6339@abrinc.com
обсуждение исходный текст
Ответ на Re: to_tsquery, plainto_... avoiding bad input, injections. Is there a builtin function for this ? Escaping?  (Reg Me Please <regmeplease@gmail.com>)
Ответы Re: to_tsquery, plainto_... avoiding bad input, injections. Is there a builtin function for this ? Escaping?
Список pgsql-general
Greetings!

> Wed, Jan 7, 2009 at 8:07 PM, Mohamed <mohamed5432154321@gmail.com>
> > Hi, I am wondering whether or not there exists any built in
> > function for making sure a query/textinput is not harmful or one
> > that escapes them. If not, what kind of things should I watch out
> > for ?
>
> * Reg Me Please <regmeplease@gmail.com> [2009-Jan-08 00:20 AKST]:
> Maybe I'm missing the point, but have read about quote_ident() and
> quote_literal() at chapter 9.4 "String Functions and Operators"?

quote_literal() does seem like a good choice for getting the quoting
correct.  As far as protecting yourself from SQL injection attacks, you
may want to look at the options available in the programming language
you are using to get user input.  In Python, for example, you can run
queries as follows:

  parameters = (12, "bar", True)
  query = "INSERT INTO foo VALUES (%d, %s, %s);"
  cursor.execute(query, parameters)
  cursor.commit()

Python fills the '%X' fields with the parameters after verifying they
are safe.  Probably best to test how much protection this offers.

I believe the risk isn't so much a question of quoting or special
characters, but carefully crafted input variables.  For example, what if
the second parameter was:

  "'bar', True); DELETE FROM foo; INSERT INTO foo VALUES (1, 'bar',"

Cheers,

Chris
--
Christopher S. Swingley
http://swingleydev.com/
<cswingle@gmail.com>


В списке pgsql-general по дате отправления:

Предыдущее
От: Laurent ROCHE
Дата:
Сообщение: version number between pgdump and server
Следующее
От: "Harald Armin Massa"
Дата:
Сообщение: Re: version number between pgdump and server