The recent post about what people are using for webmail got me thinking about a perhaps irrational policy I have with my own self-hosted software: I don’t install anything written in PHP, because I have this vague notion that PHP software is often insecure. I think I probably got this idea because years ago I saw all the vulnerabilities in PHP webmail clients and PHP software like Wordpress and decided that it was the language’s fault—or at least a contributing factor.

Maybe this isn’t fair. Maybe PHP is just more accessible to new devs and so they’re more likely to gravitate to it and make security mistakes. Maybe my perception isn’t even accurate, and webmail / blog software written in other languages is just as bad—but PHP gets all the the negative attention because it’s so prevalent for web apps. Maybe my policy was a good idea, years ago, but now it’s just out of date.

To be clear, I’m not trying to stoke the flames of a language holy war here or anything. I’m honestly asking: Is it maybe time to revisit my anti-PHP policy? I’m looking longingly at some federated software like Pixelfed and wondering if maybe I’m just being a little too close-minded.

So I’m interested in your own experiences and polices here. Where do you draw the security line for what you will or won’t host, and what made you make that choice?

46 points

I’m a full time senior PHP/JS developer.

PHP has a bad rap because of a few factors.

1, as you said, it’s accessible. It’s a very easy language to learn with a simple syntax and a simple tool chain. So often, it’s a dev’s first language. PHP holds your hand a little bit, but for the most part, security is on the developer, and when a dev doesn’t know any better, bad practices like interpolating values directly into your sql query seem like an easy way to get the job done, but at the hidden cost of opening up SQL injection vulnerabilities. But I’ve seen the same thing happen in Python code, so that’s not really a PHP problem so much as an education problem.

2, earlier versions of PHP were, in a word, shit. They were rife with inconsistencies, poor structure, half-baked features, and it all ran like dogshit. Even today, there’s still some contention in the PHP world about whether to fix the inconsistencies or not, because so much legacy code would fall apart if they did. PHP <= 4 was a goddamned dumpster fire. 5 was MARGINALLY better and brought in proper OOP. 6 literally didn’t exist for various reasons. 7 was actually getting pretty good, now with optional static typing. 8 is BANGIN’. It’s fast, easy to work with, has a great feature set, and a huge community.

3, it’s a big player. When you’re a huge player, you’re also a huge target. Wordpress is one of the most prolific web apps in existence, and it’s PHP based. Being huge, many more people are writing (shit) code for it, and many more (shit) people are trying to break it. Of course software that’s run on more servers is gonna be attacked more. It’s just numbers.

TBH, today, working in both languages extensively, I’d gladly take a PHP based web app over a NodeJS based web app. Don’t get me wrong, I love node for what it is and the paycheck I get, but JS is a goddamned dumpster fire of a half-baked language.

So tldr, don’t fear the PHP. As long as your software was written by somebody who knows their aaS from a hole in the ground, you’ll be fine.

permalink
report
reply
9 points
*

Lol, I really appreciate your thoughts! These are exactly the sort of insights I came here for. I hope this is useful to others too who may be wondering about the same thing.

permalink
report
parent
reply
3 points

The fact that people still stuck talking about baggages of PHP 4/5, which was released in 2000, as if they’re still valid today is hilarious to me.

permalink
report
parent
reply
17 points

Bad applications full of security flaws can be written in basically every language.

The thing with PHP is there’s still extremely old apps that just haven’t been updated to modern standards, because PHP itself is much older and thus predates more modern JavaScript/Ruby/Python apps. Wordpress in particular hasn’t changed all that much, and insists on using a wildly outdated database layer on the name of remaining compatible with old plugins, because those plugins is what people turn to Wordpress for.

As with any app you don’t completely trust, the solution is to restrict what they can do as much as possible. Run with minimum privileges, sandbox it in a container, whatever is needed.

permalink
report
reply
2 points

That makes sense. Maybe then the trick is to look at whether any particular app (PHP or otherwise) is written with modern security practices. How do you judge a project’s security practices though?

And then, yeah, maybe also lock it down in a container so the blast radius of any actual exploit is pretty minimal.

permalink
report
parent
reply
14 points

I wrote my personal website in PHP, and I’m pretty happy with the security I’ve got going on. I’m not an expert, but I paid close attention to best practices to avoid pitfalls like SQL injection. My instinct is that it’s certainly easy to code insecure applications in PHP (and probably many other languages as well), but the language does provide means by which to code safely.

permalink
report
reply
1 point

Awesome, good to hear from an actual PHP dev. I assume then you’re also fine self-hosting third-party PHP applications? How do you make the call on whether it’s okay to host from a security perspective? The same as with software written in any other language?

permalink
report
parent
reply
5 points

It’s a good idea to invest time into hosting all your stuff in individual containers. You get lots of benefits that way, on top of isolation.

permalink
report
parent
reply
1 point

Totally. Preachin’ to the choir here. :D

permalink
report
parent
reply
2 points

If I’m being honest, I’ve never even looked to see what language most of the stuff I run is written in. Out of 16 apps that I’m running, only 3 are accessible from outside my LAN. Those three are high-profile open source projects that are actively maintained. That’s enough for me to be comfortable security-wise in my environment.

permalink
report
parent
reply
1 point

Fair enough!

permalink
report
parent
reply
12 points
*

Security flaws are on the programmer, not the programming language. PHP is easy to learn and has many built in functions useful for web developing, but if the programmer doesn’t know anything about security and ships trash code it’s only his fault, this is why Laravel is so popular

permalink
report
reply
10 points

Being worried about software written in PHP is like being worried about buildings built with Ryobi tools.

permalink
report
reply
2 points

I’m not sure that analogy quite holds (it’s not like the Ryobi tools are left connected to the building as a critical component of the HVAC system or something), but I like the image anyway. :D

permalink
report
parent
reply

Selfhosted

!selfhosted@lemmy.world

Create post

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don’t control.

Rules:

  1. Be civil: we’re here to support and learn from one another. Insults won’t be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it’s not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don’t duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

Community stats

  • 3.5K

    Monthly active users

  • 3.3K

    Posts

  • 71K

    Comments