Skip to content

Debug mode is enabled by default in production when Dotenv is not installed #43793

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

Closed
pierres opened this issue Oct 28, 2021 · 0 comments
Closed

Comments

@pierres
Copy link
Contributor

pierres commented Oct 28, 2021

Symfony version(s) affected

5.3.9

Description

When using only environment variables to configure Symfony, you end up with debug mode enabled even when APP_ENV=prod. This only happens when symfony/dotenv is not installed.

Installing dotenv will disable debug in prod mode by default. Even if you do not use .env files, installing this package will change this behavior. See \Symfony\Component\Runtime\SymfonyRuntime.

One might not have dotenv installed in a production environment as it should not be needed or when using an older setup. Past versions of the Symfony Skeleton did have symfony/dotenv as require-dev and not require dependency.

How to reproduce

  • $ composer create-project symfony/skeleton sf
  • $ cd sf
  • $ bin/console
  • will print (env: dev, debug: true)
  • $ APP_ENV=prod bin/console
  • will print (env: prod, debug: false)
  • $ composer remove symfony/dotenv
  • $ APP_ENV=prod bin/console
  • will print (env: prod, debug: true)
  • $ APP_ENV=prod APP_DEBUG=false bin/console
  • will print (env: prod, debug: false)

Possible Solution

I would suggest to always disable debug mode within the prod environment unless explicitly enabled. It is hard to notice and unexpected otherwise.

E.g. change the fallback to false in \Symfony\Component\Runtime\GenericRuntime which currently is true:

$debug = $options['debug'] ?? $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? true;

Additional Context

No response

@pierres pierres added the Bug label Oct 28, 2021
@xabbuh xabbuh added the Runtime label Oct 28, 2021
@fabpot fabpot closed this as completed Nov 5, 2021
fabpot added a commit that referenced this issue Nov 5, 2021
…d (nicolas-grekas)

This PR was merged into the 5.3 branch.

Discussion
----------

[Runtime] fix defining APP_DEBUG when Dotenv is not enabled

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #43793
| License       | MIT
| Doc PR        | -

Commits
-------

189987a [Runtime] fix defining APP_DEBUG when Dotenv is not enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants