PHP security - developing a new language
Tuesday, June 27th, 2006There’s an interesting an pretty intelligent thread on bugtraq about why PHP is an insecure language and how to solve it. Most of the thread is pretty pedantic, but the most recent post by Glynn Clements is pretty interesting. In his post, he describes what a secure language from the standpoint of XSS and SQL injection might be.
My theory is there is no such thing as a safe language. When there was C there was buffer overflows and stack smashing. When there was PERL there was null byte injection, now that we have PHP there is, well, everything that PERL had wrong, minus null bytes (sorta). What would a new language look like that could protect you from all the wrong doings of your web users?
It would have to protect you from CSRF, it would have to protect you from injection, wether it’s script injection, HTML injection or otherwise. It would need to validate the authenticity of any uploaded files to be the files they were expected to be. It would have to identify and stop robotic activity, like blog spamming, without blocking valid users. It would need to keep state (session management), and not allow cookie replaying. It would have to clean up memory properly. It would have to abstract databases so credentials could not be leaked. It would have to properly escape all chars bound for the database through a database access teir. It would have to escape all presentation bound data to be presented in the way it should. It should monitor all outbound activity for patterns that could denote database dumping (credit cards or otherwise) and stop them. And probably about a dozen other things…
Would that make it secure? What would that solve exactly? Well now that I’ve got all that stuff taken care of, I’m still not sure that I’m secure. What about basic content filters? Those are different on every site. What about insuring that you aren’t allowing illicit content to be uploaded (okay, you can argue a content filter could detect illegal porn, but I wouldn’t buy it). What about those Chinese bad words, we discussed? Yes, we’d have to go out of our way to block those so our Chinese brothers could visit our site. My point being, no matter what you do, you still end up having to customize your application to deal with the other security risks that your organization faces (if you care).
Why can’t this all be a module? Why can’t I just include CGI.pm in PERL and have it magically take care of all this stuff for me? Why do I need a new language? How is that new language any better than a single inline module? Does it help me as a developer? My guess is that no, it doesn’t. Firstly it forces me to learn a new programming language, which by the looks of his article would be less than trivial. Secondly, it is still vulnerable to some attacks, no matter what you do. Third, I still end up having to include modules to do the application logic that I need, like thumbnailing or polling widgets or whatever.
Since PHP is abstracted already, and has the concept of libraries and includes, why don’t we just create a module that overwrites all of the base functions to make them more secure? Wouldn’t that go a lot further to solving the problem than creating a new language, on top of which would need to be re-created every dynamic application that has already be built? I think re-inventing the wheel (again) isn’t solving the problem, it’s just abstracting it and making developer’s lives more difficult.


