this post was submitted on 30 Oct 2023
977 points (96.1% liked)

Programmer Humor

32588 readers
1691 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 1 year ago* (last edited 1 year ago) (1 children)

If you're going to do that, then you also have to have a community that stresses best practices.

In 1999, Perl was leading the world with a tutorial for DBI (its primary database driver interface then and now) that uses placeholders in its very first code example. The community made that the standard, and it was the first hit on "Perl SQL tutorial" on Google for a long time. Perl applications with SQL injection attacks are out there, but have been relatively uncommon.

Notice that the API doesn't force you to use placeholders. It's simply strongly encouraged by the community.

Also in 1999, PHP was leading the world in not having a database driver interface through a common API, but rather a thin wrapper over whatever C libraries were used for individual databases. If that database supported placeholders at all (MySQL didn't, and guess which database was most popular with PHP?), then it often had a different syntax* for every one. (Note that Perl's DBI uses a translation interface that can implement "?" as a placeholder for you if the underlying DB doesn't do anything else or uses weird syntax). You could always use a filtering function, and PHP devs would routinely try to write their own rather than use the one that came with the database API that's already vetted. Either way, there was no widespread community pressure to use safe practices, and PHP led the world in SQL injection vulnerabilities for well over a decade.

*As a side note, I was recently accused by another dev of having a Python app riddled with SQL injection vulnerabilities. In fact, it was well protected, but it was using the psycopg interface to PostgreSQL, and it has a weird placeholder syntax that the other developer wasn't familiar with. Thanks, psycopg!

[–] [email protected] 2 points 1 year ago (1 children)

An interesting thing you may have missed is that the PHP community actually aggressively removed posts from stack overflow suggesting the old broken autoquoter approach. I'd say that PHP actually has an incredibly security minded community at this point.

[–] [email protected] 5 points 1 year ago

I don't doubt the language has improved. I just don't see a point when there's a million other options. In the 90s/early 2000s, you had Perl, Python, Java, and PHP. Ruby was playing around the fringes. There had been some attempts at server side JavaScript, but they weren't well developed or integrated with the frontend the way it is today.

We're now spoiled for choice, and I see no reason to give PHP any of my time over Elixir, Rust, Go, or TypeScript.