On this page
What this issue is
A .env file stores settings for an application as KEY=value lines. Frameworks such as Laravel, Symfony, Node apps and many Docker setups use it. It often contains the database login, payment and email API keys, and an app secret.
The file is only meant to be read by the application on the server. It becomes exposed when it sits inside the public web root and the server is willing to serve it. Then anyone can open https://yourdomain.com/.env in a browser and read it.
This is common after a deployment that copies the whole project folder into the public directory, after pointing the domain at the project root instead of a public subfolder, or after a server migration that drops the original block rules.
Why it costs you leads or sales
Automated scanners constantly request /.env on every site they can find. If it is readable, the secrets inside can be used within minutes, not weeks.
| Secret in the file | What an attacker can do | Effect on your business |
|---|---|---|
| Database password | Read or delete customer and lead records | Lost leads, data breach duties |
| Email/SMTP or API key | Send spam or phishing from your domain | Blocklisted domain, form emails land in spam |
| Payment or CRM API key | Read orders, create refunds, export contacts | Direct financial and data loss |
| App secret key | Forge sessions or tokens | Account takeover |
| Ad or analytics tokens | Change or drain campaigns and data | Wasted spend, corrupted tracking |
- Scanner requests /.envBots try this URL on many sites
- Server returns the fileNo rule blocks dotfiles
- Secrets copiedDB, SMTP and API keys read
- Abuse of your systemsData theft, spam, fraud
- Leads and trust lostDowntime, blocklists, clean-up
The break is the web server serving a file it should never serve.
How to check if your site has it
Open the URL in a private window
Visit https://yourdomain.com/.env. A 403 or 404 page is good. If you see lines like DB_PASSWORD=..., the file is exposed.
Check with curl
Run the command below. A 200 status with content means exposed. Do this for the main domain and for every subdomain and staging site.
Check common variants
Try /.env.local, /.env.production, /.env.backup, /.env.example and /app/.env, /config/.env, /api/.env. Frameworks and old deployments often leave these.
Search for a soft 200
Some sites return a 200 with an HTML error page. Read the body: only real KEY=value lines count as a leak.
for p in .env .env.local .env.production .env.backup; do
printf "%s " "$p"
curl -s -o /dev/null -w "%{http_code}\n" "https://yourdomain.com/$p"
doneHow to fix it
There are two parts: stop the file being served, then rotate the secrets. Do both. Blocking alone does not undo a leak that already happened.
Block the file right now
Add a server rule (see the tabs below) or temporarily delete or rename the file if the app can run without it.
Move it out of the web root
Point the domain at the framework's public folder (for Laravel, the public directory) so the project root and .env are not reachable. Keep .env one level above.
Rotate every secret
Change the database password, SMTP credentials, API keys, app key and any tokens. Update the new values in the .env and restart or clear config caches.
Review for misuse
Check database users, API dashboards, email sending logs and ad accounts for activity you do not recognise.
Keep it out of Git
Add .env to .gitignore and commit only a .env.example with empty values.
Apache (.htaccess or vhost)
Add: <FilesMatch "^\.(?!well-known)"> Require all denied </FilesMatch>. On Apache 2.2 use Order allow,deny and Deny from all instead. Reload Apache.
Nginx
Add inside the server block: location ~ /\.(?!well-known) { deny all; return 404; } then run nginx -t and reload Nginx.
Fix the document root
Set the root to the public subfolder, not the project folder. This is the real fix; the rules above are a safety net.
Find stray .env files
WordPress itself does not use .env, but some themes, Bedrock setups and developer tools do. Look in the site root and wp-content via your host's file manager or SFTP.
Delete or move it
Remove copies that are not needed. On Bedrock, keep .env above the web folder.
Add a block rule
On Apache hosts add the FilesMatch rule above to .htaccess. On Nginx hosts ask your host to add the location rule.
Not affected on the store itself
Shopify hosts your storefront and you cannot upload a .env there. Check any separate app, custom backend or headless front end you run on your own server instead.
Rotate keys if pasted into a theme
If someone pasted an API key into theme code, remove it and rotate the key in the service that issued it.
Not affected on Webflow hosting
Webflow does not serve arbitrary server files. Check any separate backend, proxy or serverless app you connect to the site.
Remove secrets from custom code
Do not paste private API keys into Project Settings > Custom Code or embeds. They are visible in the page source. Rotate any you did.
Not affected on Wix hosting
You cannot place a .env file in a Wix site. Check any external server your site calls.
Keep secrets in Secrets Manager
If you use Velo, store keys in the Secrets Manager instead of page code, and rotate any that were exposed.
Not affected on Squarespace hosting
You cannot upload server files such as .env. Check any separate server or tool you connect.
Remove pasted keys
Do not place private keys in Code Injection. It is public in the page source. Rotate any that were.
location ~ /\.(?!well-known) {
deny all;
return 404;
}<FilesMatch "^\.(?!well-known)">
Require all denied
</FilesMatch>Exposed
- /.env returns 200 with passwords
- Domain points at the project root
- Secrets unchanged since the leak
Fixed
- /.env returns 403 or 404
- Domain points at the public folder
- All secrets rotated and old ones revoked
How to confirm it's fixed
- https://yourdomain.com/.env returns 403 or 404 in a private window
- The curl loop shows no 200 for .env, .env.local, .env.production, .env.backup
- Staging and other subdomains return 403 or 404 too
- The site and its forms still work after rotating secrets
- Old database, API and mail credentials are revoked, not just replaced
- Access logs show no requests to the file after the fix returned 200
How to prevent it happening again
- Always serve from a public folder, never the project root
- Keep dotfile blocking in the server config as a default for every site
- Add .env to .gitignore and deploy secrets through your host's environment settings
- Do not upload backups or copies such as .env.bak to the server
- Re-test /.env after every deploy, migration or server change
- Give each service its own key with minimal permissions so a leak does less harm
How FunnelGuard handles this
FunnelGuard does not check for an exposed .env file today. It is a possible future check, not a current feature.
What FunnelGuard does do is run your real customer journeys on a schedule: lead forms, checkouts, booking and chat buttons. It checks each step, the tracking hits sent to ad and analytics platforms, and whether test leads reach your inbox and CRM. If a leaked or rotated key breaks a form, an email or a tag, that kind of failure can show up there, but FunnelGuard will not tell you the cause is an exposed file.
To watch for this yourself, add /.env to a post-deploy checklist and run the curl loop above. You can also schedule that command from a cron job or CI step, or use a vulnerability scanner or your host's security tools that test for sensitive files. Repeat it for every subdomain.
Questions people ask
How do I check if my .env file is publicly accessible?
Open https://yourdomain.com/.env in a private browser window, or run curl -I on the same URL. A 403 or 404 means it is blocked. If you see lines such as DB_PASSWORD=..., it is exposed and you should block it and rotate the secrets.
Why is my .env file visible in the browser?
Usually the domain points at the project root instead of the public folder, or the server has no rule denying dotfiles. A deployment or migration may also have dropped an earlier block rule. Fix the document root and add a deny rule.
How do I block access to .env in Nginx?
Add location ~ /\.(?!well-known) { deny all; return 404; } inside your server block, run nginx -t, then reload Nginx. Also set the web root to the public folder so the file is not in it.
How do I block .env in Apache or .htaccess?
On Apache 2.4 add a FilesMatch rule for names starting with a dot, with Require all denied, and keep .well-known allowed. Reload Apache if you edited the main config. Moving the file out of the web root is safer still.
What should I do if my .env file was exposed?
Block the file first, then rotate every secret in it: database password, API and mail keys, app key and tokens. Revoke the old ones, check logs and provider dashboards for misuse, and review access logs for earlier requests to /.env.
Is an exposed .env file a data breach?
It is a serious security exposure. If someone used the secrets to access personal data, it may count as a breach under laws such as GDPR. Get advice on your reporting duties if you find evidence of access.
Does FunnelGuard detect an exposed .env file?
No. FunnelGuard does not check for this yet; it is a possible future check. It monitors funnel journeys, tracking hits and lead delivery, so test /.env yourself after deploys.
Can Shopify, Wix or Squarespace sites have an exposed .env file?
Not on the hosted platform itself, because you cannot upload server files there. The risk applies to any separate server, backend or app you connect, and to private keys pasted into public page code.