Exposed .env file: the settings file that hands out your keys
Last reviewed
An exposed .env file hands out the keys to your website.
A .env file is a plain text configuration file where a website stores its secrets: database passwords, API keys and login details for connected services. It is meant to stay private on the server. If the server is misconfigured, anyone can download it by typing its address into a browser, and automated bots request that exact address on sites across the internet every day.
Why an exposed .env file costs you customers
Whoever reads the file can use what is in it. That can mean customer records copied from your database, spam sent through your email account, or charges run up on a paid service under your name. You are then dealing with a data breach, notifying customers and rebuilding trust, all from one file left in the wrong folder.
What usually causes an exposed .env file
- The file was uploaded into the public web folder instead of above it
- The server has no rule blocking access to files that start with a dot
- A deploy copied the whole project folder, secrets included, to the live site
- A backup copy of the file was left behind under a slightly different name
- A host migration dropped the access rules that used to protect it
How to check for an exposed .env file yourself
- On a site you own, type your domain followed by /.env into a browser. An error page such as 403 or 404 is the result you want.
- If text appears or a file downloads, with lines that look like NAME=value, the file is exposed. Close it and treat every value inside as compromised.
- Try the same test on any subdomains, staging sites and older copies of the site, which are often less carefully configured.
- Ask your developer whether the project uses a .env file at all and where on the server it is stored.
How to fix an exposed .env file
- Have your developer or host block public access to the file today, either by moving it above the public web folder or adding a server rule denying dot files.
- Rotate every secret in the file: database passwords, API keys, email credentials and tokens. Blocking the file does not help if a copy was already taken.
- Ask your host to review the access logs for requests to that address, to learn whether and when the file was fetched.
- Check connected services for activity you do not recognize, and follow your legal obligations if customer data may have been reached.
- Have your developer change the deploy process so secrets are never copied into the public folder again.
How Prsona catches an exposed .env file
On request, for a site you own, Prsona checks whether private configuration files such as a .env file can be downloaded from it. Only a confirmed exposure is reported, so a finding means a real problem and not a false alarm.
Prsona looks for an exposed .env file as part of website security monitoring.
Confirm that private configuration files on your own site cannot be downloaded by strangers.
Questions about an exposed .env file
What is a .env file used for?
Developers use it to keep settings and secrets separate from the code. It holds the values an application needs to run, such as the database address and password, keys for payment or email services, and security tokens. The application reads the file on the server. It should never be reachable from a web browser.
If I block the file now, do I still need to change my passwords?
Yes. You cannot know who downloaded the file while it was public, and bots look for these files constantly. Every password, key and token it contained should be replaced with a new one, and the old ones revoked. Blocking access stops future leaks only. It does nothing about copies that already exist.