Comments on PHP security

php.internals

Alain Williams

19 years ago
This has just appeared: http://www.theregister.co.uk/2007/01/11/php_apps_security/
-- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Rasmus Lerdorf

19 years ago
Alain Williams wrote:
> This has just appeared: > > http://www.theregister.co.uk/2007/01/11/php_apps_security/
There are some concrete suggestions in the article that we addressed a while ago. Things like: "I'd like to see new defaults that limit include() and require() to only allow local files, thereby avoiding remote file injection." That's the default in PHP 5.2.0 which was released over 2 months ago now. "It would be nice to have a global way for a script to ignore all variables in the URL, avoiding unexpected variable manipulation and XSS forgeries." We can't really make that the default (which isn't suggested) since that would break a lot of stuff, but is has been possible to do this for years by simply removing "G" from the variables_order setting. "Maybe there's even a way to force users to filter input and escape output every time, helping to avoid SQL injection and all sorts of other common problems. That last one would go a long way." The filter extension has been available for quite a while now in pecl and is bundled with PHP 5.2 and it does exactly this. I won't disagree that we can and should do more to help people write safer apps, but we have to balance that with the ease of use that brought people to PHP in the first place along with the massive amount of existing code out there. It is an interesting balancing act. Another thing to keep in mind is that there are two very distinct security issues here. Remote vs. Local issues. Just about every reported security problem against PHP itself has been of the Local variety. That means that it is a flaw in our various attempts to separate users that share the same server in a shared hosting environment. I wrote about this back in 2004 in this note related to the PHPBB issues at the time: http://www.php.net/security-note.php Like I said there, when you share a server with someone else, you are never going to achieve 100% security against those other local users, especially if the ISP is running everyone on the same Apache instance with the same user id, etc. But even with jails/chroot there have been some interesting ways over the years to defeat those, and I don't doubt there will be more. Same goes for local PHP issues. It is very hard to protect the user from himself without completely crippling the language and the various attempts we have made over the years like safe_mode and open_basedir can never be fully secure. Something like open_basedir is however useful as one layer in a layered security model. For example, you can do an initial layer of user input filtering using something like mod_security, then further filter using the filter extension and finally use open_basedir to define a restricted set of directories that an application should be able to open files from. Any one of those 3 layers may not be 100% secure by themselves, but the chances are pretty good that in combination it would be quite hard for something nasty to get through since the holes in each would have to line up perfectly. An example would be naiive code like this: readfile("/some/path/".$_GET['filename']); Assuming the developer didn't think about input filtering at all, someone could simply put: ?filename=../../etc/passwd in the URL and they would see the local /etc/passwd file from the server. Even with shadow passwords on most systems today, it is a bad idea to allow remote users to read any file on your server. In this case you could have a mod_security rule to disallow ../.. style patterns in URLs. But if someone found a way to still sneak that pattern through, perhaps because of a bug in mod_security related to weird and wonderful character set tricks, if the application had a well-defined open_basedir setting the readfile() call would fail trying to read anything from /etc A second example: <a href="/download.php?filename=<?php echo $_GET['filename']?>">download</a> Again, a very common type of mistake. Without any sort of input filtering the remote user can do something like: ?filename=/etc/passwd"onmouseover="alert(document.cookie) Here the bad guy is trying to do 2 attacks at once. It is trying to trick the download.php script into downloading /etc/passwd and it is doing a very common XSS attack. Going through our layers we might have a mod_security rule that tries to strip out tags, but in this case since there are no tags and we are simply adding an attribute to an existing tag, it might slip through. Next, ext/filter kicks in with a default filter of "special_chars" for example and changes " to &quot; and the XSS is defeated and finally open_basedir stops the /etc/passwd access. This would all be without changing a single line of code in the obviously badly written application. Just a couple of configuration options in Apache and PHP. Of course, such default filtering and strict open_basedir settings might break the app if it is expecting unfiltered input somewhere in it or it is expecting access to a dir you haven't added to your open_basedir list, but it becomes pretty easy to identify the few places in an app where you need to loosen things a bit simply by starting off very strict and seeing where things break. I hope this explains some of our current thinking towards PHP security. I really don't think things are as bad as people make them out to be, but it is all about perception, so if they think it is bad, it is bad and we need to do a better job documenting things like the filter extension and how to apply a layered security model in PHP. -Rasmus

Stefan Esser

19 years ago
Hello Rasmus,
> There are some concrete suggestions in the article that we addressed a > while ago. Things like: > > "I'd like to see new defaults that limit include() and require() to > only allow local files, thereby avoiding remote file injection." > > That's the default in PHP 5.2.0 which was released over 2 months ago now. >
This is not true. It was demonstrated several times that the "protection" is easily bypassed by using data:// or php://input URLs. Maybe this is fixed in PHP 5.2.1 but it is not in 5.2.0. And it certainly is no protection at all when someone can just use one of the other URL wrappers of PHP that are considered safe and put in an overlong URL that produces a stack overflow. (Hello zip://)
> Another thing to keep in mind is that there are two very distinct > security issues here. Remote vs. Local issues. Just about every > reported security problem against PHP itself has been of the Local > variety. That means that it is a flaw in our various attempts to >
What a blatant lie. PHP had several bufferoverflows etc... in functions often exposed to user input and some direct remote exploits in the past. To just name a few: htmlentities() overflow, about a million bugs in unserialize(), fileupload exploits, memory_limit exploits, ... Last year there was f.e. the zend_hash_del_key_or_index vulnerability that exposed a large number of PHP applications to remote attacks. Ah yes and If I had not babysitted the CVS in the past there would be even more direct remote exploits against PHP, like the HTTP Digest Auth double free vulnerability. And yes, only looking at local holes, PHP has more than enough of them.
> In this case you could have a mod_security rule to disallow ../.. style > patterns in URLs. But if someone found a way to still sneak that > pattern through, perhaps because of a bug in mod_security related to >
There is nothing more trivial than sneaking something through the combination mod_security + PHP.
> tag, it might slip through. Next, ext/filter kicks in with a default > filter of "special_chars" for example and changes " to &quot; and the >
Maybe, if ext/filter would be bug free... Stefan Esser PS: Stop the "We are secure" marketing and face reality

Rasmus Lerdorf

19 years ago
Stefan Esser wrote:
> Hello Rasmus, >> There are some concrete suggestions in the article that we addressed a >> while ago. Things like: >> >> "I'd like to see new defaults that limit include() and require() to >> only allow local files, thereby avoiding remote file injection." >> >> That's the default in PHP 5.2.0 which was released over 2 months ago now. >> > This is not true. It was demonstrated several times that the > "protection" is easily bypassed by using data:// or php://input URLs. > Maybe this is fixed in PHP 5.2.1 but it is not in 5.2.0. And it > certainly is no protection at all when someone can just use one of the > other URL wrappers of PHP that are considered safe and put in an > overlong URL that produces a stack overflow. (Hello zip://)
Yes, this has been fixed. And I didn't say it was bug free. Nothing is ever bug free, but that the feature was introduced.
>> Another thing to keep in mind is that there are two very distinct >> security issues here. Remote vs. Local issues. Just about every >> reported security problem against PHP itself has been of the Local >> variety. That means that it is a flaw in our various attempts to >> > What a blatant lie. PHP had several bufferoverflows etc... in functions > often exposed to user input and some direct remote exploits in the past. > To just name a few: htmlentities() overflow, about a million bugs in > unserialize(), fileupload exploits, memory_limit exploits, ... Last year > there was f.e. the zend_hash_del_key_or_index vulnerability that exposed > a large number of PHP applications to remote attacks. Ah yes and If I > had not babysitted the CVS in the past there would be even more direct > remote exploits against PHP, like the HTTP Digest Auth double free > vulnerability. And yes, only looking at local holes, PHP has more than > enough of them.
Sure, but the majority were still local. Some of the local ones can of course be triggered remotely given the right circumstances which is why they are still very important to fix. We fix them as fast as we can and appreciate any help we get from you and others on this front.
> PS: Stop the "We are secure" marketing and face reality
This isn't "we are secure" marketing. This is simply explaining what we are doing to make PHP more secure. -Rasmus

Pierre Joye

19 years ago
Hello Stefan, On 1/11/07, Stefan Esser <sesser@hardened-php.net> wrote:
> Hello Rasmus, > > There are some concrete suggestions in the article that we addressed a > > while ago. Things like: > > > > "I'd like to see new defaults that limit include() and require() to > > only allow local files, thereby avoiding remote file injection." > > > > That's the default in PHP 5.2.0 which was released over 2 months ago now. > > > This is not true. It was demonstrated several times that the > "protection" is easily bypassed by using data:// or php://input URLs. > Maybe this is fixed in PHP 5.2.1 but it is not in 5.2.0. And it > certainly is no protection at all when someone can just use one of the > other URL wrappers of PHP that are considered safe and put in an > overlong URL that produces a stack overflow. (Hello zip://)
For your information, zip is not enabled by default. If you have a bug/issue about the specific zip:// URL, please let me know. Ilia and Tony already fixed some paths fixes and the fixes are available in zip-1.8.4. They will be in 5.2.1. --Pierre

Stefan Esser

19 years ago
> For your information, zip is not enabled by default. If you have a > bug/issue about the specific zip:// URL, please let me know. Ilia and > Tony already fixed some paths fixes and the fixes are available in > zip-1.8.4. They will be in 5.2.1.
For your information Pierre: Security Bugs in PHP are usually found by me. So guess twice WHO told security@php.net that there are bufferoverflows in zip:// URLs and WHY there have been bugfixes to ext/zip. BTW: Last time I checked, popular packages like dotdeb PHP activate ext/zip by default... And yes... Also prepare for the ***more than 30 vulnerabilities*** I disclosed to security@php.net during the last 3 weeks. Have fun... Stefan

Pierre Joye

19 years ago
Hi Stefan, On 1/11/07, Stefan Esser <sesser@hardened-php.net> wrote:
> > > For your information, zip is not enabled by default. If you have a > > bug/issue about the specific zip:// URL, please let me know. Ilia and > > Tony already fixed some paths fixes and the fixes are available in > > zip-1.8.4. They will be in 5.2.1. > For your information Pierre: Security Bugs in PHP are usually found by > me. So guess twice WHO told security@php.net that there are > bufferoverflows in zip:// URLs and WHY there have been bugfixes to ext/zip.
No idea who posted them or if someone posted something about zip. As you know I have no access to security@ and so far all I see are commits in my packages without much explanations. Not like I do not want you or anyone else to help or to do not give you the credits. But I did not know that someone else reported the issues, I apologize for that.
> BTW: Last time I checked, popular packages like dotdeb PHP activate > ext/zip by default... > > And yes... Also prepare for the ***more than 30 vulnerabilities*** I > disclosed to security@php.net during the last 3 weeks.
Nice, better later than never. Remember my numerous requests in the last months *BEFORE* the stable release (and you were still a PHP Securtiy member)?
> Have fun...
I have fun anyway, if not I will not bother to discuss that here. --Pierre

Pierre Joye

19 years ago
On 1/11/07, Pierre <pierre.php@gmail.com> wrote:
> Hi Stefan, > > On 1/11/07, Stefan Esser <sesser@hardened-php.net> wrote: > > > > > For your information, zip is not enabled by default. If you have a > > > bug/issue about the specific zip:// URL, please let me know. Ilia and > > > Tony already fixed some paths fixes and the fixes are available in > > > zip-1.8.4. They will be in 5.2.1. > > For your information Pierre: Security Bugs in PHP are usually found by > > me. So guess twice WHO told security@php.net that there are > > bufferoverflows in zip:// URLs and WHY there have been bugfixes to ext/zip. > > No idea who posted them or if someone posted something about zip. As > you know I have no access to security@ and so far all I see are > commits in my packages without much explanations. Not like I do not > want you or anyone else to help or to do not give you the credits. But > I did not know that someone else reported the issues, I apologize for > that. > > > BTW: Last time I checked, popular packages like dotdeb PHP activate > > ext/zip by default... > > > > And yes... Also prepare for the ***more than 30 vulnerabilities*** I > > disclosed to security@php.net during the last 3 weeks. > > Nice, better later than never. Remember my numerous requests in the > last months *BEFORE* the stable release (and you were still a PHP > Securtiy member)?
After having received the info (Thanks to Rasmus and Ilia), I can say that only one flaw was related to the _active_ zip extension (zip:// used with huge path). This flaw is already fixed in php-src and the last PECL release (1.8.4) contains the fix as a release has been done 2 days after I saw the commit. That does not mean there is no other but that is the only known issue and it is now fixed. The active branch is available in PECL (latest version is 1.8.4) and from PHP 5.2.0 or earlier. This extension is 100% backward compatible with the old API but with a complete new implementation. If any linux distribution still provides php4 packages, I can only recommend to use this new version instead of the old and unmaintained code (or even better, drop php4). I hope things are clearer now. --Pierre

Alain Williams

19 years ago
On Thu, Jan 11, 2007 at 05:04:30PM +0100, Stefan Esser wrote:
> PS: Stop the "We are secure" marketing and face reality
More to the point: ''We might be secure because we are careful experienced programmers'', however many of those who write in PHP are not careful and/or experienced, we should be looking to help those people - there are more of them than they are of us.
-- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Mark Krenz

19 years ago
On Thu, Jan 11, 2007 at 04:17:31PM GMT, Alain Williams [addw@phcomp.co.uk] said the following:
> On Thu, Jan 11, 2007 at 05:04:30PM +0100, Stefan Esser wrote: > > > PS: Stop the "We are secure" marketing and face reality > > More to the point: ''We might be secure because we are careful experienced programmers'', > however many of those who write in PHP are not careful and/or experienced, we should > be looking to help those people - there are more of them than they are of us. >
And for the programmers that write programs that require safe mode to be off or don't provide a provision for having it on. STOP telling your users things like "If your webhost has safe mode on then they suck". Safe mode is the only way to get around certain situations. Get a clue. You know who you are. Somehow I doubt any of these said programmers are on this list. Shame. Mark
-- Mark S. Krenz IT Director Suso Technology Services, Inc. http://suso.org/

Ilia A.

19 years ago
Safe mode does suck, and it utterly useless anyone who knows PHP internals will happily tell you that. On 11-Jan-07, at 11:25 AM, Mark Krenz wrote:
> On Thu, Jan 11, 2007 at 04:17:31PM GMT, Alain Williams > [addw@phcomp.co.uk] said the following: >> On Thu, Jan 11, 2007 at 05:04:30PM +0100, Stefan Esser wrote: >> >>> PS: Stop the "We are secure" marketing and face reality >> >> More to the point: ''We might be secure because we are careful >> experienced programmers'', >> however many of those who write in PHP are not careful and/or >> experienced, we should >> be looking to help those people - there are more of them than they >> are of us. >> > > And for the programmers that write programs that require safe mode to > be off or don't provide a provision for having it on. STOP telling > your > users things like "If your webhost has safe mode on then they suck". > Safe mode is the only way to get around certain situations. Get a > clue. > You know who you are. > > Somehow I doubt any of these said programmers are on this list. > Shame. > > Mark > > > -- > Mark S. Krenz > IT Director > Suso Technology Services, Inc. > http://suso.org/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
Ilia Alshanetsky

Stanislav Malyshev

19 years ago
> PS: Stop the "We are secure" marketing and face reality
I wonder what do you mean by that - that PHP group should publish press release "PHP is not secure, please do not use it anymore" or what? I see PHP group is working quite well eliminating the security issues. As far as I know, last year there was 7 remotely exploitable issues in PHP (which is regrettable but that's the way of life to have bugs), and all of them are fixed, IIRC, and within acceptable timeframe (the last can be debatable, but PHP being opesource project the only way to fix it is to get more participation from people in submitting patches). I know of no remotely exploitable security issue that is now in current PHP version. So I wonder what would you like PHP Group to improve? What would you mean by facing reality - what in your opinion the reality is and what would you have PHP group to do to satisfy you on facing reality account?
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Stefan Esser

19 years ago
> I wonder what do you mean by that - that PHP group should publish > press release "PHP is not secure, please do not use it anymore" or > what? I see PHP group is working quite well eliminating the security > issues. As far as I know, last year there was 7 remotely exploitable > issues in PHP (which is regrettable but that's the way of life to have > bugs), and all of them are fixed, IIRC, and within acceptable > timeframe (the last can be debatable, but PHP being opesource project > the only way to fix it is to get more participation from people in > submitting patches). I know of no remotely exploitable security issue > that is now in current PHP version. > So I wonder what would you like PHP Group to improve? What would you > mean by facing reality - what in your opinion the reality is and what > would you have PHP group to do to satisfy you on facing reality account?
First of all PHP group is doing nothing. Neither do they improve PHP's security nor do they stop well known PHP license abusers (because they are friends). Secondly security patches are done by Ilia and maybe the Zend stuff by Dmitry. All the others are doing nothing in the sense of security. And do I need to remind you about a certain bug in the new super duper Zend Memory manager that results in a far too small buffer being allocated? Do I need to post an exploit that uses this bug to exploit for example the Soap HTTP client from ext/soap? This is a kind of remote exploit against PHP. And god knows how many other places are vulnerable because of the new "improved" Zend Memory Manager. And what about the heap underflow bug in ext/filter... Also not a remote exploit? The fact that you do not know about any remote exploit against PHP is quite irrelevant for reality. Stefan Esser

Jordan Moore

19 years ago
This is pathetic. I thought most of you were adults, but I really can't tell sometimes. Why can't this be discussed without everyone getting upset and snapping at each other? The biggest problem with PHP right now is how thick-headed and cocky some of the posters to this list are. Grow up, and then maybe PHP will have a chance to grow up. It's only taken a couple months to realize how much time is wasted on political crap on this list instead of bug-fixing. On 1/11/07, Stefan Esser <sesser@hardened-php.net> wrote:

Ilia A.

19 years ago
Rather then commenting on what other people should and should not do, do something productive like fix bugs or help to extend the PHP test suit. On 11-Jan-07, at 2:23 PM, Jordan Moore wrote:
> This is pathetic. I thought most of you were adults, but I really > can't tell sometimes. > > Why can't this be discussed without everyone getting upset and > snapping at each other? The biggest problem with PHP right now is how > thick-headed and cocky some of the posters to this list are. Grow up, > and then maybe PHP will have a chance to grow up. > > It's only taken a couple months to realize how much time is wasted on > political crap on this list instead of bug-fixing. > > On 1/11/07, Stefan Esser <sesser@hardened-php.net> wrote: >> >> > I wonder what do you mean by that - that PHP group should publish >> > press release "PHP is not secure, please do not use it anymore" or >> > what? I see PHP group is working quite well eliminating the >> security >> > issues. As far as I know, last year there was 7 remotely >> exploitable >> > issues in PHP (which is regrettable but that's the way of life >> to have >> > bugs), and all of them are fixed, IIRC, and within acceptable >> > timeframe (the last can be debatable, but PHP being opesource >> project >> > the only way to fix it is to get more participation from people in >> > submitting patches). I know of no remotely exploitable security >> issue >> > that is now in current PHP version. >> > So I wonder what would you like PHP Group to improve? What would >> you >> > mean by facing reality - what in your opinion the reality is and >> what >> > would you have PHP group to do to satisfy you on facing reality >> account? >> First of all PHP group is doing nothing. Neither do they improve >> PHP's >> security nor do they stop well known PHP license abusers (because >> they >> are friends). >> Secondly security patches are done by Ilia and maybe the Zend >> stuff by >> Dmitry. All the others are doing nothing in the sense of security. >> >> And do I need to remind you about a certain bug in the new super >> duper >> Zend Memory manager that results in a far too small buffer being >> allocated? >> >> Do I need to post an exploit that uses this bug to exploit for >> example >> the Soap HTTP client from ext/soap? This is a kind of remote exploit >> against PHP. And god knows how many other places are vulnerable >> because >> of the new "improved" Zend Memory Manager. >> >> And what about the heap underflow bug in ext/filter... Also not a >> remote >> exploit? >> >> The fact that you do not know about any remote exploit against PHP is >> quite irrelevant for reality. >> >> Stefan Esser >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
Ilia Alshanetsky

Jordan Moore

19 years ago
That was my intent when I joined the list. I wanted to get a feel for the community and the development process. This is the first open-source project that I've considered contributing to, so it's all new to me. I still plan to dive into it, but it's disheartening to see some of these petty arguments. That is all... Jordan On 1/11/07, Ilia Alshanetsky <ilia@prohost.org> wrote:
> Rather then commenting on what other people should and should not do, > do something productive like fix bugs or help to extend the PHP test > suit. > > On 11-Jan-07, at 2:23 PM, Jordan Moore wrote: > > > This is pathetic. I thought most of you were adults, but I really > > can't tell sometimes. > > > > Why can't this be discussed without everyone getting upset and > > snapping at each other? The biggest problem with PHP right now is how > > thick-headed and cocky some of the posters to this list are. Grow up, > > and then maybe PHP will have a chance to grow up. > > > > It's only taken a couple months to realize how much time is wasted on > > political crap on this list instead of bug-fixing. > > > > On 1/11/07, Stefan Esser <sesser@hardened-php.net> wrote: > >> > >> > I wonder what do you mean by that - that PHP group should publish > >> > press release "PHP is not secure, please do not use it anymore" or > >> > what? I see PHP group is working quite well eliminating the > >> security > >> > issues. As far as I know, last year there was 7 remotely > >> exploitable > >> > issues in PHP (which is regrettable but that's the way of life > >> to have > >> > bugs), and all of them are fixed, IIRC, and within acceptable > >> > timeframe (the last can be debatable, but PHP being opesource > >> project > >> > the only way to fix it is to get more participation from people in > >> > submitting patches). I know of no remotely exploitable security > >> issue > >> > that is now in current PHP version. > >> > So I wonder what would you like PHP Group to improve? What would > >> you > >> > mean by facing reality - what in your opinion the reality is and > >> what > >> > would you have PHP group to do to satisfy you on facing reality > >> account? > >> First of all PHP group is doing nothing. Neither do they improve > >> PHP's > >> security nor do they stop well known PHP license abusers (because > >> they > >> are friends). > >> Secondly security patches are done by Ilia and maybe the Zend > >> stuff by > >> Dmitry. All the others are doing nothing in the sense of security. > >> > >> And do I need to remind you about a certain bug in the new super > >> duper > >> Zend Memory manager that results in a far too small buffer being > >> allocated? > >> > >> Do I need to post an exploit that uses this bug to exploit for > >> example > >> the Soap HTTP client from ext/soap? This is a kind of remote exploit > >> against PHP. And god knows how many other places are vulnerable > >> because > >> of the new "improved" Zend Memory Manager. > >> > >> And what about the heap underflow bug in ext/filter... Also not a > >> remote > >> exploit? > >> > >> The fact that you do not know about any remote exploit against PHP is > >> quite irrelevant for reality. > >> > >> Stefan Esser > >> > >> -- > >> PHP Internals - PHP Runtime Development Mailing List > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > >> > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > Ilia Alshanetsky > > > > >
-- Jordan Moore - Creative Director Sanctus Studios LLC http://sanctusstudios.com (360) 616-4818

Stanislav Malyshev

19 years ago
> First of all PHP group is doing nothing. Neither do they improve PHP's > security nor do they stop well known PHP license abusers (because they > are friends).
OK, that's just not true and it is obvious to anybody with access to the commit logs (namely, everybody) - bugs are getting fixed and improvements are getting done. You may argue they are not enough, but you certainly can not claim that nothing at all is done. As for the alleged license abuse, I am aware of your sensitivity in this regard, however this has nothing to do with the subject of security, so it would be very good if we stick to the subject.
> And do I need to remind you about a certain bug in the new super duper > Zend Memory manager that results in a far too small buffer being allocated?
Actually yes, you do - I don't remember any unfixed bugs in Zend MM, so if you know of an unfixed vulnerability there please do remind about it - preferably through the security list, of course, so all the usual people see it.
> against PHP. And god knows how many other places are vulnerable because > of the new "improved" Zend Memory Manager.
If you have ideas on how to make it work better, you are more than welcome to discuss it. By "discuss" I mean the thing regular people mean - exchange ideas, evaluate their merits and hopefully reach decision that is best for all, not that one participant calls others liars, morons and useless marketing droids, dismisses everything they say as propaganda and refuses to contribute anything. Any discussion in the former sense is more than welcome, if you want to help - you can write your proposals to me, for example. Last time I asked about this I got response in lines of "why should I help?". However, the door is still very much open.
> And what about the heap underflow bug in ext/filter... Also not a remote > exploit?
Again, I was under impression the underflow bug was fixed. If you know about another, unfixed one - please... you know.
> The fact that you do not know about any remote exploit against PHP is > quite irrelevant for reality.
I can't avoid noticing that you forgot to answer my question. To remind, my question was not "is my knowledge seems adequate to you". My question was "what did you mean by recognizing the reality by the PHP group and what do you propose to do". Could you please try again?
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Andi Gutmans

19 years ago
Stefan, do you truly believe that other languages allow for secure shared hosting without using a setuid or chroot solution? I mean take Ruby, Python, Java, C/C++. Can you point out one of them which would not have the issues that PHP has? I think the problem in this case is that shared hosters do not deploy PHP securely. Is this our problem? Yes, I think we need to provide better best practices on how to do it although there is quite a lot of information on the Web on how to do it. In any case, I am planning to write up something more structured so that shared hosters start doing the right thing. The big ones I have worked with actually do have a clue and deploy PHP well. Do we need to provide better tools for our developers? Definitely! This is why we are working on ext/filter (I agree the first pass wasn't very successful), a filter extension in Zend Framework, and other best practices. We have also made significant progress on the core PHP security issues including a coverity code scan (and we are planning to use an additional company), removing flawed features such as register_globals and safe_mode (the latter was never encouraged but I can't blame people for falling into the trap with the crappy name), and many other things. We also have had IBM Research look into various aspects of PHP one of these efforts led to Wietse Venema's suggestion for tainting (which is the main reason why Stefan left the security team as he took that personally because a few years ago he brought up the idea and we weren't in favor). Stefan has a personal vandetta against the PHP Group because we had asked him not to use the PHP brand in the Hardened-PHP patch. This was absolutely not personal but a result of our license. For the same reason Zend does not use PHP in its product names as the PHP license does not allow it. We can not enforce that with projects which are not directly derived from PHP's source code like PHP applications and groups, but Stefan considers we are still following a double standard which we aren't. To be clear, I am not saying PHP doesn't have vulnerabilities. Of course it does. And so do other languages check the bug database of your favorite language and you'll see the segfaults except for languages which don't seem to have an open bug database like Microsoft's and Ruby (I couldn't find the latter). Stefan has actually been very helpful in identifying some of these areas and we have done our best to address them quickly. I hope at some point Stefan is going to channel his knowledge in a more positive way. Andi

Paweł Stradomski

19 years ago
W liście Andi Gutmans z dnia czwartek, 11 stycznia 2007 20:53:
> Stefan, do you truly believe that other languages allow for secure shared > hosting without using a setuid or chroot solution? I mean take Ruby, > Python, Java, C/C++.
It wasn't me who's been asked, but at least for Java, the answer is yes. You can declare privileges for the code based on where it is located (in the filesystem tree). That should be sufficient, if used properly.
-- Paweł Stradomski

Andi Gutmans

19 years ago
How familiar are you with Java in shared hosting environments?

Paweł Stradomski

19 years ago
W liście Andi Gutmans z dnia czwartek, 11 stycznia 2007 21:48:
> How familiar are you with Java in shared hosting environments?
Been hacking one mayor Java app to make it work with JSM. Not much, but I believe Sun took much care to make sure JSM works as advertised.
-- Paweł Stradomski

Stanislav Malyshev

19 years ago
> It wasn't me who's been asked, but at least for Java, the answer is yes. You > can declare privileges for the code based on where it is located (in the > filesystem tree). That should be sufficient, if used properly.
I'm pretty sure these things are not covering, for example, JNI modules. Extensions are basically JNI of PHP.
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Mathieu CARBONNEAUX

19 years ago
>I'm pretty sure these things are not covering, for example, JNI modules. >Extensions are basically JNI of PHP.
i'm not very java fan... but i think majority of java application not use any JNI module... because of this risk and because in majority situation all necesary can be coded and are coded in full java... and only core java runtime are C and some native module like crypto (for SSL)...all major avolution api are coded in full java...only core language are in developped in C... in my java shared hosts, they are no jni... if application need jni they use dedicated machine... but effectively on my php shared hosts i use hardening path + mod_chroot + mod_security like reverse proxy in front (used also with java shared host) + one apache instance with uid by application... but i think some good security idea have been said, for exemple using "prepare statement" to avoid sql injection... also i think is important to educate new php developper in adding more security guide documentation in official manual... Best regards, Mathieu

Stanislav Malyshev

19 years ago
> i'm not very java fan... but i think majority of java application not > use any JNI module... because of this risk and because in majority > situation all necesary can be coded and are coded in full java...
Well, here's the difference - PHP uses it's "JNI" a lot. Thus we can't use same model as Java successfully (safe mode was an attempt to do exactly that and it didn't work very well exactly by this reason).
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

Brian Moon

19 years ago
Mathieu CARBONNEAUX wrote:
> but i think some good security idea have been said, for exemple using "prepare statement" to avoid sql injection...
We really need to stop spreading this myth that prepared statements are a security measure. Prepared statements only allow passing of the value parts of where clauses and a couple of other parts of the query. Limit values would be the most common thing in a query that use variables but are the not allowed to be prepared. I have also seen plenty of applications that use variables for the table names, field names, order by, and other parts. Prepared statements help with none of those. Prepared statements protect very little against sql injection. Making people believe otherwise is dangerous.
-- Brian Moon ------------- http://dealnews.com/ It's good to be cheap =)

Vlad Bosinceanu

19 years ago
It's better than having to deal with sql at a lower level, while not as good as proper training. Which is more likely we will see happening? I really doubt it's the latter. Should PHP babysit the programmer to ensure he dosen't screw up? Not really, IMO. There's good docs available, but what beginners want is a quick glance at the manual resulting in a quick hack - and eventually that's what they end up doing over time, because that's what works for them and does their job. What might help is pushing (via the manual) for the adoption of tools that prevent common problems, with pdo's prepared statements being one such tool. V Brian Moon wrote:

Mathieu CARBONNEAUX

19 years ago
_____ From: Vlad Bosinceanu [mailto:vladb@pseudo-infinity.ro] What might help is pushing (via the manual) for the adoption of tools that prevent common problems, with pdo's prepared statements being one such tool.ok, documenting is what i say... but not all use php5 pdo... not all use php5... many use php4... in some php sql driver implementation have prepare statement... but not all... oci8 has, mysql no...why... in the same idea of the portal (my last post...), the net has many information how to developpe securily but you must search this information... for experienced programmer is not a probleme... but for beginer... where, what to search!!?? if this portal is directly visible from www.php.net is more simple to search... and if this portal link to this information... Regards, Mathieu

Mathieu CARBONNEAUX

19 years ago
_____ From: Brian Moon [mailto:brianm@dealnews.com] We really need to stop spreading this myth that prepared statements are a security measure. Prepared statements only allow passing of the value parts of where clauses and a couple of other parts of the query. Limit values would be the most common thing in a query that use variables but are the not allowed to be prepared. I have also seen plenty of applications that use variables for the table names, field names, order by, and other parts. Prepared statements help with none of those. Prepared statements protect very little against sql injection. Making people believe otherwise is dangerous. Is what i say about security guide is to speak about how to correctly program... And using prepare statement to pass variable by binding variable is simple good programming (and must be used with many other good practice...input check...) And effectively is the variable binding and not the prepare statement that add real security again sql injection... but actualy i've not seen sql variable binding without prepare statement...is why all speak about prepare statement and not variable binding... And generating dynamic (and no variable binding) sql statement in general is not good for performance... because that add cpu and sgbd sql cache consuming... and also for security again sql injection like you say... But using input DIRECTLY for generate sql statement FROM table name... i think is design miss fit... You can developpe protection systeme as you can but without reel developer education... I thing 70% of the security risk can be covered with a good communication... and the rest by the technique... And finaly you connot cover 100% of the risk...but is the problem of all computer system... But is my think about that... why not construct wiki/portal site structured on the different aspect of good secured php programing ? with forum !? Best Regards, Mathieu

Brian Moon

19 years ago
> And using prepare statement to pass variable by binding variable > is simple good programming (and must be used with many other good > practice...input check...) > And effectively is the variable binding and not the prepare > statement that add real security again sql injection... > but actualy i've not seen sql variable binding without prepare > statement...is why all speak about prepare statement and not > variable binding...
I do not dispute that variable binding can help with some issues of sql injection. But, it does not do as much as some would have you believe. I have read statements like "Prepared statement are generally immune to SQL Injection" and worst of all "I am using prepared statements to be sure that my application are not vulnerable to sql injection attacks" A quick google search for 'sql injection prepared statements' found those 2 statements (1 is a security article) very quickly. That is the message that users are getting about prepared statements. Its simply not a good message. That is my point. The PHP manual nor the MySQL manual mentions sql injection when talking about prepared statements. And frankly, its not the manual's job to tell you how to write secure code. So, this has to be coming from people.
> And generating dynamic (and no variable binding) sql statement in > general is not good for performance... because that add cpu and > sgbd sql cache consuming...
Are you saying that filling a variable into a string is slower than calling a function with an array to generate a sql statement? I don't think so. If you know of such a variable binding library in PHP, please hook me up. I will start using it tomorrow. And, as you said, variable binding has only been used in PHP with prepared statements. Unless you reuse a statement, you loose performance every time you prepare a statement. So, IMO, there is no performance gain either with prepared statements/variable binding for normal, one time use queries.
-- Brian Moon ------------- http://dealnews.com/ It's good to be cheap =)

Tim Starling

19 years ago
Brian Moon wrote:
> Mathieu CARBONNEAUX wrote: >> but i think some good security idea have been said, for exemple using >> "prepare statement" to avoid sql injection... > > We really need to stop spreading this myth that prepared statements are > a security measure. Prepared statements only allow passing of the value > parts of where clauses and a couple of other parts of the query. Limit > values would be the most common thing in a query that use variables but > are the not allowed to be prepared. I have also seen plenty of > applications that use variables for the table names, field names, order > by, and other parts. Prepared statements help with none of those. > Prepared statements protect very little against sql injection. Making > people believe otherwise is dangerous. >
Limits, table names, and several other query parts are protected by MediaWiki's query builder. A complex select query might look like this: $result = $db->select( # Tables array( 'user', 'revision' ), # Fields array( 'user_name', 'rev_timestamp' ), # Conditions (WHERE) array( 'user_id=rev_user', 'rev_page' => $page_id ), # Query tag, goes into a comment in the SQL __METHOD__, # Options array( 'LIMIT' => 10, 'ORDER BY' => 'rev_timestamp DESC', ) ); It even has some degree of DBMS-independence, thanks to creative interpretation of the options parameter. This is what I would like to see in the PHP core. -- Tim Starling

Robert Cummings

19 years ago
On Fri, 2007-01-12 at 15:57 +0000, Tim Starling wrote:
> > Limits, table names, and several other query parts are protected by > MediaWiki's query builder. A complex select query might look like this: > > $result = $db->select( > # Tables > array( 'user', 'revision' ), > # Fields > array( 'user_name', 'rev_timestamp' ), > # Conditions (WHERE) > array( > 'user_id=rev_user', > 'rev_page' => $page_id > ), > # Query tag, goes into a comment in the SQL > __METHOD__, > # Options > array( > 'LIMIT' => 10, > 'ORDER BY' => 'rev_timestamp DESC', > ) > ); > > It even has some degree of DBMS-independence, thanks to creative > interpretation of the options parameter. This is what I would like to see > in the PHP core.
Wow, that's hideous! Cheers, Rob.
-- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

Mathieu CARBONNEAUX

19 years ago
>Limits, table names, and several other query parts are protected by >MediaWiki's query builder. A complex select query might look like this: > >$result = $db->select( > # Tables > array( 'user', 'revision' ), > # Fields > array( 'user_name', 'rev_timestamp' ), > # Conditions (WHERE) > array( > 'user_id=rev_user', > 'rev_page' => $page_id > ), > # Query tag, goes into a comment in the SQL > __METHOD__, > # Options > array( > 'LIMIT' => 10, > 'ORDER BY' => 'rev_timestamp DESC', > ) >); > >It even has some degree of DBMS-independence, thanks to creative >interpretation of the options parameter. This is what I would like to see >in the PHP core. > >-- Tim Starling
the only security risk is $page_id and is variable... with prepare statement can be binded...

Stefan Esser

19 years ago
Andi,
> Stefan, do you truly believe that other languages allow for secure shared hosting without using a setuid or chroot solution? I mean > take Ruby, Python, Java, C/C++. Can you point out one of them which would not have the issues that PHP has? I think the problem in >
How it the fitness of other languages relevant for the security holes in PHP. What have other languages todo with the POOR quality of PHP's C source code? Unlike other languages PHP claims to have functions like disable_functions / open_basedir / safe_mode. They are however worth NOTHING, because there are so many local vulnerabilities in PHP that every attacker can just choose one and execute any code he wants anyway.
> Do we need to provide better tools for our developers? Definitely! This is why we are working on ext/filter (I agree the first pass > wasn't very successful), a filter extension in Zend Framework, and other best practices. >
Stop blaming PHP users. Of course a lot of them are not skilled and do error. This is however completely unrelated to the POOR quality of PHP's C source code.
> We have also made significant progress on the core PHP security issues including a coverity code scan (and we are planning to use an > additional company), removing flawed features such as register_globals and safe_mode (the latter was never encouraged but I can't >
You cannot achieve security with tools. Coverity has obviously not found a single of the vulnerabilities I disclosed. They are worthless. You cannot improve security with tools.
> blame people for falling into the trap with the crappy name), and many other things. We also have had IBM Research look into various > aspects of PHP one of these efforts led to Wietse Venema's suggestion for tainting (which is the main reason why Stefan left the > security team as he took that personally because a few years ago he brought up the idea and we weren't in favor). >
Andi your propaganda is getting old. First of all I never brought up the taint mode idea. I simply started an implementation for HPHP and told security@php.net that I think I should continue to work on it before you have yours ready. The fact that someone brought it up in the past is completely unrelated to me. The fact that I was immediately attacked by Zend after telling security@php.net about this plan was just one more drop. I left the PHP Security Response Team, because you do not listen, because you think you know everything better, because you believe the PHP community is full of security heroes. I had enough of this. I strongly disagree and I see no reason to be part of a "security team" that has actually no clue. And I also had enough from the countless attacks from other PHP developers that want me dead, call me immoral traitor, ...
> Stefan has a personal vandetta against the PHP Group because we had asked him not to use the PHP brand in the Hardened-PHP patch. >
Vendetta yourself. Unlike your silly accusations my vulnerability reports are based on facts.
> PHP license does not allow it. We can not enforce that with projects which are not directly derived from PHP's source code like PHP > applications and groups, but Stefan considers we are still following a double standard which we aren't. >
You are following a double standard. A project that steals CSS source code from the PHP source and uses it in a PHP application to mimic the phpinfo() look has stolen code licensed under the PHP license. It cannot have the name PHP in it's name. But we all know that Shiflett is your close friend... Nothing more has to be said.
> I hope at some point Stefan is going to channel his knowledge in a more positive way. >
Andi grow up. Who do you want to trick with these closing words? A lot of people know WHO improved the security of PHP during the last years. If that is not a positive thing I really don't know. Stefan Esser

Zeev Suraski

19 years ago
Stefan, I'll concentrate on the technology aspect. The situation in other languages has everything to do with PHP. It's fine that you decided to concentrate in PHP, but the fact exactly the same problem exists in other languages suggests it's an inherent problem, and not something unique to PHP. In my opinion, it's also something that cannot be solved. We can't treat hundreds of thousand of lines of code, some of it generated code that we can't even fully validate, as 100% security sensitive. After you left and started sending local exploits (with a few being remotely exploitable, but most of them not), I looked at it as some sort of a wakeup call. Not that they existed - it's pretty clear that a project the size of PHP contains crash bugs both in PHP's code and 3rd party libraries that it uses, especially when you're intentionally trying to use it in ways that it was not intended to be used in order to crash it. The wakeup call was that we did not sufficiently message the fact that languages cannot be trusted to local users unless you use OS level protection a-la chroot/suexec or a VPS, and PHP is certainly no exception. There was a heated discussion about that topic in the security mailing list, which at this point has not concluded in a meaningful way. My take on this is that we should shout as much as we possibly can - "DO NOT TRUST PHP (OR ANY OTHER LANGUAGE) TO LOCAL USERS WITHOUT OS LEVEL PROTECTION". Protecting PHP from malicious local hackers is futile, just as it is futile to protect any other language from local exploits. safe_mode, open_basedir and the likes are inherently flawed since they protect at the wrong level. They cannot be fixed, they are inherently prone to bugs - and every tiny bug immediately becomes a security bug. disable_functions must also not be used as a security feature but as an administrative feature, since again, a determined hacker will always be able to find an exploitable crash bug. The right solution is to deprecate safe_mode and open_basedir and make it clear what the purpose of disable_function is. To be clear, otherwise-local exploits which are very commonly found in remotely-triggerable code should be considered as remote exploits and dealt with quickly. To be also clear, we all value the work you've been doing auditing PHP code. I'd still like to grab a beer together with you in a couple of weeks' time when I'm in Germany if you're around. Zeev At 22:20 11-01-07, Stefan Esser wrote:

Pierre Joye

19 years ago
Hello Andi, On 1/11/07, Andi Gutmans <andi@zend.com> wrote:
> Do we need to provide better tools for our developers? Definitely! This is why we are working on ext/filter (I agree the first pass > wasn't very successful), a filter extension in Zend Framework, and other best practices.
What do you mean? Having bugs in the first release is a sign of failure? Or the complete lack of feedbacks before 5.2.0 was the cause? I would love to hear your opinion on what we made wrong. I really dislike to read that here and now, given the huge amount of calls for feedbacks/tests I made before 5.2.0-final. One solution to solve this problem is to release more often through PECL (it works for zip and my other extensions). About the Zend Framework, what does it have to do with PHP internal choices? In my opinion nothing, or not more/less than any other frameworks or application out there. If ext/filter needs to be improved to fit your needs, please tell us. --Pierre

Ilia A.

19 years ago
On 11-Jan-07, at 9:41 AM, Alain Williams wrote:
> This has just appeared: > > http://www.theregister.co.uk/2007/01/11/php_apps_security/
Of many people who use PHP not many have strong programming background and even fewer experience with security. The use PHP because it makes it easy to solve problems, especially in a web environment. When you consider this it is hardly surprising that many people write bad and/or insecure code. While PHP does try to make things better, and occasionally has bugs in the language core you need to realize that PHP is a programming language. As such if you really want to shoot yourself in the foot you can, just as you can do with C/C++/Perl/Python/etc... Ilia Alshanetsky

Alain Williams

19 years ago
On Thu, Jan 11, 2007 at 12:05:45PM -0500, Ilia Alshanetsky wrote:
> > On 11-Jan-07, at 9:41 AM, Alain Williams wrote: > > >This has just appeared: > > > > http://www.theregister.co.uk/2007/01/11/php_apps_security/ > > Of many people who use PHP not many have strong programming > background and even fewer experience with security. The use PHP > because it makes it easy to solve problems, especially in a web > environment. When you consider this it is hardly surprising that many > people write bad and/or insecure code. While PHP does try to make > things better, and occasionally has bugs in the language core you > need to realize that PHP is a programming language. As such if you > really want to shoot yourself in the foot you can, just as you can do > with C/C++/Perl/Python/etc...
I think that everyone would agree with that. The discussion is how PHP can help them to discover problems in their scripts. This is what led to Wietse Venema's suggestion about tainting a few weeks ago. These may be things that members of this forum do not feel that they need, but the ''quality'' of the majority of PHP programmers is such that they would be of benefit. To an extent it is an accolade to PHP that novice/... programmers can use it do create applications, it just puts a greater burden on us to do what we can to protect them from their own problems.
-- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Ilia A.

19 years ago
On 11-Jan-07, at 12:11 PM, Alain Williams wrote:
> The discussion is how PHP can help them to discover problems in their > scripts. This is what led to Wietse Venema's suggestion about tainting > a few weeks ago. These may be things that members of this forum do not > feel that they need, but the ''quality'' of the majority of PHP > programmers is such that they would be of benefit. > > To an extent it is an accolade to PHP that novice/... programmers can > use it do create applications, it just puts a greater burden on us > to do > what we can to protect them from their own problems.
The tools already exist, look at E_NOTICE for example. A good number of PHP exploits are caused by register_globals + un-initialized vars. If the developers of those apps tried to run their code with that error reporting method enabled there would be far fewer security bugs all around. Ilia Alshanetsky

Alain Williams

19 years ago
On Thu, Jan 11, 2007 at 12:26:17PM -0500, Ilia Alshanetsky wrote:
> > On 11-Jan-07, at 12:11 PM, Alain Williams wrote: > >The discussion is how PHP can help them to discover problems in their > >scripts. This is what led to Wietse Venema's suggestion about tainting > >a few weeks ago. These may be things that members of this forum do not > >feel that they need, but the ''quality'' of the majority of PHP > >programmers is such that they would be of benefit. > > > >To an extent it is an accolade to PHP that novice/... programmers can > >use it do create applications, it just puts a greater burden on us > >to do > >what we can to protect them from their own problems. > > The tools already exist, look at E_NOTICE for example. A good number > of PHP exploits are caused by register_globals + un-initialized vars. > If the developers of those apps tried to run their code with that > error reporting method enabled there would be far fewer security bugs > all around.
E_NOTICE flags up attempts to use an uninitialised variable, it is not helpful if you assign to a typeo. This people do and can be hard to find, especially if it is not in an often used code path.
-- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Derick Rethans

19 years ago
On Thu, 11 Jan 2007, Alain Williams wrote:
> On Thu, Jan 11, 2007 at 12:26:17PM -0500, Ilia Alshanetsky wrote: > > > > On 11-Jan-07, at 12:11 PM, Alain Williams wrote: > > >The discussion is how PHP can help them to discover problems in their > > >scripts. This is what led to Wietse Venema's suggestion about tainting > > >a few weeks ago. These may be things that members of this forum do not > > >feel that they need, but the ''quality'' of the majority of PHP > > >programmers is such that they would be of benefit. > > > > > >To an extent it is an accolade to PHP that novice/... programmers can > > >use it do create applications, it just puts a greater burden on us > > >to do > > >what we can to protect them from their own problems. > > > > The tools already exist, look at E_NOTICE for example. A good number > > of PHP exploits are caused by register_globals + un-initialized vars. > > If the developers of those apps tried to run their code with that > > error reporting method enabled there would be far fewer security bugs > > all around. > > E_NOTICE flags up attempts to use an uninitialised variable, it is not > helpful if you assign to a typeo. This people do and can be hard to find, > especially if it is not in an often used code path.
That is why there is a concept called "testing" [1] and code coverage [2]. [1]. http://phpunit.de/ [2]. http://sebastian-bergmann.de/archives/578-Code-Coverage-Reports-with-PHPUnit-3.html regards, Derick

Alain Williams

19 years ago
On Thu, Jan 11, 2007 at 06:44:35PM +0100, Derick Rethans wrote:
> That is why there is a concept called "testing" [1] and code coverage > [2]. > > [1]. http://phpunit.de/ > [2]. http://sebastian-bergmann.de/archives/578-Code-Coverage-Reports-with-PHPUnit-3.html
You are an experienced and careful programmer, that is why you understand the value of doing this sort of thing. The trouble is that most PHP programers are not experienced and/or careful ... that is *why* many PHP scripts have nasty bugs in them. As I said: we are looking at ways of helping the sort of person who would not come near this mail list.
-- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Ilia A.

19 years ago
On 11-Jan-07, at 12:53 PM, Alain Williams wrote:
> On Thu, Jan 11, 2007 at 06:44:35PM +0100, Derick Rethans wrote: > >> That is why there is a concept called "testing" [1] and code coverage >> [2]. >> >> [1]. http://phpunit.de/ >> [2]. http://sebastian-bergmann.de/archives/578-Code-Coverage- >> Reports-with-PHPUnit-3.html > > You are an experienced and careful programmer, that is why you > understand the value > of doing this sort of thing. The trouble is that most PHP > programers are > not experienced and/or careful ... that is *why* many PHP scripts > have nasty bugs in > them. > > As I said: we are looking at ways of helping the sort of person who > would not > come near this mail list.
Uhm those are PHP tools for PHP code, what do they have to do with internals. Rather then whining about "if I only had tool XYZ" use what's already widely available. Ilia Alshanetsky

Tim Starling

19 years ago
Ilia Alshanetsky wrote:
> > On 11-Jan-07, at 9:41 AM, Alain Williams wrote: > >> This has just appeared: >> >> http://www.theregister.co.uk/2007/01/11/php_apps_security/ > > Of many people who use PHP not many have strong programming background > and even fewer experience with security. The use PHP because it makes it > easy to solve problems, especially in a web environment. When you > consider this it is hardly surprising that many people write bad and/or > insecure code. While PHP does try to make things better, and > occasionally has bugs in the language core you need to realize that PHP > is a programming language. As such if you really want to shoot yourself > in the foot you can, just as you can do with C/C++/Perl/Python/etc...
This is exactly what the article said. "PHP shouldn't be blamed for its popularity, so I don't want readers to get the wrong idea. Many lower level languages like C/C++ are even more popular and give developers far more rope to hang themselves than PHP. Therefore, there are other issues at play. "Applications written in every language can, will, and have had a myriad of security vulnerabilities over the years. It doesn't matter if it's C++, Perl, ASP, Visual Basic, Python, or Ruby and Ruby on Rails. [...] "I have no doubt that some PHP Group developers shake their head at the very basic security mistakes that many new programmers make. The problems are all over the web. They're user issues, so they probably don't concern themselves with them. But they should. [...] "I'm not saying the PHP Group is responsible, but they could help. As architects of the language they should consider ways of hardening the language and its defaults against some of the real basic mistakes so many people are making." The developers of the major PHP applications have to take some responsibility as well. A sysadmin once told me "I'd disable register_globals but the users complain that their applications break". No doubt it's a common story. Mark Krenz makes the same argument about safe mode. It can be difficult to make things work in safe mode, open_basedir is much easier and probably more secure. Magic quotes are a nuisance for programmers at any level, definitely a misfeature. The best way to avoid SQL injection is to use a query builder, like we do in MediaWiki. PHP should have one built in. Prepared statements, as in PDO, are a useful step in the right direction. Shell escaping could be handled in a similar way. PHP does not even have a working cross-platform shell escaping function. I would like to see spawnlp-style functions in PHP -- you can't have shell injection when you don't use the shell. The situation with HTML injection (XSS) is much the same. The historic lack of HTML construction functions means that programmers put the strings together themselves, often not bothering to escape user input. An HTML construction library which makes a clear distinction between HTML and text input would go some way towards solving this, if it was promoted well enough. Maybe DOM does this already, I'll tell you once I manage to comprehend the documentation. It's certainly more verbose than the equivalent in Perl. Over and over, we see security vulnerabilities introduced due to the manipulation of text-like protocols using string concatenation and interpolation. The solution is to handle each and every one as a protocol, not as a string. -- Tim Starling