Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide .env passwords in Laravel whoops output?

How can I hide my passwords and other sensitive environment variables on-screen in Laravel's whoops output?

Sometimes other people are looking at my development work. I don't want them to see these secrets if an exception is thrown, but I also don't want to have to keep toggling debug on and off, or spin up a dedicated site just for a quick preview.

whoops output screenshot with passwords shown

like image 971
Jeff Puckett Avatar asked Sep 25 '17 13:09

Jeff Puckett


2 Answers

As of Laravel 5.5.13, you can censor variables by listing them under the key debug_blacklist in config/app.php. When an exception is thrown, whoops will mask these values with asterisks * for each character.

For example, given this config/app.php

return [      // ...      'debug_blacklist' => [         '_ENV' => [             'APP_KEY',             'DB_PASSWORD',             'REDIS_PASSWORD',             'MAIL_PASSWORD',             'PUSHER_APP_KEY',             'PUSHER_APP_SECRET',         ],         '_SERVER' => [             'APP_KEY',             'DB_PASSWORD',             'REDIS_PASSWORD',             'MAIL_PASSWORD',             'PUSHER_APP_KEY',             'PUSHER_APP_SECRET',         ],         '_POST' => [             'password',         ],     ], ]; 

Results in this output:

whoops exception page

like image 91
Jeff Puckett Avatar answered Oct 09 '22 10:10

Jeff Puckett


First of all, love the solution by Jeff above.

2nd, if like me you wanna hide all the env variables while still use whoops, here is a solution:

'debug_blacklist' => [         '_COOKIE' => array_keys($_COOKIE),         '_SERVER' => array_keys($_SERVER),         '_ENV' => array_keys($_ENV),             ], 

Output:

enter image description here

EDIT: Legend has it that since laravel 7x you would need debug_hide key instead

like image 20
Raheel Hasan Avatar answered Oct 09 '22 09:10

Raheel Hasan