# What happens when .env is open to the world
*articles*
Leave .env in what you deploy and one request hands over your passwords and API keys. Here is how V10 in vuln (Priority 3) sees it, and the order to fix it.


Have you ever typed `/.env` after your site's URL? If a check flagged ".env exposure", this article covers what can be read and how to stop it.

The short answer: **if `/.env` can be downloaded, every secret inside (API keys, passwords and other values that must stay private) can be read in a single request.** In vuln it is Priority 3, the highest in the check. If it shows up, fix it before the other findings.

## .env is the settings notebook

Imagine hanging a bunch of house keys on a hook outside your front door. Not one bunch: the keys to every room, the family car and the office safe, all on one hook. .env is a file that often ends up in a place like that.

A .env file is a text file that holds your app's settings. One per line, in `KEY=VALUE` form. Database connection details, payment service keys, email keys and more live there.

Environment variables (settings kept outside the code, with values not shown on screen) are collected in .env while you work locally. Keeping settings out of the code is the right idea. The only problem is where the file sits.

## What can be read if it opens

What gets read is not a single password. The keys that run your service are taken together.

- The database connection string and password. Read, change or delete every user's data
- The payment service secret key (an API key, a string used to call an external service). Charges, refunds and product operations
- The email service key. Send fake mail from your domain
- The key that signs login state. Act as any user, including an admin
- Cloud and external API keys. Operate servers and storage, and run up the bill

All of this is a "may". The impact when it does happen is a step above the other findings, because personal data, money and trust all move at once.

**Even if your site looks unchanged, the keys are already handed over.** You will not know whether they were used until you read the access log. So do not stop at deleting the file; pair it with rotating the keys.

This kind of exposure is classified as CWE-538 (an international numbering system for software weaknesses). An attacker may not target your site at all. Automated scanners try common paths in order, and that is how most of these are found.

## "It's a hidden file" is not enough

Files that start with a dot are hidden in a file browser. On the web, they are not hidden. Any file under the public directory is served if the name is requested.

There are several ways it gets there:

- You uploaded the whole build folder by FTP or drag and drop
- A container copied the whole working folder, as in Docker's `COPY . .`
- You put .env directly in the public directory of a static host
- A framework setting copied .env to the public side

Some hosts return 200 and an HTML page for any path that does not exist (common with client-side apps). In that case what comes back is an error page, not the contents of .env. vuln tells the two apart and does not flag an HTML body as exposure.

## How this differs from the other findings

[Missing security headers](/en/checks/security-headers) narrow the way in. [Source map exposure](/en/articles/source-map-exposure) lets someone read how the code is built. Both are worth fixing, but neither hands over a key.

.env exposure hands over the keys. If you need an order, start here.

## How vuln shows it

In vuln (a [free check that only needs the public URL](/en/vuln)), .env appears as one row, V10.

- V10 .env exposure (Area: Exposure, Priority: 3)

The range it looks at is fixed.

- GET `/.env` (the first 64 KB)
- GET `/.env.production` only when the request budget allows
- An HTML body is not flagged (so a site that answers 200 for missing paths is not a false positive)
- One or more lines in `KEY=` form is enough; values are never shown, and up to ten key names are listed
- Keys named SERVICE_ROLE, SECRET, PRIVATE_KEY, DATABASE_URL or API_KEY make it critical; anything else is high

critical is the heaviest rating in the check. When it needs attention, the fix column reads "Remove the file from the deployment, block dotfiles at the host, and rotate every secret it contained."

A 404 or 403 is a pass. If the file cannot be fetched, it becomes "not checked". **A pass means "nothing was found at these two paths"**; it does not cover files with other names, such as `.env.local` or `config.json`.

The official documentation is here.

- [OWASP Secrets Management Cheat Sheet (English)](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)
- [CWE-538 (English)](https://cwe.mitre.org/data/definitions/538.html)

## Measured on this site

On 27 November 2026 we used curl (a command that fetches the contents of a URL) to fetch `https://ismyappok.com/.env` and `/.env.production`.

Both returned **HTTP 404**, and the body was a `text/html` error page. The file is not served, so V10 is a pass.

This site runs on Cloudflare and serves its static files as Workers assets. Because no `.env` is placed there, the request returns 404.

## How to stop it

The first step is to remove it from what you deploy. Do not put .env in the public directory (`dist`, `public`, or wherever you upload). Build tools do not include .env in their output by default.

Vite passes only variables starting with `VITE_` into browser code. Next.js passes only variables starting with `NEXT_PUBLIC_` to the browser. **Any value with that prefix is readable by anyone**, so never use it for a secret.

The second step is to block it at the host. Configure the host not to serve files whose name starts with a dot. Some hosts have a setting in the dashboard; others need a rule in the server in front.

The third step matters most. Deleting the file does not erase a copy someone took. Treat any secret that was reachable as leaked: revoke it and issue a new one. The order is the database password, the payment and email API keys, then the signing key.

Rotating the signing key logs every user out. Telling them beforehand avoids confusion.

Also check three things.

- The access log for requests to `/.env`. Even one means you should assume it was taken
- The database dashboard for connections or operations you do not recognise
- The payment service for charges or refunds you do not recognise

If `/.git/config` is also open, the repository location can lead to the whole source. It is worth checking on the same day. See [.git/config exposure](/en/checks/git-config-exposure).

The official documentation is here.

- [Vite environment variables and modes (English)](https://vite.dev/guide/env-and-mode)
- [Next.js environment variables (English)](https://nextjs.org/docs/app/guides/environment-variables)
- [The Twelve-Factor App: Config (English)](https://12factor.net/config)

## Summary

Start by opening `https://your-domain/.env` in a browser. If you get a 404 or your usual HTML page, you are done for today. If you see `KEY=VALUE` lines in text, close the tab and rotate every secret that was listed.

A settings file is a note that keeps your app running. It is not something you publish. As with keys hanging outside the front door, moving it to one other place is all it takes.

But deleting only closes the door. The keys that got out do not come back. The item is done when the rotation is done.

Each check is explained here.

- [.env file exposure](/en/checks/env-file-exposure)
- [.git/config exposure](/en/checks/git-config-exposure)
- [Secrets in client JavaScript](/en/checks/client-secrets)

Related articles:

- [What a public source map gives away](/en/articles/source-map-exposure)
- [Running vuln on a Lovable app](/en/articles/lovable-vuln-token)

When you have made the changes, [run a check with vuln](/en/vuln). You can also review display and links before launch with [audit (no login)](/en/audit).

We wrote this article after checking our own site. It contains no results from scanning third-party sites. The numbers describe how the implementation works; measured values are only those stated with a date and method in the text.

## Check your own site
Enter a URL and see what is missing before launch. Free, and no login required.
[Run the free check](https://ismyappok.com/en/audit)