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

Add ability to set whether environment variables to be displayed #281

Closed
wants to merge 2 commits into from

Conversation

MarnuLombard
Copy link

If you are able, you are welcome to ignore the first commit of the two - it's just an amendment to the .gitignore file.

The second commit's message explains the code changes well.

Fixes filp#119
Add $environmentDisplay member in PrettyPageHandler. Defaults to true.
Add getEnvVariables() method that returns $_ENV or message stating that display of environment variables has been disabled
Add setEnvironmentDisplay() method that casts to a boolean and sets the $environmentDisplay member.
@denis-sokolov
Copy link
Collaborator

Thank you for your contribution.
What is the use case for not displaying environment variables?

@@ -2,3 +2,5 @@ vendor/*
report/*
phpunit.xml
composer.lock

.idea/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you may want to use a user-global gitignore file to minimize noise and also to minimize work for yourself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah cool, This wasn't meant to be part if the pull request - I don't have a lot of experience with pull requests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice about the global .gitignore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about it, if we choose to merge, I'll quickly rebase it myself.

@MarnuLombard
Copy link
Author

Hi Denis.

A lot of people use environment variables to store sensitive config (third party services passwords, etc).

While one would never use Whoops in production, I've found that the environment between my local development environment and the production ready site (staging environment) needs to be accessible from the outside - whether I'm reviewing with remote design teams or getting client's input.

In the staging environment I use leave all debug ability turned on - being that at this stage bugfixes are still really likely. But leaving my database username & password, my AWS username and password and all of that open for anyone to stumble upon is extremely dangerous.

When looking into whether there was a flag to disable the display of $_ENV i came across #119 - Indicating to me that it was a function of Whoops others wanted too.

The fact that you added it to the Features to add list motivated me to do the work.

@MarnuLombard
Copy link
Author

Do you want me to write tests for this?

@MarnuLombard
Copy link
Author

Perhaps there could be an apposing method to addDataTable().
Sort of a filterOutData(), that could look an unset data - instead of just a yes-no for $_ENV?

if( $this->environmentDisplay )
return $_ENV;

return ['PLEASE NOTE' => 'Display of environment variables has been disabled'];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also going to wrap these strings in double quotes, it seems that's the style you've used in the class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix the short array syntax I used.

@denis-sokolov
Copy link
Collaborator

denis-sokolov commented May 8, 2015

Edit: see the more up-to-date comment.

I have now realized why I am against this. I do not want to create an illusion of security.
If we add any single feature that masks some data, developers will begin to expect that this has somehow made PrettyPageHandler "secure".
Even if nothing else reveals their sensitive data (code snippet, traceback function values), we have no guarantees that we will not add more information to PrettyPageHandler display in the future.
For example, what if one day PHP allows us to collect local variables from the point of error?
What if we add an interactive console for better debugging?
PrettyPageHandler is absolutely insecure and must not ever be used in any context where you might want to hide something. Just replace it with an EmailHandler.

If you absolutely really need a short term hack, just mask the data yourself:

$run->pushHandler(new PrettyPageHandler());
$run->pushHandler(function($exception, $inspector, $run) {
  $_ENV['SENSITIVE_KEY'] = 'censored';
});

Thank you for your contribution.
The feature you request will not be added to PrettyPageHandler in any form.

@MarnuLombard
Copy link
Author

That actually makes a lot of sense,
Thanks for explaining.

Stay well.

1 similar comment
@MarnuLombard
Copy link
Author

That actually makes a lot of sense,
Thanks for explaining.

Stay well.

@garygreen
Copy link
Contributor

garygreen commented Aug 3, 2017

@denis-sokolov

I have now realized why I am against this. I do not want to create an illusion of security.

I think you have totally missed the point behind creating a way of masking sensitive values or hiding them at all. For a user of Whoops to think that because there is now an option to hide e.g. envs means they can now enable PrettyPageHandler for every request would be a ludicrous thing to suggest.

We realise that it's not secure, in any case, to enable that mode on production - the real value here is accidental enabling of the handler e.g. enabling debug mode (in Laravel) and suddenly BOOM you have exposed every database env password, API key, everything. One silly mistake is all it takes. We're all human, and this extra bit of security on top will only help in those cases.

Your view is basically this - don't enable debugging / tracing in production. What if MySQL connection by PDO took the same view and exposed the "Using password: < MY LOVELY PASSWORD >" because, hey, you shouldn't be displaying errors / stack traces in production.

Mistakes happen. This is a way of helping when things go badly wrong. It's nothing to do with adding a false sense of security, it's about realising we're human.

@garygreen
Copy link
Contributor

garygreen commented Aug 3, 2017

Another example - Whoops has now been officially added back into Laravel 5.5

What if a malicious user or very bad pull request came in for Laravel which meant that PrettyPageHandler is accidentally running in production. People pull down the update, deploy, not realising the change.

Now sites are exposing database passwords, API keys, everything. Yes, it's also exposing code traces, and other stuff, but at least information that is clearly sensitive is hidden and damage is kept to a minimum.

Don't get me wrong, this would be a terrible thing to happen and I really hope it doesn't, but it's a frightening thought. Anything we can do to help mitigate potential problems is a win in my mind.

PS - I've submitted a PR to Laravel to only install Whoops on development and not production, this will help mitigate any security problems by exposing envs and stuff accidentally.

@denis-sokolov
Copy link
Collaborator

My more up-to-date comment might be of interest to you, @garygreen.

@garygreen
Copy link
Contributor

garygreen commented Aug 3, 2017

@denis-sokolov thanks for the link, glad to see you have changed your thoughts towards masking of sensitive information, the PR looks awesome. It might be an idea to update your original comment above with the link so people coming to this issue will see the most recent changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants