Re:A file that's both an acceptable HTML page and a JPEG (vi...
by crazygringo on Friday July 06, 2012 @04:20PM
(#4209453)
But almost any site will be sending the image along with a Content-type header, so your browser would still open it up as an image, not an HTML page with JavaScript? Or no?
[ Parent
| on HN ]
Re:A file that's both an acceptable HTML page and a JPEG (vi...
by daeken on Friday July 06, 2012 @04:22PM
(#4209464)
If you can control the filename, you can do things like embed <?php something_malicious(); ?> into an image, put it up as foo.jpg.php, and then execute it by hitting the 'image' directly. That's... sadly common.
Re:A file that's both an acceptable HTML page and a JPEG (vi...
by mkopinsky on Friday July 06, 2012 @07:17PM
(#4210047)
Filename validation, I would imagine, is far more common than content validation.
If you are inspecting binary data for validity, and not checking the parameter (filename) that affects how Apache serves your file, you are doing something wrong.
Re:A file that's both an acceptable HTML page and a JPEG (vi...
by lucb1e on Saturday July 07, 2012 @05:32PM
(#4212794)
Checking a filename may leave bugs to exploit. It's quite unlikely, but why break your head over a possible way to exploit your validation when you can just rename the file to something of your liking? Check the file for a png, jpg, etc. header, append that as extension (erroring when none was found), and done; no risk of it being executed.
Re:A file that's both an acceptable HTML page and a JPEG (vi...
by navytank on Saturday July 07, 2012 @10:21PM
(#4213355)
You'd think this would be enough protection, but it turns out that some browsers (looking at you, IE) actually try to infer the content type from the page content. See http://msdn.microsoft.com/en-us/library/ms775147(v=vs.85).as... for more info.