Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent scripts from stealing password in open source PHP project?

I'm currently developing a PHP framework. Other developers may create modules for the framework. Source code of these modules should reside in the framework directory.

Since the project is open-source, modules know location of the config file which has database password in it. How to protect passwords from malicious modules? Please check that modules may just require_once the config file and do harmful things!

Currently I'm storing Database passwords in a directory named config, and protecting it by a .htaccess file:

<Directory config>
order allow,deny
deny from all
<Directory>

But that is not sufficient to prevent scripts steal the password, is it?

I've read the thread How to secure database passwords in PHP? but it did not help me finding the answer.

like image 510
Shafiul Avatar asked Aug 28 '11 12:08

Shafiul


1 Answers

In PHP, you can't. It's not a sandboxed language; any code you run gets all the permissions of the user it's running under. It can read and write files, execute commands, make network connections, and so on, You must absolutely trust any code you're bringing in to your project to behave well.

If you need security boundaries, you would have to implement them yourself through privilege separation. Have each module run in its own process, as a user with very low privileges. Then you need some sort of inter-process communication. That could be using OS-level pipes, or by having separate .php files run as different users running as web services accessed by the user-facing scripts. Either way, it doesn't fit neatly into the usual way PHP applications work.

Or use another language such as Java, which can offer restricted code with stronger guarantees about what it is allowed to do (see SecurityManager et al).

like image 189
bobince Avatar answered Sep 19 '22 21:09

bobince