What is a .env file, and why should you care?

You probably do not manage your website's code day-to-day. But somewhere inside your website's file structure, there is almost certainly a file called .env — or wp-config.php if you use WordPress — that contains the keys to your kingdom.

Database usernames and passwords. API keys for payment processors. Email service credentials. Sometimes even access tokens for cloud services like AWS or Google Cloud.

If that file is publicly accessible — meaning anyone with a browser can type your-domain.com/.env and read it — you have a critical vulnerability. And it is far more common than you think.

Check right now

Open your browser and type: yourdomain.com/.env — if you see text (not a 404 error page), you have a critical vulnerability that needs fixing today. Also try yourdomain.com/wp-config.php and yourdomain.com/.git.

How does this happen? (It's not as stupid as it sounds)

Configuration files end up publicly exposed for entirely understandable reasons:

None of these are acts of recklessness. They are accidents. But on the internet, accidents are permanent until someone fixes them.

"The most dangerous vulnerabilities in small business websites are not sophisticated zero-day exploits. They are configuration errors — files left in the wrong place, permissions set incorrectly. These are entirely preventable."

— PwC UK, Cyber Security Threat Intelligence Report, 2025

What can an attacker actually do with your .env file?

Let's be specific, because "security risk" is too abstract to act on.

If your database credentials are exposed:

If your email service API keys are exposed:

If your payment processor keys are exposed:

🚨
AWS credentials are especially dangerous

"We have seen cases where exposed AWS credentials led to cloud bills of over £50,000 in a single weekend. Attackers spin up cryptocurrency mining operations on your account the moment they find valid keys." — KPMG UK, Incident Response Case Studies, 2025

11 months The average time an exposed configuration file sits undetected on a UK small business website ProtectPatch audit data, 2025–2026

How to fix it — and what to do if it's been exposed

Immediate fix steps:

<Files ".env">
  deny from all
</Files>

Longer-term protection:

"The cost of rotating credentials proactively is an afternoon. The cost of rotating them after a confirmed breach — plus customer notification, forensic review, and potential ICO reporting — is weeks and thousands of pounds."

— The Guardian, Small Business Security supplement, January 2026

Key takeaways

  • Exposed .env files are the 2nd most common critical finding in UK website audits
  • They typically sit undetected for months or years — no alarm ever fires
  • Consequences range from database theft to £50,000+ cloud bills
  • The fix takes less than 30 minutes once you know the file is exposed
  • The only way to know is to check — right now, not next month