4 ms·
The driver isn't totally to blame, too many developers weren't and still aren't trained properly. The problem is actually that users would probably never have
by teh_klev 11y ago
The driver isn't totally to blame, too many developers weren't and still aren't trained properly.
The problem is actually that users would probably never have used parameter binding even if it was available. Despite the original mysql driver not supporting parameter binding you could still mitigate against SQL injection attacks even back then. The mysql_real_escape_string() function is available to help prevent SQL injection attacks, it's been around since the dawn of PHP4 (yes I know it's not totally secure if you're not aware of your character encoding [0]) . But barely anyone used it, or even understood the purpose of mysql_real_escape_string().
I've had to trawl through ancient customer code which uses the old mysql driver on our hosting platform to explain why their site got hijacked. There's more often that not even a single use of mysql_real_escape_string(). This is code written by pro-developers I'm often told. There's not even attempts to perform naive quote escaping.
The real issue is education. There are still hoards of developers who have never heard of SQL injection. Part of the problem was that the PHP documentation from back in the day provided poor examples, the other part sites like W3S omitting any mention of mitigating against SQL injection attacks. So folks merrily copy/paste never even having heard of the concept of SQL injection.
I still have to educate customers about SQL injection attacks and many still stick their heads in the sand and don't want to believe this could possibly happen, or blame us.
And for all of the PHP team's prognostications about binning the mysql driver, folks will just move on to mysqli or PDO and still carry on doing stuff like:
$sql = "SELECT name FROM people WHERE name='$name'";
This isn't a problem specific to PHP, it's still endemic in codebases written in Classic ASP, ASP.NET, Java, python all churned out by herds of badly trained developers blissfully ignorant of the mess they're creating for their clients.
[0]: http://stackoverflow.com/a/12118602/419 http://stackoverflow.com/a/12118602/419
- kbenson 11y agoYes, but mysql_real_escape_string is a horrible, inefficient solution to a well understood problem with well understood industry standard solutions. Bound parameters were introduced into Perl's DBI module in August of 1995[1] and in the DBD::mysql module in 1997, and those reference DBD::Oracle when noting where you can get more info, so they weren't the first. My main problem with PHP on this subject is that their response to this problem for years was so lackluster, when it wasn't non-existent, that I can't give tutorials all the blame. The entire ecosystem was initially built on terrible, insecure practices for negligible benefit (I'm looking at you, register_globals), and it cost everyone on the web, not just PHP developers, for many years. And it's not like they didn't have multiple chances to fix major problems. Conversions from PHP 3 to PHP 4 were happening back in 2001. The mysql extension survived that. It also survived the migration from PHP 4 to PHP 5 in 2004. They fixed register_globals back in the PHP 4 release in 2001, but it took until 5.5, released in June of 2013 to deprecate the mysql driver. 1: http://search.cpan.org/~timb/DBI-1.634/Changes#Changes_in_DBI_0.61,_22_Aug_1995 http://search.cpan.org/~timb/DBI-1.634/Changes#Changes_in_DB...