Reply
Is PDO enough protection?
Old 05-09-2008, 05:42 PM Is PDO enough protection?
Tulork's Avatar
Experienced Talker

Posts: 38
Location: Sweden
Was thinking about it for a while today...is PDO with prepared statements realy enough protection against SQL-injections?
__________________
Hurray for me (not)
Tulork is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-09-2008, 05:53 PM Re: Is PDO enough protection?
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 603
I've been looking it over quite a bit lately. I might be wrong, but I think that it's only injection-safe if you use prepared statements with parameters. PDO->query() isn't injection-safe and I don't think the prepared statements are either without parameters. They also recommend not using PDO->quote() to build your queries.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-09-2008, 05:56 PM Re: Is PDO enough protection?
Tulork's Avatar
Experienced Talker

Posts: 38
Location: Sweden
with parameters I guess u meen

PHP Code:
$do->bindParam(':user'$this->usernamePDO::PARAM_STR); 
__________________
Hurray for me (not)
Tulork is offline
Reply With Quote
View Public Profile
 
Old 05-09-2008, 06:01 PM Re: Is PDO enough protection?
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 603
Yep, or the ? variety as well.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-09-2008, 09:06 PM Re: Is PDO enough protection?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 860
Name: Jeremy Miller
Location: Reno, NV
I would suggest sanitizing data no matter what. There are some threads here if you search for "sql injection" which will guide you.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-10-2008, 10:12 PM Re: Is PDO enough protection?
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 603
Quote:
Originally Posted by JeremyMiller View Post
I would suggest sanitizing data no matter what. There are some threads here if you search for "sql injection" which will guide you.
How would you recommend doing that without having a database specific method of escaping data? There's PDO->quote(), but the manual says it isn't recommended for building queries and I think it also says that it doesn't work for the ODBC driver.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-10-2008, 10:44 PM Re: Is PDO enough protection?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 860
Name: Jeremy Miller
Location: Reno, NV
Depends on the data being sanitized. For example, if it's usernames, I only allow letters, numbers, underscores, and dashes, so the data could be sanitized like this (for inserting):

PHP Code:
$username_sanitized preg_replace('/[^a-z0-9\-\_]/i','',$_POST['username']); 

For selecting, you'd need to escape the _ character (don't know if that's specific to MySQL or not) like this:

PHP Code:
$username_sanitized preg_replace('/[^a-z0-9\-\_]/i','',$_POST['username']);
$username_sanitized str_replace('_','\_',$username_sanitized); 
I have to admit, however, that I make all of my stuff specific to MySQL b/c generalizing too much reduces the total amount of query types available to you and I like the optimization which can be applied by using everything available to MySQL.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Is PDO enough protection?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13956 seconds with 13 queries