Home / Core Health / Verify .env and credential files are not publicly accessible
Exposed Files · Scan Check Guide

Verify .env and credential files are not publicly accessible

15 min Impact: high Effort: low ✓ Scan-verified — no manual checkbox

A .env file holds your application's real secrets — database passwords, API keys, third-party credentials — in plain text. If it's sitting in your site's public web root, anyone who requests yoursite.com/.env can read every one of those secrets directly.

An exposed .env file reveals database credentials, API keys, and secret tokens — complete account compromise in seconds. This is one of the most common and catastrophic misconfigurations.

The full picture

Publicly accessible .env and credential files represent one of the more severe, directly exploitable vulnerabilities a website can have, since these files typically contain genuine, sensitive configuration data — database credentials, API keys, secret tokens — that provide direct, often immediate access to systems and data well beyond the website itself if discovered and accessed by an attacker.

This vulnerability commonly occurs through a specific, avoidable configuration oversight — development environment files not properly excluded from the publicly accessible web root, meaning a file intended purely for server-side configuration reading becomes directly downloadable by anyone who knows or guesses its location.

The severity here genuinely exceeds most other individual security issues discussed throughout this broader hardening work, since successful exploitation doesn't require any sophisticated attack technique — an attacker who discovers this exposure gains direct access to whatever credentials the file contains, potentially providing immediate access to databases, third-party services, or other systems the exposed credentials protect.

Verification and remediation here deserve genuine priority and thoroughness — confirming these files are genuinely inaccessible from the public web, not merely absent from obvious locations, and reviewing your broader deployment process to ensure this category of file is consistently, reliably excluded from public access going forward, addresses both the immediate exposure and the underlying process gap that allowed it.

How to fix it

  1. 1
    Confirm whether it's actually exposed
    Visit https://yoursite.com/.env directly — if it downloads or displays content, this is urgent.
  2. 2
    Move it outside the public web root
    Your .env file should live OUTSIDE the folder your web server serves publicly — one level up, not inside /public or /www.
  3. 3
    Block it at the server level as a backup
    Add a rule denying access to any .env file, regardless of location — most web servers support this in a few lines of config.
  4. 4
    Rotate every secret that was exposed
    If the file WAS publicly accessible for any period, treat every credential in it as compromised — rotate database passwords and API keys, don't just fix the exposure.

Common mistakes

How you'll know it's done

https://yoursite.com/.env returns a 403 or 404, and every credential that was in the file has been rotated.

H.I.V.E. checks this automatically

Fix it, then re-scan — the check confirms itself. No manual checkbox, the scan is the truth.

Run this check in H.I.V.E. →