tags:

views:

66

answers:

3

I've got a "globabVars.php" doc in my own little framework that contains database connection vars etc... I'm thinking would be neat to store outside of the web facing directories to keep it a little more secure. But, then I was thinking, is it really THAT much more secure? I mean, if someone were able to look at my .php files as a whole (without the server processing them) they would be INSIDE my server looking at all my files anyway...

Thoughts?

+2  A: 

It means noone can access it via a URL by default.

You can hide with .htaccess if it is in your docroot, but storing it above the docroot is just that bit safer.

You can have it read via PHP if your application is prone to directory traversal attacks.

alex
+4  A: 

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');?>.

Rook
@The Rook Rad :) Let me ask you this. If my access to server side programs is limited to what's generally available in an admin like "cpanel", which I'm assuming you are familiar with, do you think I will be able to remove the FILE privileges or chmod that path? I feel like my access is limited to just one level below web... and I don't think that's where PHP is sitting. Is this something I would should take up with a server administrator? I'm using hostgator btw... any horror stories about them?
Jascha
@Jascha I haven't heard anything about hostgator, although most hosting companies already lock down your MySQL account. Its easy to test, try and fire off that load_file query. Yes you can chmod files with cPanel. You can change MySQL privileges with phpmyadmin, but you need `GRANT` rights which you shouldn't have.
Rook
+2  A: 

Yeah, you are right. There is a very small difference.

Col. Shrapnel
@Col.Shrapnel That was my thought. I'm not that familiar with ftp security, but I figure I can do all the fancy tricks I want to the front end of my script to prevent attacks, while someone could just show up through the back door via ftp. Especially considering a handful of my clients passwords are the same thing. (don't tell anyone).
Jascha
@Jascha yes, that's truth. nowadays trojan programs steal ftp passwords from client computers and then infect your site. but it cannot be a reason not to use any other protection.
Col. Shrapnel
It's a little ironic to need protection FROM Trojans.... sorry, had to say it.
Jascha