-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
security issue: env.php must be writeable in production #4955
Comments
Can you point on functionality that required writeable env.php in production? |
its the cache, as soon as a cache option is disabled, it attempts to rewrite the file:
version is 2.0.7 |
also i think if you disable/enable any cache it rewrites the file |
Don't think that you need disable the cache on production. |
it just breaks functionality or security so its bad design |
Magento can be used in different environment. In developer mode, you can clean cache because in this case you don't need maximum security, in production mode, you cannot disable cache with maximum security settings. So no security issue there. |
but it wont work with any cache disabled, if I modify my env.php and disable one of the caches the app is broken (it wont load anything being stuck on trying to rewrite the file), also the admin-interface suggest to disable caches, this would also result in a failed write attempt another aspect is, that I'm not sure which other parts of the code for whatever reasons might attempt to rewrite this file... if the app was designed to be able to write this file in either of the modes, then something else might break my shop at any time, or an update might so my point is that either the app expects the file to writeable at all times (which is bad for security as long as this is a a php-file), or it should take into account that the file might not be writeable. both are not the case. |
I can only guess as to why this file was chosen as a php-file, might as well be an ini-file using http://php.net/manual/en/function.parse-ini-file.php keeping the dependency to read this cfg to a minimum, either way i think its a bad practice to mix "static"-cfg-values given by the environment and settings of the app (i.e. the cache being enabled/disabled) |
it really doesn't work, now I can't even upgrade anymore in production:
is not letting me pass... it doesn't even need to write any file... it just checks for it... |
I wrote my own upgrade console command with a custom but this only proofs, that yes magento expects to write these files and wont work without being able to write them. |
Internal ticket MAGETWO-55424 to consider non-executable format for configuration files. |
also, you should separate non-static configuration from static. |
There are so many reasons to find a better method to doing this. It also complicates deployment. Dynamically writing out an executable config file? Serious wtf in the choices department here. |
I am currently having an similar problem with database upgrade on deployment to an ( stage ) environment which runs in production mode. When i run
Man, i just want ( need ) an DB Upgrade, otherwise Magento wont run throwing an Exception where it asks for an upgrade. |
@eduard-kistner yes, it is frustrating, which is why I wrote my own upgrade command which skips the file-checks |
also, see this ticket: #7933 |
@ludwig-gramberg thanks for the information and the corresponding issue. |
Hi, |
sounds like 2.2.0 will begin to be a version with developers in mind... magento 2 has so many large and small quirks which make you want to claw your eyes out to make the pain stop... |
Just noting my frustration with this behavior too—I'm trying to deploy Magento 2 in a containerized environment (in Kubernetes), with a static env.php file which is controlled by our VCS and deployment tools, and uses environment variables for many important bits of information. It seems like, even after Magento is installed, the first page request to any new container will trigger Magento to rewrite the entire contents of the file, which removes any of the environment variables I had in the original file, and then the site starts throwing exceptions. Right now I'm trying to find a way to work around this annoying issue. If I set the file to read-only, then any time I try loading a page I get:
[Edit: Just adding that it seems that I saw some unrelated errors relating to needing to re-run code compilation to populate the |
We now also encountered this issue when upgrading to Magento 2.3.2, but with a different message:
Tests confirmed, that it is the same issue (production mode). When env.php is writable, the issue doesn't happen. This is a big issue for us, because we are using Kubernetes and the env.php is coming from a ConfigMap, which can not be mounted read-write. |
The reason for this is the new Observer page_cache_switcher_for_maintenance that tries to disable the PageCache in Magento 2.3.2 when enabling maintenance mode. |
This is still an open issue and it just got worse with Magento 2.3.3, because the patch "Magento\Downloadable\Setup\Patch\Data\AddDownloadableHostsConfig" tries to write to the env.php. Is there any update on this issue? |
Hi @engcom-Charlie. Thank you for working on this issue.
|
Hello @ludwig-gramberg We are not able to reproduce this issue on a fresh Magento 2.4-develop. Testing scenario:
Result: So i have to close your issue. Thanks for your report! |
@engcom-Charlie This is still an issue, see my comments. This is not the only instance where the file has to be writable. |
@engcom-Charlie how about 2.3? |
This is still an issue in the most recent production release of Magento - 2.3.5. For us the main issue happens when running |
almost 4 years and no solution in sight rant: |
@ludwig-gramberg , I mostly agree and I would add that I don't understand how are people commited to a framework that try to enforce deployment and exploitation workflows to their customers. |
I am running into this issue on If you move the env file to a ConfigMap in k8s this will completely break deployments.
results in
|
@rootindex: it's probably better to follow these issues (since these are still in status "Open"): |
I have an issue with Magento expecting the env.php file to be writeable in production, potentially an attacker who gains code-execution in the webserver could then manipulate this file to execute arbitrary code
in production I want to be able lock down this file so nobody can manipulate it, after all this is the production mode, so no code-generation is necessary (and if you must store parts of the config in a writeable way inside a file, don't use a php-file, use xml or ini)
The text was updated successfully, but these errors were encountered: