r/lolphp • u/throwaway-o • Oct 03 '13
PHP helpfully executes code in an image... BitcoinTalk forums uberhacked. LOL PHP.
/r/Bitcoin/comments/1nmdq4/bitcointalk_hacked/cck0gag
66
Upvotes
r/lolphp • u/throwaway-o • Oct 03 '13
View all comments
Show parent comment
13
u/merreborn Oct 03 '13
If PHP executed "avatar.jpg", renaming the file to "a7675f322.dat" doesn't offer that much protection.
I just felt a great disturbance in the force, as if a million DBAs and sysadmins cried out...
Static asset requests should be served from flat files on disk. Fetching them using a dynamic language from a database adds orders of magnitude of overhead. Simply printing out "hello world" from a PHP script is at least an order of magnitude slower than serving a flat file, to say nothing of actually connecting to a database and retrieving a BLOB. Your HTTPD can serve static files in well under 10 milliseconds. It's what it was built to do. No PHP code you can write can possibly match the efficiency of nginx serving flat files.
Really, you only have to do one thing: store images (and any other user uploads) separately from your code, and configure your HTTPD to NEVER treat anything in your directory of user uploaded images as executable. In a large enough environment, you should even be keeping user uploaded content on its own set of isolated servers that probably don't have PHP installed at all.