Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

I've heard it said that PHP is inherently insecure. Is this true? Why?

share|improve this question
add comment

6 Answers

up vote 15 down vote accepted

It is pretty hard for a language to be "inherently insecure" by my definition, since a good programmer can adapt. But PHP started out leaving a lot of minefields lying around for novices.

The initial versions of PHP paid little attention to security and the design had some big flaws. Security is hard to retrofit into the core software and into the libraries. Security training is hard in the best of circumstances, and even more so when a large subset of the developers are inexperienced and started off with bad defaults.

For example, it wasn't until version 4.2.0 that register_globals was disabled by default, so data received over the network was not inserted directly into the global namespace anymore. This feature is finally slated for complete removal in the next version.

The early release of PHP and the ease of deploying simple PHP applications also attracted many developers with little security awareness, and ensured a large number of applications, a significant number of which had remotely exploitable vulnerabilities. The size and vulnerability of the deployed base also attracted a lot of interest from the exploit community.

Here are some references and useful links

share|improve this answer
add comment

Some of these reasons are described in "Fractal of bad design".

  • PHP is the blind leading the blind. I read the PHP wikibook; it should be called "how to write a absolutely vulnerable application". I can't imagine that could be published in any other language.

  • Relation to security. If you read python docs for insecure things like serializing (pickle), you'll see a red warning on the top of the page "Don't use on untrusted input!". How about PHP?

  • PHP runs only as CGI, that means complete reinitialisation of a script on every request. And that causes hate to the frameworks: "They are slow!". But frameworks eliminate code injection vulnerabilities (SQL injections - to 100%). There is a principial difference: prepared statements are safe by default. You have to do nothing to protect yourself from SQL injections, that means you can't forget or don't know about it. Not using them is uncesure by default: you have a security flaw unless you fix it manually every time.

  • PHP interpreter itself is broken. That poisonous zero bugs where the API interpretes \0 as the string terminator while php itself doesn't - why doesn't python have it??

Weak typing (i.e., silent automatic conversion between strings/numbers/et al) is so complex that whatever minor programmer effort is saved is by no means worth it.

  • Look at this. You think you are comparing 2 variables as strings? Oops, you are not!
share|improve this answer
add comment

No, it is not true. You can write secure code in PHP perfectly well. However, a lot of code written in PHP is insecure, and the reason for that is simple - PHP has relatively low barrier of entry, which means a lot of people that know little about security write in PHP. On the other hand, PHP is web-oriented, which means the public PHP application can be attacked by anyone on the internet (while, for example, C++ application for the desktop can usually be attacked only by somebody who already has access to the said desktop computer).

share|improve this answer
add comment

There are at least two points to this:

  1. PHP is very ubiquitous, and this makes it an interesting target for hackers. It also means a lot of novice programmers use PHP, because it is easy to use. So you are more likely to pick up insecure code if you include third party libraries in your application.

  2. And I guess the more important point is that PHP wasn't design to be used on the scale it is today. Rasmus Lerdorf wrote PHP to replace some Perl-scripts he used, and it grew from there. So security wasn't the most important aspect when he wrote it, and a lot of the things he decided to use back than (because it was easier to program in) are now security risks.

share|improve this answer
add comment

There are a lot of idiots who are able to write PHP code as it's a very simple language. This results in lots of insecure code, especially include($_GET['page'])-style (remote) code inclusion holes, XSS holes and SQL injection holes.

Python and Java are not so popular for people who never programmed before so there are less programming newbies and thus the chance of horrible insecure code is lower.

share|improve this answer
    
I believe that @Moshe's question was about PHP interpreter insecurities. And please, without impolite words. –  anonymous Nov 21 '10 at 16:38
5  
How dare they make an easy programming language. How obnoxious of regular people to learn these easy languages. I think we should find more ways to find faults in them. Those that enter the realm of coding without your approval, those, that commit blasphemous acts against the sacred art of programming. They should be slayed. –  DMin Nov 21 '10 at 19:48
4  
@DMin So very true! :) However, there is still an argument to be made there. One isn't, for example, allowed to practice medicine without proper training, because of the possible harm caused. Same analogy could be drawn for public internet services, since a fault in security causes harm. Note that I'm not saying I'd think it should be treated the same (in fact, I think quite the opposite), only that the analogy does have some merit. –  Ilari Kajaste Nov 25 '10 at 9:23
add comment

More popular subject is - more attention it derives. This is the first truth. Second truth is that PHP from the beginning was not very well designed and nowadays it has a lot of internal hacks to work well, that consistently leads to failures in security implementations, versions incompatibilities. As the best proof you can check MOPS. I really don't think that there is more to discuss.

share|improve this answer
    
This is untrue. PHP does have a lot of hacks, but it has nothing to do with insecurity. Any complex program has bugs, some of them would be security-related, so pointing to the list of bugs as proof of "inherent insecurity" is pointless and misleading. –  StasM Dec 24 '10 at 8:33
    
@StasM, are you trying to say that there are no vulnerabilities in PHP interpreter or you have misinterpreted part of my third sentence? Sure, only hacks is not the reason for insecurity. In my third sentence part "[...], that [...]" is related more to the beginning. –  anonymous Dec 24 '10 at 10:48
    
@Ams of course there are (were) vulnerabilities, as in any other software big and popular enough. This however in no way means some "inherent insecurity". –  StasM Dec 29 '10 at 1:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.