4 ms·
> PHP has supported safe SQL and safe HTML for decades, but the programmer has to understand the problem and the solution. The ecosystem has a ton of exposed w
by paulddraper 5y ago
> PHP has supported safe SQL and safe HTML for decades, but the programmer has to understand the problem and the solution.
The ecosystem has a ton of exposed wires in builtins and libraries.
When the function's name is literally `mysql_real_escape_string` ... what does that tell you?
- zzt123 5y agoIt makes me wonder if there’s a mysql_fake_escape_string or mysql_doesnt_actually_escape_string function. And why those functions would even exist in a language.
- hnick 5y agoIt exists because "mysql_escape_string() does not take a connection argument and does not respect the current charset setting."
- zzt123 5y agoI thought the security of escaping is dependent on not having mismatched charsets? In which case, not respecting charset settings seems potentially not actually escaping? Seems like a strange function to have, although I could be foggy on my charsets.
- hnick 5y agoPHP (and old languages in general) are full of ASCII-only English-centric assumptions. I think both functions are now considered deprecated since we have even more variations like mysqli_real_escape_string (or just use PDO with bound params).
- SilverRed 5y agoIt shows the culture in PHP. They would rather keep a function around that doesn't work properly just so existing code still works instead of making everyone test that the new function works.
- ericbarrett 5y agoAs another commenter points out, this is actually a quirk of the underlying MySQL C library, which has (or had) both functions.
- gregjor 5y agoIt shows a trade-off between arbitrarily breaking code in production or not. Lots of PHP sites are hosted on services that don’t give the programmer control over the PHP version. If the hosting provider upgrades and breaks a bunch of sites that’s a problem every bit as serious (to the site’s owner) as unescaped HTML opening up XSS attacks.
- SilverRed 5y agoThis is not sustainable or a desirable thing to keep. By accepting this state of things, no security fix with breaking changes can ever be implemented.
- gregjor 5y agoWith all respect your comment is both arrogant and unrealistic. Exactly how do we not accept this state of things? No one claims it's desirable, it just is: bad code is out there, and it's not easy to fix. What would you tell a small business that relies on clunky 10-year-old code to run their business? To rewrite it in a more modern language at huge expense and risk (given that a majority of rewrite projects fail)? Can you guarantee the new thing won't be just as obsolete and vulnerable and buggy in ten years? These kinds of problems -- poorly-written and vulnerable code, amateur programmers, lack of professionalism, maintaining back-compatibility with an installed base -- are not specific to PHP. They afflict the entire software industry, and always have. Who could have seen into the future back in 2000 (when I first got exposed to PHP) that a new site would get probed by an army of bots within five minutes of going live? Or that it would be even harder today than back then to find and hire experienced programmers? PHP has had many security fixes implemented since the early releases, but how can anyone force users of an open-source language to upgrade for their own good? Or pay someone to ferret out and fix vulnerabilities they have never got hit by? Even brand new code has this problem. Look at all of the cryptocurrency code written in the last few years. We read about hacks and thefts and vulnerabilities every day, and that was written by supposedly smart people with access to modern languages and with knowledge of the contemporary security issues. And it still gets hacked. If we knew how to write perfect code that would still be perfect into the future I'm sure we would do that but until then we'll have to live with what we have. So far it has been sustainable, just less than optimal, if by optimal we mean what we can imagine rather than what we, as programmers, actually deliver.
- chipotle_coyote 5y agoWhile you're not wrong, per se, this has a bit of that "never give PHP credit for getting better when it's still possible to do bad things with it" vibe to it. I mean, it's fairly well-established PHP did some pretty boneheaded things in its history and one could argue they didn't get serious about cleaning those up until rather late in PHP 5's life cycle. (Some would say not until PHP 7.) In the case of your example, what it tells me is that they had a "mysql_escape_string()" that they needed to remove but had to deprecate first to avoid breaking existing code, however bad it might be, and so replaced it with "mysql_real_escape_string()" -- which itself hasn't been in PHP for over 5 years, since that whole MySQL driver was deprecated. There's still a "mysqli_real_escape_string()", but that name is likely a quirk of history, as there's no matching "mysqli_escape_string()" for people who would like to use the supported driver but continue screwing up the charset. (Edit: another comment reminded me of something that I knew once but had forgotten. The MySQL C API has the "escape_string" and "real_escape_string" functions in it which do precisely the same things the old PHP functions did. So this actually tells us even less about PHP the language, although it may tell us something more about MySQL.)
- paulddraper 5y ago> "never give PHP credit for getting better when it's still possible to do bad things with it" vibe to it I was trying to go for the "PHP has tons and tons of terrible shoddy baggage" vibe. https://preview.redd.it/v53przfht6n01.png?width=960&crop=smart&auto=webp&s=93201d089ea283931cc87728fa2d2d2cd9fd8fa5 https://preview.redd.it/v53przfht6n01.png?width=960&crop=sma...
- gregjor 5y agoWhat language anyone uses that's older than a couple of years doesn't have terrible shoddy baggage in at least someone's opinion? I have the same opinion about node.js/npm, and Java. My opinion doesn't make anyone stop using those languages. Stroustrup quipped "There are only two kinds of languages: the ones people complain about and the ones nobody uses." PHP is the first kind. Like every language and tool before it that came with a low barrier to entry it led to a proliferation of bad code. My friends who work in ML/data science make the same complaints about Python -- it's easy to get something to work but the code quality -- ugh. And in a few years lots of that code will face the "upgrade and break it or keep it and cross our fingers" point that so much legacy PHP is at already.
- wvenable 5y ago> The ecosystem has a ton of exposed wires in builtins and libraries. PHP is a light wrapper around C libraries. > When the function's name is literally `mysql_real_escape_string` ... what does that tell you? That it comes from the MySQL directly: https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-escape-string.html https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-escape-str...
- paulddraper 5y agoThat doesn't surprise me. MySQL is the PHP of databases.
- gregjor 5y agoExactly. Free, well-supported, useful, widely-deployed, used by lots of developers.