News for hackers. Stuff that matters.
Re:I think tumblr has a huge security hole by zaidf on Saturday March 19, 2011 @08:04AM (#2343388)
I understand that view.

But I am talking specifically about something that would just dump the code of the php file to the browser.

Re:I think tumblr has a huge security hole by Maxious on Saturday March 19, 2011 @08:25AM (#2343418)
I think this was more of a systemic failure - the file that failed in this case was also relied upon to disable development mode/error output on production servers. I'm pretty sure my production web servers return a HTTP code 500 with no further output when they encounter an error with the php.ini-production configuration file provided in the PHP source distribution.

The hitch was of course that the file in question had a "i?php" (someone was using vi and hit i too many times?) instead of "<?php" which lead the php interpreter to output that section of code as if it were HTML. That feature is something PHP could provide an option to disable and only allow explicit echo/print/printf which should be what templating engines use.

Re:I think tumblr has a huge security hole by KevBurnsJr on Saturday March 19, 2011 @10:56AM (#2343727)
Actually, PHP returns a 200 when it encounters a fatal error.

This explains why it was indexed by Google.

Re:I think tumblr has a huge security hole by yrashk on Saturday March 19, 2011 @08:06AM (#2343391)
they just had a single typo i?php instead of <?php I guess somebody's using vim
Re:I think tumblr has a huge security hole by russss on Saturday March 19, 2011 @09:13AM (#2343509)
At Last.fm we had a Subversion pre-commit hook which ensured that all .php files began with <?.

That would have easily caught this problem, no drama.

Re:I think tumblr has a huge security hole by SoftwareMaven on Saturday March 19, 2011 @05:54PM (#2344848)
Unless the file was checked in separately. If they were doing something like updating the db password, so they need to update "current running" and "up-and-coming" code. As a result, they may have made the change in production, with the typo, and the change in SVN, without the typo.

I would put my money on something like this being the cause.

Re:I think tumblr has a huge security hole by KevBurnsJr on Saturday March 19, 2011 @09:21AM (#2343519)
+1 to russ. PHP syntax checking on precommit would have caught this.

Edit: I'm wrong. It does not catch this.

Re:I think tumblr has a huge security hole by zaidf on Saturday March 19, 2011 @10:12AM (#2343615)
Not necessarily. Makes sense for syntax check to only check between php tags.

Root of the issue is that by default php outputs anything not between php tags to the browser.

Perhaps some sort of buffer control at the top most include can disable output to browser until a later time. That's pretty much how templating systems work except they don't disable output afaik thus leaving possibility of this open.

Re:I think tumblr has a huge security hole by bluesnowmonkey on Saturday March 19, 2011 @12:23PM (#2343949)
Exactly right. There's no reason for a config file (or any of the setup code) to be writing output. A good way to force this is by immediately starting an output buffer with a callback that returns nothing, then calling ob_end_clean() after setup is complete.
Re:I think tumblr has a huge security hole by dexen on Saturday March 19, 2011 @10:19AM (#2343636)
You could do ob_start(); include '...'; ob_end_clean();, but it turns out that die() (say, in a custom error handler) () causes an implicit buffer flush. So it's not a foolproof solution.
Re:I think tumblr has a huge security hole by bluesnowmonkey on Saturday March 19, 2011 @12:28PM (#2343965)
You can attach a callback to the buffer to prevent that implicit flush.

    ob_start(function() {});
Re:I think tumblr has a huge security hole by dexen on Saturday March 19, 2011 @12:52PM (#2344044)
Thanks, I'll investingate and probably adopt it for my code :D
Re:I think tumblr has a huge security hole by KevBurnsJr on Sunday March 20, 2011 @04:56AM (#2345877)
Or register_shutdown_function - http://blog.kevburnsjr.com/php-fatal-error-500
Re:I think tumblr has a huge security hole by dexen on Saturday March 19, 2011 @10:22AM (#2343643)
No chance. The problem was a missing <?php tag -- PHP syntax cheching would NOT have raised alarm, because everything before a <?php tag is not considered PHP.

Forcing every file to start with <?php is just PITA for developers working on templates.

Re:I think tumblr has a huge security hole by russss on Saturday March 19, 2011 @01:20PM (#2344115)
> Forcing every file to start with <?php is just PITA for developers working on templates.

Yep, our templates were .tpl files, which is probably a good convention to have even if you use raw PHP as your templating language.

But you get the drift. This is something you have to deal with when you use PHP.

Re:I think tumblr has a huge security hole by bluesnowmonkey on Saturday March 19, 2011 @12:13PM (#2343919)
If the templates are raw PHP, yeah. Constructing HTML in code like that is a PITA and a recipe for errors and XSS vulnerabilities. It's common to use templating engines like Smarty or Mustache. In that case, you can standardize on PHP files starting with an opening tag and having no closing tag. Then syntax checking is a piece of cake.
Re:I think tumblr has a huge security hole by dexen on Saturday March 19, 2011 @12:50PM (#2344034)
After using eZ Publish with its templating language (also implemented in PHP) for about a year, I've found `raw' PHP just more expressive and concise -- and my team, coming from various backgrounds, has that preferrence as well.

Whaddya know, PHP is a templating language, after all.

Also, it takes us less effort to ship product that matches performance requirements with `raw' PHP than with another layer of abstraction.

Re:I think tumblr has a huge security hole by jarin on Saturday March 19, 2011 @08:20AM (#2343405)
That's why I always git diff and run tests before committing, I do that all the time :-/
Re:I think tumblr has a huge security hole by drdaeman on Saturday March 19, 2011 @08:42AM (#2343449)
And this is the reason one should separate production and development environments and NEVER edit any files on production servers (let `git push` or something similiar handle it)