-
Notifications
You must be signed in to change notification settings - Fork 35
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
Protection from exposing .env #64
Comments
Just for those who stumble over this ticket in the future, this is what I have in my
@judgej Do you have any suggestions for other measures? I think the |
I think it either needs to be a PHP script, or it should go into a directory with no web access at all. Mixing PHP scripts and important non-PHP config files that absolutely must not be exposed to the world in a single directory, is just asking for mistakes to happen. Most control panels allow you to protect a whole diectory fairly easily, for where .htaccess The .env may or may not be reading if in the diectory above the public root. That depends on what security your hosting has, which should prevent your scripts from roaming around anywhere on the server outside of the web root, with the exception of The old problem of being able to cater for many hosting services - flexible and not - or defining some absolute requirements and leaving the end user to find appropriate hosting. |
How about a structure of:
Code should be able to read from |
Definitely worth seeing how other projects do it. The general approaches are: keep it out of your web root, or hide it with .htaccess http://stackoverflow.com/questions/33069319/env-file-is-visible You can also set the variables up in other ways, as php.ini settings or simililar. The .env entries all ultimately just get set as global environment variables, which you can do before your WP script is run just as effectively as using dotenv to do it once your WP bootstrap starts running. Maybe ,env should simply be out of the web root, and stated in capital letters in .env.example? Anyone not able to do that should either set up environment variables elsewhere (e.g. SentEnv in php.ini or .htaccess or whatever nginx uses) or put it into a hidden directory or hide the specific file. But those should probabty all be fallbacks if you can't locate it outside the web root. Laravel handles this by supplying a |
TL;DR Yes, you should definetively put Unfortunately, unlike Lavarel, we don't ship a complete system or a framework, we ships an installer for an application, WordPress, that is intended to be all put inside webroot. The only files in WordPress that can be outside of webroot are In the WP Starter documentation, the sample
This is the suggested way to use WP Starter and it is the example However, this is only possible if you hosting allows you to put files up of webroot. When that is not possible, something I successfully did in past is to create a subfolder in the webroot provided by hosting and then create a If even this is not an option, then there are 2 things left:
A thing that I always suggest is to remove permission to read/write/execute the file to anyone that is not the owner of the file, and ensure that the owbenrr is not the webserver user, this way even in case of some misconfiguration the file permission should prevent the file to be dumped on HTTP response. On a side note, the absolutely best way to handle Environment variables are a great solution because you can set them in the physical environment (e.g. via Apache In fact, To be honest, current version of WP Starter (2.*) somehow relies on The main target for WP Starter 3 (in the work, but no ETA) will be to improve the workflow and to make usage of physical environment variables much easier. |
If you run your server this is the way to block access to non-entry-point WordPress files: |
That is assuming apache. Which I don't really want (personally I don't work in projects using apache since at least 3 years now). |
I happened to come across this issue on a random "learn more" trip. https://github.com/wecodemore/wpstarter/blob/master/docs/quick-start.md should probably have a mention about public |
v3 docs have a very detailed explaination of the issue and how to overcome it. But I should update also v2 docs, as this is security relevant. |
I have "backported" documentation to v2. https://github.com/wecodemore/wpstarter/blob/master/docs/quick-start.md#important-security-issue-with-env-file I guess I can close this. |
I noticed .env is in the same directory as index.php Many hosting services by default will display .env, and .git/ and other files and directories you would normally expect to be hidden.
Some protection can be put in using .htaccess, but I'm wondering what other measures are taken, planned or recommended?
The text was updated successfully, but these errors were encountered: