Home > Backend Development > PHP Tutorial > What should you pay attention to about sensitive information in PHP programs?

What should you pay attention to about sensitive information in PHP programs?

WBOY
Release: 2016-07-25 08:54:32
Original
803 people have browsed it
  1. return array(
  2. 'database' => array(
  3. 'host' => '192.168.0.1',
  4. 'user' => 'administrator',
  5. 'password ' => 'e1bfd762321e409cee4ac0b6e841963c',
  6. ),
  7. );
  8. ?>
Copy code

Sometimes for some reasons, such as code review, or cooperative development, etc., third parties It is necessary to obtain the read permission of the code version warehouse. Once authorized, sensitive information such as the database address, user name, password, etc. will be exposed. Of course, you can not save the configuration file in the code version repository, but write a document to explain it, but I don't like this method, because then the code itself is incomplete.

How to solve this kind of problem? The most direct way is to remove sensitive information from the code and save it somewhere else. Where exactly is it saved? There are many options, such as setting it through nginx’s fastcgi_param:

  1. return array(
  2. 'database' => array(
  3. 'host' => $_SERVER['DATABASE_HOST'],
  4. 'user' => $_SERVER[' DATABASE_USERNAME'],
  5. 'password' => $_SERVER['DATABASE_PASSWORD'],
  6. ),
  7. );
  8. ?>
Copy code

In addition, you can also pass the env command of php-fpm To set:

env[DATABASE_HOST] = 192.168.0.1 env[DATABASE_USERNAME] = administrator env[DATABASE_PASSWORD] = e1bfd762321e409cee4ac0b6e841963c

One thing to note is that this setting must be placed in the main configuration file php-fpm.conf and cannot be placed in the sub-configuration file set by the include directive, otherwise an error will be reported: "Array are not allowed in the global section"; in addition One thing, although it is set through env, the result is still in $_SERVER, not $_ENV.

Note: @Laruence reminded me that if the configuration information is set through nginx's fastcgi_param, when nginx interacts with php, a large amount of data will be transferred (so it seems that setting it through php-fpm's env is relatively more advantageous) ), Brother Niao suggests using an independent extension, such as "hidef".

If you solve the problem through nginx and php-fpm configuration files, there is a disadvantage. It is only valid for the Web. If you run it through the command line, you cannot get the relevant information in $_SERVER. However, this is not difficult. Just write By matching the nginx or php-fpm configuration file with a public script, you can dynamically map this information to the command line environment. I’ll leave it to you to do it specifically.

The remaining work is how to ensure the security of nginx or php-fpm configuration files. However, compared with code, nginx or php-fpm configuration files do not require many people to have permissions, so they are relatively easier to manage.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template