Wiki / Exposed files

Risk: Publicly accessible.env file

Anyone who adds /.env to your address can download the application's settings file with its passwords. It usually holds the database password, the mail login, and keys for payments and other services. Close it today and change everything that was in it.

What it does not mean. It is not proof that someone has already downloaded the file. The server access log shows that: look for requests to /.env answered with 200.

Aleksandr IzmalkovFacts checked:

In our report
Risk (red), the highest category weight, 2.0
Time to fix
5 minutes to close; changing the secrets takes an hour or more
Can it break things
Closing: no. Changing secrets: yes, if the new values are not written to .env

How to fix it

Our check counts the file as exposed only when the response contains lines of the form NAME=value, so this is the real file, not an error page.

nginx (tested on 1.26.3)

location ~ /\.(?!well-known/) {
    return 404;
}

On the test server the response for /.env and /sub/.env changed from 200 to 404. The same rule closed .env.production, .htaccess and .DS_Store, while /.well-known/acme-challenge/ stayed at 200: certificates are renewed through that path. Put it above other regular-expression location blocks: nginx uses the first one that matches.

Apache (tested on 2.4.59, also works in .htaccess)

RedirectMatch 404 "/\.(?!well-known/)"

Needs mod_alias. Same result on the test server as with nginx.

More reliable: keep the file above the web root

mv .env ../.env

On the test server, once the file sat one level above the web root, the answer was 404 with no rule at all. The application has to be told the new location. Laravel projects need no move: the web root must be public/, which leaves .env outside it.

After closing: the secrets

grep -E "PASSWORD|SECRET|KEY|TOKEN" .env

The command lists what has to be changed. Change each value where it was issued (the database, the mail service, the payment provider's account) and only then write it to .env. Closing the file does not cancel the old passwords.

Terminal: before the rule curl prints .env lines with database, mail and payment keys; after the rule the server answers 404 while the .well-known path stays at 200
Test nginx 1.26.3 before and after the rule. Every password and key in the example is made up; on real sites that place holds real ones.

How to check

curl -s -o /dev/null -w "%{http_code}\n" https://example.com/.env

Expected

404

A 200 response means the file is still open. In a browser use a private window: it may show an old copy.

What can break

  • If you change the database password without writing it to .env, the site can no longer connect to the database. Change both places in one go.
  • Laravel with cached configuration (php artisan config:cache) no longer reads .env: run the command again after the change.
  • The rule hides every file and folder whose name starts with a dot, except /.well-known/. If you serve another such path to browsers on purpose, add an exception for it.

Our data

45

of 73,386 inspected .lt websites (0.06%) serve the contents of their .env file. Dataset, 16 November 2026

Sources

Next