Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Securing database connection information

I know that the question How do I secure my database connection credentials? has been asked and answered multiple times (e.g. How to secure database passwords in PHP?).

A commonly accepted answer to that question is to store the details outside of the web root. But I'm curious as to why this really makes much difference.

From what I understand, a person cannot download the source of the PHP file via HTTP (unless your web sever is not configured properly, but you would know about that right away). So you won't be able to see the credentials unless you have access to the source of the PHP file anyways. Correct me if I'm wrong, but doesn't this basically mean that you would need shell access? And if you have shell access, can't you just get to the file outside the web root anyways?

If the answer to that question is that the include file might have special permissions that don't allow anyone but the web server user to read it, then (considering that I have shell access), couldn't I just write (or modify) any PHP file to just echo out those credentials?

So the question is, does it really make any difference whether you store the credentials directly in the PHP script vs. in a file outside the web root?

like image 756
Travesty3 Avatar asked Oct 11 '12 13:10

Travesty3


People also ask

How do you secure your connection string information?

The best way to secure the database connection string is to encrypt the value within the configuration file. The application would then load the encrypted value from the config file, decrypt the value, and then use the decrypted value as the connection string to connect to the database.

Where should you store the connection string information?

Connection strings in configuration files are typically stored inside the <connectionStrings> element in the app. config for a Windows application, or the web. config file for an ASP.NET application.

What is data Connection in database?

A data connection is a dynamic link between a form and a data source that stores or provides data for that form. A form can have one primary data connection, called the main data connection, and it can optionally have one or more secondary data connections.


2 Answers

Suppose, due to a error in the webserver, the webserver no longer processes php files, but treats them as html files.

In that case something like http://mysite.com/config.php would simple reveal the credentials of your database.

So the answer is: Yes, it does really matter, where and how you store the database credentials.

like image 97
JvdBerg Avatar answered Oct 01 '22 07:10

JvdBerg


The main issue is that the web server might break down later on. E.g. after a software update php might not work properly anymore and the server falls back to delivering the files directly. Or again after a software update the configuration might be reset, so PHP is no longer registered for the file extension. Or the server breaks down under heavy load and also starts delivering files plainly.

Many things can happen and it's rather easy to mess up the config at some point. Better be safe and keep it outside the document root.

like image 24
NikiC Avatar answered Oct 01 '22 06:10

NikiC