Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot-env variables easily exposed #18492

Closed
hakuno opened this issue Mar 25, 2017 · 16 comments
Closed

Dot-env variables easily exposed #18492

hakuno opened this issue Mar 25, 2017 · 16 comments

Comments

@hakuno
Copy link

hakuno commented Mar 25, 2017

  • Laravel & Lumen Version: 5.4
  • PHP Version: 7
  • Database Driver & Version: pgsql 9

Description:

  1. Time ago, a Laravel's error exposed my database credential. (Yes, I refer about those erros with "thrown exceptions" while APP_DEBUG is true).

  2. Now, my Lumen has DB_PASSWORD at $_SERVER in.

So... how do I avoid these security issues? Should dot-env variables be there?

Thanks in advance.

Steps To Reproduce:

dd($_SERVER)

@deleugpn
Copy link
Contributor

What's the issue?

@hakuno
Copy link
Author

hakuno commented Mar 25, 2017

The former. Database password must not be shown in debug error or whatever.

The latter sounds developer driven as usual.

Ps.: about the nº 1, is it all related to APP_DEBUG variable and just? Is that my blame?

Sorry.

@deleugpn
Copy link
Contributor

Your description of 1 seems like a leak in the debug backtrace. So, yeah, you shouldn't be running production with APP_DEBUG on.

Still don't understand why you care about 2, though.

@hakuno
Copy link
Author

hakuno commented Mar 26, 2017

Nice.

IMO, all the world has warned us about the "globals". So I couldn't call the variable globally ($_SERVER["DB_DATABASE"]), but through its own object (env function) and just.

It's the purpose, isn't?

Thanks.

@hakuno
Copy link
Author

hakuno commented Mar 26, 2017

In fact, I see no code bug. Maybe some security tips are needed for understanding.

@hakuno hakuno closed this as completed Mar 26, 2017
@sisve
Copy link
Contributor

sisve commented Mar 27, 2017

You must php artisan config:cache to disable the loading of .env and the setting process-wide environment variables. Thus they won't show up in $_SERVER, $_ENV or other superglobals.

Exception handling tools such as filp/whoops are dumping $_SERVER, possibly disclosing critical information put there by phpdotenv.
Related: vlucas/phpdotenv#124

You need to config cache first. Not a bug.
We don't expect it to work if you forget to do that.
Source: #13906 (comment)

Starting in laravel 5.2, we only use dotenv to populate the config cache, then we don't load the environment on any requests. I recommend everyone does something like this.
Source: vlucas/phpdotenv#76 (comment)

ONLY use env inside your config files, and then you MUST use the cache command to setup the config files. Then there are ZERO env issues in production.
Source: Source: vlucas/phpdotenv#76 (comment)

@bappy004
Copy link

bappy004 commented Oct 9, 2018

since
php artisan config:cache
doesnt work for Lumen, what is the recommended procedure for this for lumen ?

@sisve
Copy link
Contributor

sisve commented Oct 9, 2018

@bappy004
Copy link

bappy004 commented Oct 9, 2018

Hi @sisve thanks for the suggestion. However, switching to Laravel seems a bit extreme just to mitigate this dotEnv potential issue. Any other suggestions?

@sisve
Copy link
Contributor

sisve commented Oct 10, 2018

@bappy004 Avoid using the .env file. Instead, modify the configuration files directly.

The root cause is that dotenv will set entries in $_SERVER, and the only way to avoid it is to avoid using dotenv, and thus the .env file.

https://github.com/vlucas/phpdotenv/blob/54d599d414f8cf3f6129e287acaf44b610486aa1/src/Loader.php#L386

@PieterjanDeClippel
Copy link

PieterjanDeClippel commented Dec 5, 2018

This can't be true...
I noticed this HUGE security breach yesterday.

When you accidently forget to set APP_DEBUG to false
all of your application passwords, keys and usernames are plainly exposed to the entire world
and the answer to this breach is "Well, you shouldn't set 1 simple configuration variable to true huh?".

That's just enough convincing for website owners to ditch Laravel and go for one of the like 200 other MVC frameworks (think of codeigniter, symphony itself, yii, CakePHP, and so on, and so on)

Why don't you just remove the .env variables from the Whoops page by default (and yeah, entirely)?
You'd be making 95% of your users happy.
For the other 5% who are too lazy to just locate and open the .env file, you can still add a, I don't know, I_AM_LAZY environment variable.

Problem solved?

@tufanbarisyildirim
Copy link

This can't be true...
I noticed this HUGE security breach yesterday.

When you accidently forget to set APP_DEBUG to false
all of your application passwords, keys and usernames are plainly exposed to the entire world
and the answer to this breach is "Well, you shouldn't set 1 simple configuration variable to true huh?".

That's just enough convincing for website owners to ditch Laravel and go for one of the like 200 other MVC frameworks (think of codeigniter, symphony itself, yii, CakePHP, and so on, and so on)

Why don't you just remove the .env variables from the Whoops page by default (and yeah, entirely)?
You'd be making 95% of your users happy.
For the other 5% who are too lazy to just locate and open the .env file, you can still add a, I don't know, I_AM_LAZY environment variable.

Problem solved?

This is like forgetting your FTP on public/anonymous access mode and then yelling at a developer like WHY DON'T YOU JUST REMOVE ALL PHP FILES FROM FTP TO KEEP US SECURE?

@PieterjanDeClippel just delete your files, that will keep you far from security risks in being a website/webapp owner.

@devcircus
Copy link
Contributor

The security concern here, is using debug mode in production.

@PieterjanDeClippel

This comment has been minimized.

@ludo237
Copy link

ludo237 commented Dec 11, 2018

@tufanbarisyildirim You're retarded

Well shame on you by leaving APP_DEBUG true in production also Laravel now provides a handy config file to explicitly exclude certain variables from debug so you can leave APP_DEBUG on true and test in production without problems 😉

@driesvints
Copy link
Member

@PieterjanDeClippel please refrain from name calling and be polite to other developers.
@tufanbarisyildirim Please keep it civil and only reply if you have something positive to contribute to the conversation.

Going to lock this thread down as this has gone off topic too much.

@laravel laravel locked as too heated and limited conversation to collaborators Dec 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants