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?
PHP is as secure as any other major language. PHP is as secure as any major server-side language. With the new PHP frameworks and tools introduced over the last few years, it is now easier than ever to manage top-notch security.
If your server supports PHP, then you do not need to do anything. Just create your . php files, put them in your web directory and the server will automatically parse them for you.
Web developers and others who are knowledgeable about web pages know you can use a browser to view the HTML source code of a website. However, if the website contains PHP code, that code is not visible, because all the PHP code is executed on the server before the website is sent to a browser.
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');?>
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With