I still don't understand why you think you need security through obscurity. Just because you "make it harder" for someone to hack doesn't mean that it will never happen. So they can't directly get to your config file because you placed an exit() call (although I prefer the header()) so what? The point here is that the server needs to be set up correctly. If another domain can read stuff from your site simply by using file_get_contents('../../../../../../someotherdomain.com/www/includes/config.php') then there's a huge security hole that needs to be plugged in PHP and NOTHING you can do will stop that.
I'm not sure you entirely understood what I was getting, probably because my explanation wasn't particularly wonderful 🙂 Firstly, I was saying that you should use exit; in addition to header() (just afterwards), just in case the browser ignores the header and the server sends all the data. Secondly, I was referring to a situation where another user on the same server has obtained read-only access to the files, which is surprising common with shared server solutions, especially free ones (which are not set up correctly, as you say). You are absolutely right when you say that the problem needs to be solved in the PHP setup, but I like to do as much as I can in my application to keep the data safe, even if that means trying to sort out a problem that is better fixed elsewhere.
Encrypting a database password is probably not the best thing I've heard in terms of security. If you want security, encrypt the database itself. Not to mention, if they can get into your database, perhaps you should be less worried about the database, and more worried about your entire security schema from an FTP level on up.
No, I never believed encrypting the database password was the best way to do it. In fact that's the exact reason I made this topic, for some extra ideas and a wider perspective. I am not concerned about a user reading the data, but rather having access rights that allow them to change the data. And yes, security should be considered on a grander scale then just protecting the database password.
If you use a good server like Apache, you can limit what files are viewed by the users. You could use a simple mod_rewrite like:
Code:
RewriteEngine On
RewriteRule .* index.php
And then just put in your index.php some simple redirect code for your main site file. There are much simpler ways to secure your items than just encrypting passwords.
As I said previously, security is best in layers. How about instead of using security method A OR security method B, we use both. Such thinking can help to make an application more secure.
For example, SMF uses a Settings.php file to store all the settings about the current forum setup. Yet if you go to their Community and remove index.php and replace it with "Settings.php" you will see a blank page. Nothing wrong with that. You can't get information from it if you don't echo anything out. Now, if you yourself code a parse-error into your config file, that's your fault and nothing you do (except deny it with .htaccess or rewrite the url with .htaccess) will stop it from being viewed (or the error); especially if you have a poorly set up server.
To prevent errors from showing the code, you could store the configuration details in your own data format and then open it and check for errors when the application starts. But as you say, the best way is to rewrite the url with .htaccess.
Oh, and it seems that you're just shooting down all the ideas that are generated here.
Relax, please 🙂 I created this topic in the hope of getting the ideas and opinions of all the php pros in the community, and your replies have all been great. I'm sorry if it seems like I'm shooting down the ideas you're giving me, and I must tell you that I absolutely did not mean to do that.
Just because you place an exit at the top of the script won't stop someone with FTP or read access from wreaking havoc on your site. This is where server setup comes into play. You can store whatever you want wherever you want with whatever "security" steps you want. But if I can simply brute-force your FTP password (or that of the root server user) or simply use a file_get_contents() of a local path, security means nothing.
Yeah I know, hence encrypting the database password so they can't get into the database. I think that if the unauthorised user has read-only access, then there are some quite substantial steps we can take to prevent that read-only access from giving them read-write access to the database. Ok, the methods won't be flawless and perfect, but in the world of security nothing really ever is.
If you're not going to listen to anyone else here, I'll just shut the thread down. All the points given within this thread have been alternative ways to secure what you ask for.
Once again, relax, and be safe in the knowledge that I am listening and have already made some major shifts in the way I am thinking about this problem, thanks to all the points supplied in this thread. I am only stating the disadvantages to generate debate and not to try to put others down and I'm happy to admit that my idea is no doubt covered in flaws. I hope you can see the difference and won't be nuking the thread 🙂
If you want real security, you need to get a dedicated server, and encode all your files with some program like Zend Guard, ionCube or NuSphere's program.
Ok, true. But:
A) Why encode an open source application? (that's the kind of app I was thinking of)
😎 If the application is going to allow the user to set the database password on install, then we're back to step 1.
C) These aren't supported everywhere.
Otherwise, use the Apache permissions or rewrite rules in .htaccess or put the document outside the web-root. Plenty of good web applications store their database username, password, host, and database name in plain-text inside their config or settings files and yet they don't get hacked. Just because it's plain-text doesn't mean it's insecure.
Yes I know that this is not one of the most common security holes, and it is in fact caused by having PHP poorly set up. This is why I was nowhere near 100% sure that the extra layer of security was truly logical, and hence brought my idea to your attention. It just seems that placing the database credentials in plain text in a config file makes the mysql authorisation system rather pointless.
By the way, thanks for your comments 🙂