Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing important secret keys in php files

Tags:

security

php

We're making an app using PHP and using some third party services that require a secret API key. We have a PHP file that contains all those keys definitions that we then import (using require_once) when needed.

Is this approach safe? Should we store the keys in a different place?

Thank you.

like image 202
DiogoNeves Avatar asked Feb 22 '10 14:02

DiogoNeves


2 Answers

Something similar was asked today for a shell script. The answer is valid here as well: Make sure you store the file outside the web root, or (if that's not possible) protect it using a .htaccess file.

I also like to unset() any variables containing sensitive data after use, so not even a full variable dump (e.g. in a debug message) later in that script could reveal it.

like image 100
Pekka Avatar answered Sep 28 '22 07:09

Pekka


It should be relatively safe as long as the file is not accessible from the web. A lot of sites will place sensitive files outside of the webroot on the server, and simply include them when needed into their app.

like image 29
Steven Mercatante Avatar answered Sep 28 '22 08:09

Steven Mercatante