Skip to content

My .env file is publicly accessible. How do I fix it?

Short answer

Short answer: block public access to the file, rotate every private credential it contained, and verify the host no longer serves it. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.

Check yours now
Read-only. No writes or row contents.

What the publicly exposed .env file check covers

A reachable .env file may disclose database credentials, API tokens, or internal configuration. Even a file that appears empty today can become sensitive when a later deployment adds variables.

The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.

A denied response is useful evidence only for that exact path and host. Check common deployment aliases and case variants without requesting private content; do not download or redistribute values you discover.

Understand the evidence before changing code

Remove the file from the public build directory, add it to the correct ignore rules, and configure the host to deny dotfiles. Rotate every private credential that was served rather than relying on removing the file.

Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.

Apply the narrow, safe change

Keep runtime values in the host's secret manager and load them server-side. If a static site needs a public setting, create a separate explicit public config file that contains no private values.

Deny dotfiles except the required well-known directory · nginx
location ~ /.(?!well-known) {
  deny all;
  return 404;
}

Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.

Verify the production result

After redeploying, request the exact file path and confirm it returns a denial or not-found response. Also review the build output and any CDN cache to ensure an earlier copy is no longer reachable.

Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.

Keep the issue from returning

Add a deployment check for dotfiles and secret patterns, and review ignore rules when changing frameworks. A .gitignore entry does not prevent a file already copied into a static output directory.

Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.

Limits and next steps

A public scan can confirm a response at one URL but cannot know every secret that was inside the file. Use provider rotation and access logs to assess the impact.

Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.

A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.

Key facts

  • A .gitignore rule does not stop a build from copying a file into public output.
  • Removing a served file does not revoke credentials it contained.
  • A CDN can retain an earlier copy after the origin is fixed.

Questions

Can a clean publicly exposed .env file check prove the app is secure?
No. It is evidence about the advertised public surface only. Treat any private value in a served file as compromised and rotate it.
What should I do first if the finding is real?
Remove the file from output, deny dotfiles at the host, and rotate credentials.
Does ProofForge change application data?
No. The scan is read-only and does not sign in, write records, or use a discovered secret. You make and review any remediation in your own project.
What should I do after the repair?
Request the exact production path after deploy and check the CDN response.

Official documentation referenced

Related

Last updated 2026-11-25 · Reviewed by ProofForge · Methodology · Markdown