Search code examples
securitylumen

Variables from my .env are shown on error


I just started using laravel's lumen and managed to make it work both locally and on a server, when I was about to start exploring it, my index.php consisted in just:

$app = require __DIR__."/../lumenTest/bootstrap/app.php";
$app->run($app->make('request'));
echo $myundefinedvariable;

Which displays a ErrorException: Undefined variable: myundefinedvariable, but inside the "...at Application->Laravel\Lumen\Concerns{closure}" window I can see a giant wall of text with stuff like:

... 'APP_KEY' => 'fake0BqKgHeC72EmT7039B6pDCsJ90key' , ...,  'DB_PASSWORD' => 'secret', ...

And my first thoughts were, maybe it is because im running it localy with XAMPP or something, so I went and tried it on the server and the same thing happened.

Is it normal that sensitive data from my .env file gets shown to everyone after doing any php error?

Is there a way to avoid this happening? (different than not having any PHP errors, because I tend to have them a lot).

Additional info:

  • PHP version 7.1.12
  • Lumen (5.6.1) (Laravel Components 5.6.*)
  • The directory "lumenTest" is one level above my www or public and there is where the .env is located, the site is on a Linux server shared host

Solution

  • Yes, if you have debug mode enabled, any sort of data relating to an error can be displayed. This certainly would include sensitive data that would be useful when debugging.

    For production, you want all errors to be privately logged, not publicly displayed. For this reason, you will want debug=false in your .env file.

    If this is happening while debug mode is already set to false, you will want to configure the hiding/logging of errors at the server level.