Common Apache Misconception

Published: 2009-04-07
Last Updated: 2010-10-08 10:22:30 UTC
by Johannes Ullrich (Version: 1)
3 comment(s)

Thanks to fellow handler Jason for reminding me about the following common Apache misconception. This is not an Apache bug, or a misconfiguration per se. It is more an error of the operator not to read the manual.

In order to use PHP, or other modules in Apache, you typically use a configuration directive like:

LoadModule php4_module modules/ 
AddType application/x-httpd-php .php

The misconception is about the ".php" part. Many, even experienced, Apache administrators believe that this will enable the PHP module for all files ending in ".php". Close, but wrong. It will enable php for all files that contain .php. For example, test.php.1 will be parsed using php, or something.php.bak. At first, this is actually a good thing. the .bak file will not leak source code. However, the issue becomes a very bad thing if you allow users to upload files. Now it is no longer sufficient to test if the extension is .php. A users could upload test.php.gif and the file would still be parsed by PHP.

This brings me to my checklist about how to upload files:

  • do not use the user provided filename, come up with your own random / artificial filename.
  • upload the files into one directory only, which is outside the DocumentRoot.
  • carefully validate that the mime type provided by the user matches the mime type received.
  • to retrieve the file, use a wrapper page (which can then also do access control).
  • establish maximum file sizes and enforce them on the server.
  • avoid anonymous uploads if you can.
  • use AV scanners to check the file before you allow access ot the file.

(there is a section about this in my php course).

also see:

Johannes B. Ullrich, Ph.D.
SANS Technology Institute    - twitter:

3 comment(s)


How do you \"use AV scanners to check the file before you allow access ot the file.\", via command line on the FreeBSD server or is this done locally prior to uploading?
Could you use ClamAV?
The mod_mime docs also suggest that a FilesMatch stanza can be used in place of AddType to restrict mappings to (eg) the final extension only:

Diary Archives