Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×

PostgreSQL 8.1.4 Released to Plug Injection Hole 162

alurkar writes to tell us that PostgreSQL released version 8.1.4 today in order to combat a security flaw allowing a SQL injection attack. From the article: "The vulnerability affects PostgreSQL servers exposed to untrusted input, such as input coming from Web forms, in conjunction with multi-byte encodings like (Shift-JIS (SJIS), 8-bit Unicode Transformation Format (UTF-8), 16-bit Unicode Transformation Format (UTF-16), and BIG5. In particular, Berkus says that applications using 'ad-hoc methods to "escape" strings going into the database, such as regexes, or PHP3's addslashes() and magic_quotes' are particularly unsafe. 'Since these bypass database-specific code for safe handling of strings, many such applications will need to be re-written to become secure.'"
This discussion has been archived. No new comments can be posted.

PostgreSQL 8.1.4 Released to Plug Injection Hole

Comments Filter:
  • This is why... (Score:2, Interesting)

    by ArchAngelQ ( 35053 ) on Tuesday May 23, 2006 @09:48PM (#15391054) Homepage Journal
    whitelisting, not blacklisting, is a good idea. Stop trying to define a set of 'wrong' data. Define a set of good data.
  • by Ayanami Rei ( 621112 ) * <rayanami&gmail,com> on Tuesday May 23, 2006 @10:26PM (#15391199) Journal
    Oracle and MySQL suffer from similar vulnerabilites when going UTF8 -> database charset. The "answer" in Oracle is to use UTF-16 on the backend and a select 8/16-bit encoding in the front end if you want to support multiple locales. I'm not sure what the implications are for MySQL.
  • Re:Guess its time (Score:5, Interesting)

    by jaredmauch ( 633928 ) <jared@puck.nether.net> on Tuesday May 23, 2006 @10:26PM (#15391201) Homepage
    Not faster, (for my application). I currently insert about 35k rows per second, mysql just can't handle that last I tried. For the inserts of the raw data that I have (about 250 mil rows a day, and i only save every 1:10k) these opteron 252's are just too slow with the one index. I'd like to be able to index more than a single column.

    If someone wants to try and help me with this problem, let me know, but I had trouble getting mysql to insert (actually doing COPY since it's about 10x faster) anywhere near what I can get with PG8.

  • by Srin Tuar ( 147269 ) <zeroday26@yahoo.com> on Tuesday May 23, 2006 @10:27PM (#15391206)
    I can understand how SJIS and BIG5 are vulnerable.

    But in a UTF-8 string, no single byte will match a single quote besides the single quote character (0x27).

    It seems to me that simply inserting a backslash before every single quote and backslash in a given string will have the desired effect, and that UTF-8 is not particularly vulnerable to this problem. (quite by design- it was invented by none other than Ken Thompson)

    Either that article is misleading somehow, or else the postgres developers are simply putting in some safeguards for common errors in things such as php scripts.
  • by JLeslie ( 710921 ) on Tuesday May 23, 2006 @10:43PM (#15391277)
    I've only recently begun playing with PostgreSQL coming from Oracle. I've also been primarily a Java (JDBC) guy for the last couple years. I'm not sure I completely understand where this vulnerability lies. Would a Java PreparedStatement be vulnerable to this? Would the Postgres implementation of JDBC use 'addslashes()' to bind variables in a prepared statement? Or is this a higher level function? (I have not come across it myself, but like I said I'm still pretty new to Postgres).

    I guess I see "affects PostgreSQL servers exposed to untrusted input, such as input coming from Web forms" and wonder if they're talking about some further functionality where postgres acts like a web server. My understanding of PreparedStatements is that they are bound at a very low level in the db to allow for maximum speed through caching etc...
  • by quantum bit ( 225091 ) on Tuesday May 23, 2006 @11:06PM (#15391374) Journal
    PostgreSQL defaults to SQL-ASCII encoding, which is unaffected by this particular attack. Only clients which connect using a multibyte encoding would be affected.

    Actually, this really isn't a vulnerability in the database server itself -- the update just intentionally breaks certain badly written applications in order to protect them from themselves. If PHP's addslashes() ends up creating valid multibyte characters that produce unexpected behavior, that's really PHP's problem -- Postgres is just doing what it's told.
  • Re:Prepared Queries (Score:3, Interesting)

    by Tablizer ( 95088 ) on Tuesday May 23, 2006 @11:14PM (#15391403) Journal
    People who don't use prepared queries doesn't deserve any better than having someone to fuck up your database!

    Often such are combersome or impossible with dynamic query generation, such as Query-by-Example forms where the terms and sort options depend on user input.

    Many "prepared" thingies also depend on positional parameters, which can get messy. Would you like to use and maintain a function with 19 positional parameters? That is what it can feel like.

    Further, certain kinds of prepared statements seem to have the same flaw. The PS api may "check" the types, but still passes a string to the database such that if you can find a way past the syntactical type checkers, you can pull off the same thing.

    I do wish that most database API's offered a "read-only" mode such that the query being sent to the database is designated read-only. That way the worse a hacker can do is grab table data but not change anything. If you have logins restricted only to necessary tables, then the damage exposure is further limited.
  • Re:Guess its time (Score:3, Interesting)

    by jadavis ( 473492 ) on Wednesday May 24, 2006 @02:13AM (#15392064)
    Well, I was thinking that it might be possible if you bunched enough of them into the same transaction, had sufficiently small updates, used a single prepared statement over and over, turned fsync off, and had HUGE amounts of memory, then, perhaps?

    You don't need to do all that.

    The command:
    time ruby -e 'puts "BEGIN;"; for i in 1..35000 do puts "INSERT INTO a VALUES(#{i});" end; puts "COMMIT;"' | ./81/bin/psql test

    Gives me about 7-8 seconds with write caching off, fsync on. Yes, I turned off write caching with hdparm. This is on my PC, with an el-cheapo IDE drive and a modest 1GB of RAM.

    If you think about it, why should it take a long time? It's all one transaction. It's basically just writing the data to a file (the log). The table "a" is just an int field, obviously. And with postgresql's MVCC, an INSERT is very cheap.

  • addslashes? (Score:4, Interesting)

    by Abstract ( 12510 ) on Wednesday May 24, 2006 @02:56AM (#15392196) Journal
    'He also notes that the addslashes function was deprecated in PHP 4.0 due to security risks, but a "distressing" number of PHP applications continue to use the function.'

    How come the php documentation [php.net] doesn't mention this?
  • by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Wednesday May 24, 2006 @10:29AM (#15393959) Homepage Journal
    ... because counting out 500 question marks to figure out why the hell your parameters don't match up is MUCH more fun than being paged at 3AM because the entire production database was wiped out.

    In the Python DB-API, SQL strings look like:

    select foo from bar where baz=%(baz)s

    You create a dictionary (hash table) with a key "baz", pass that dict to the database along with your query, and it fills in the blanks. Your job as the programmer is to make sure that dict has all the keys in it to complete the query; it doesn't matter which order you assign them or if you don't use them all.

    In fact, a very common case is to create on dict with all the values you'll need to execute a whole list of queries, and just keep passing the same dict rather than redoing it each time:

    # I know this example is lame.
    sqlparams = { 'zipcode': '12345', 'lastname': 'smith' }
    cursor.execute('insert into customers (lastname) values (%(lastname)s)', sqlparams)
    cursor.execute('insert into locations (zipcode) values (%(zipcode)s)', sqlparams)
    cursor.execute('insert into shipments (lastname, zipcode) values (%(lastname)s, %(zipcode)s)', sqlparams)

    It's about as easy as you can possibly make it and has no disadvantages that I've ever encountered. So, I'd take the position that it's better to protect the server and forget about old ideas like positional parameters. There are extremely programmer-friendly solutions to this problem if you know where to look.

  • Re:Use placeholders! (Score:3, Interesting)

    by TheLink ( 130905 ) on Thursday May 25, 2006 @12:51AM (#15399356) Journal
    Heh, as they fix all the stupid things, it starts to look more and more like Perl ;).

    Take away the popular but bad PHPisms like addslashes, magic quotes, cgi parameters automatically entering variable namespace, the combining of normal arrays with associative arrays/hashes (makes it messier to distinguish numeric keys from the indices), and you end up with something that is more Perl-ish than PHP-ish.

    PHP and MySQL, what a combination... hehe.

The key elements in human thinking are not numbers but labels of fuzzy sets. -- L. Zadeh

Working...