Quote from: lizardx at Dec 09, 2008, 09:42 PM
I suggest you do a review of your methods, if code like this was in that file, I assume there’s more hidden all over the place.
I agree about reviewing the method of including sample snippet code as .php files, since they should never be executed that way. But the solution is as simple as renaming any such files with a .txt extension. When this code is executed in its proper context, the code that you suggest would be redundant and unnecessary.
Quote from: lizardx at Dec 09, 2008, 09:42 PM
It’s not just the sanitization question, it’s allowing code like this in at all, in the first place, which does nothing but hide errors.
Ternary operators don’t "hide" anything; they just make your code more concise. Some people like them, some people don’t. But they’re no different than an if/else statement.
Quote from: lizardx at Dec 09, 2008, 09:42 PM
Again, relying on server settings that are not under your control rather than making your code secure, which is under your control, guarantees hacks for the life of your software.
Again, you’re missing the point here. This code is not a part of the MODx system (it’s not an file included by some other script), and it is not insecure when run in its proper context (as a snippet stored in the database). As long as it is not uploaded as an executable .php file, it is not a security risk as is.
So on that point we agree: It should not have been included in the MODx package with a .php extension. The solution is not, however, to harden this file so that it can withstand attacks in a context that it was never intended to be used and on an insecure server. The solution is as simple as renaming or deleting the file.
Note that I’m not saying that the file should be left as is; it should be renamed or deleted.
I don’t think that any major PHP software should ever be run with register_globals set to ON. There’s no realistic way to audit every line of code for possible XSS vulnerabilities in a system this complex given that quite a number of code libraries written by other teams are integrated into it and updated frequently. If there’s one possible exploit in one included file in the latest version of TinyMCE, for example (not to give them a bad name, of course), then your whole system can be compromised.
Leaving register_globals set to ON is as irresponsible as setting the permissions of PHP files to 777, and setting it to OFF protects you from this entire class of attacks.
So there are two proactive lessons here from my point of view: Don’t distribute code samples that are not meant to be executed as PHP files with a .php extension, and make the warnings about register_globals being set to ON much more dramatic so that people take them seriously (or perhaps even disable the system until it’s corrected).