Sigh… I hate it when people who do not understand the first thing about something spread misinformation about it with an air of authority. I strongly believe in Socrates' words "for what I don't know know, I don't think I know it either". In other words, if you don't fully understand what you're talking about it's best to say so and shut up than pretend you're wise beyond your knowledge.
Apache and Lightspeed have not had that problem for a very long time. They will not execute files whose extension does not end with .php
, regardless of what the URL path and query is. Unlike NginX, Apache handles PHP files based on the name of the actual file on disk, not the URL. Moreover, the caveat of accidentally allowing files with double extensions to be executed as PHP has been known and documented since 2001, long before NginX even existed.
Here's how Apache is configured to run PHP files, using Apache's <FilesMatch> directive. Remember that it operates based on the location and file name of the actual file on disk, not what you put in the URL. It normally looks like this:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
The line between the two tags of the directive may be different and depends on the server configuration and the PHP SAPI being used. The above example is typical when using PHP as an Apache module (mod_php). When using PHP through PHP-FPM (PHP FastCGI Process Manager) it looks more like this SetHandler "proxy:fcgi://127.0.0.1:9082/"
. But that's not the important part.
The important part is the first line, the part I put in bold type. It is a regular expression which is matching file names. The Regular Expression \.php$
means "anything whose filename ends with .php matched exactly and case-sensitive". A file named foobar.php.png
does not fulfil this criterion because its filename ends .php.png, not .php.
If you have a URL like https://www.example.com/images/foobar.php.png/foo.php
Apache follows the path and sees that while images/foobar.php.png
is a real file, images/foobar.php.png/foo.php
is not. It will throw a 404. If you have a URL like https://www.example.com/images/foobar.php.png?foo.php
Apache looks for the file in the path, i.e. images/foobar.php.png
. Since its filename ends in .php.png, NOT .php, it is not executed by PHP. It is served verbatim with the MIME type image/png. The browser cannot decode this as a PNG image and shows the "broken / missing image" icon in its place. Therefore, no matter what you do, files with double extensions cannot execute as PHP.
A server would only be vulnerable to what the person on the forum said, executing files with double extensions, if the server administrator was a moron and instead of the above typed this:
<FilesMatch \.php>
SetHandler application/x-httpd-php
</FilesMatch>
This is idiotic. The Regular Expression .php means "anything that has the string literal .php anywhere in its name". This matches foobar.php
, foobar.php.png
as well as foobar.phpversion.txt
. This is a security violation.
The last time I saw a server with this kind of crappy configuration was back in 2003. There was explicit warning against doing that as far back as 2001. If someone is on a server run by a person who does not understand how Apache works and has managed to somehow not read about this explicit warning for over 20 years I would posit that this would be the least of their security worries. I would be extremely worried about the overall security of the server and I'd run away to a host who actually understands how hosting works!
If you want to test if your host is a moron you need to run away from you can do it very simply. Create a file named test.php.txt
with the following content:
<?php phpinfo();
If this is a new, empty site, upload it to the site's root and access it, e.g. https://www.example.com/test.php.txt
.
If it is an existing Joomla site, upload it into the images
folder (using SFTP, or your host's file manager) and access it, e.g. https://www.example.com/images/test.php.txt
.
If you see the literal <?php phpinfo();
content you're all good. Breathe.
If, however, you see PHP's status page listing the PHP version and enabled PHP extensions you have an affected host run by a moron. In this case, run away. Move to a different host as fast as you can. If the host has not figure out how to make PHP run correctly, chances are they are unable to run a secure server at all.
Knowledge is power. Knowing how things work allows you to worry about real threats, not imaginary threats. Expending energy on imaginary threats is unproductive, and distracts you from the real threats you need to concern yourself with. You are French. You know all about the Maginot line and how one man's obsession with an imaginary threat handed over France on a plate to the Axis forces. Therefore, you surely understand what I mean here :)
Nicholas K. Dionysopoulos
Lead Developer and Director
🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!