Moving a config file outside of the web root can prevent this file from getting leaked if you accidentally mis-configure apache. For instance if you remove Apache's mod_php
then all .php files will be treated as text files. I have seen config files moved outside of the web root on production systems for this reason, and it did stop the file from getting leaked! (An admin iced the config during an update, doah!). Although this doesn't happen very often.
If an attacker can control the path of one of these functions: file_get_contents()
, fopen()
, readfile()
or fgets()
then he can read any file on your system. You also have to worry about sql injection. For instance this query under MySQL can be used to read files: select load_file("/etc/passwd")
.
To mitigate this issue, remove FILE
privileges from your MySQL user account that PHP uses. Also do a chmod 500 -R /path/to/web/root
, The last 2 zeros keeps any other account from accessing the files. You should also follow it up with a chown www-data -R /path/to/web/root
where www-data is the user account that php is executed as, you can figure this out by doing a <?php system('whoami');?>
.