Search code examples
phpimageurlfile-extensionbrowser-security

Do some browsers ignore image URLs with non-image (i.e. script) extensions?


I read that extensionless image URLs are generally acceptable with the correct content-type header set.

However, if a script generates image output and sets the content type, but the URL in the image tag is .php for instance, will any browser deny the request as potentially malicious?

For instance:

<?php
// myimage.php
header( 'Content-Type: image/jpeg' );
echo read_file_contents( 'someimage.jpg.in' );

and

<img src="myimage.php" />

Solution

  • No - a browser will not deny the request as potentially malicious.

    A response header defining the content type is important for this approach.

    Two examples: