Skip to content

Exposed env.js Checker

Does your site hand out its API keys in a public config file? Check your own domain for env.js, .env, config.json and an exposed .git/config, or paste a file and find the secrets in your browser. Every finding says whether to rotate now or whether the key is public by design.

Only check sites you own or are authorised to test.

We send up to 19 ordinary GET requests to that site: the homepage, one made-up missing file, and a fixed list of config paths (env.js, .env, config.json, .git/config and similar). No crawling, no attack payloads. File contents are never returned or stored; findings show only the type, the first characters and the length.

Loading…

Sample report · illustrative data

Exposed config check: app.example.com

A made-up React app behind nginx, deployed as one Docker image. Its entrypoint writes every environment variable into /env.js at start-up.

2 secrets a browser can read. Rotate first, then remove.

https://app.example.com · 19 requests · 3.4 s

Paths checked (extract)

PathResultHTTP
/env.jsExposed200
/config.jsonNot the file (fallback page)200
/.envNot found404
/.git/configAccess denied403

Findings

SeverityWhat it isWhereValueWhat to do
CriticalDatabase URL with a password · Secret: rotate now/env.js · DATABASE_URL · line 5Ex•••• (14 chars)Change the password, check the database is not reachable from the internet, then remove it from the file.
CriticalStripe secret key (live) · Secret: rotate now/env.js · STRIPE_SECRET_KEY · line 4sk_l•••• (40 chars)Roll the key in the Stripe Dashboard, move the call behind your own API.
MediumGoogle API key (e.g. Maps) · Check it/env.js · MAPS_KEY · line 6AIza•••• (39 chars)Restrict it by HTTP referrer to your domains and to the APIs it needs.
OKStripe publishable key · Public by design/env.js · STRIPE_PUBLISHABLE_KEY · line 3pk_l•••• (33 chars)No action.

Made-up example data. Your own run checks your site live. The report download needs a plan.

TL;DR

What this tool is

4 points
  • Many single-page apps load a runtime config file such as /env.js (window._env_ = {...}) that a container entrypoint writes from environment variables. If that script copies every variable, database passwords and API keys end up in a file anyone can download.
  • Check my site: enter a domain you own. We request the homepage and a fixed list of 17 config paths (env.js, .env, config.json, .git/config and similar), ignore the site's fallback page, and report what is really served.
  • Paste a file: paste env.js, a .env file or a JavaScript bundle. Detection runs in your browser and nothing is sent anywhere.
  • Each finding is sorted into "Secret: rotate now", "Check it" or "Public by design: OK" (Stripe publishable keys, Firebase web config, Supabase anon keys, Sentry DSNs), with the fix. Values are always masked.

How secrets end up in public config files

  • Runtime env.js. One Docker image, many environments: an entrypoint script writes window._env_ = {...} into the web root at start-up. Written as “every variable” instead of an allow-list, it publishes the database URL and server keys along with the API URL.
  • Build-time prefixes. NEXT_PUBLIC_, VITE_ and REACT_APP_ values are written into the JavaScript bundle. A secret given one of those prefixes “to make it work” is in every visitor's browser.
  • The .env file in the web root. A static site or PHP app deployed with its .env next to index.html, and a server that serves dotfiles.
  • Source maps and .git. Public .map files rebuild your original source; an exposed .git folder can give away the whole repository and its history.

What the site check requests

The homepage, one made-up missing file (to learn the site's fallback), and these paths. Nothing else, no crawling, at most 19 requests, 5 seconds each:

/env.js /__env.js /env-config.js /runtime-env.js /config.js /app.config.js /assets/env.js /static/env.js /js/env.js /.env.js /config.json /assets/config.json /env.json /.env /.env.local /.env.production /.git/config

How to fix it, by framework

  • Next.js. Only NEXT_PUBLIC_ variables are inlined into client JavaScript; everything else stays on the server. Never prefix a secret. Call the third-party API from a Route Handler or Server Action and return only the result.
  • Vite. VITE_ variables are bundled into client code and Vite says they should not hold API keys. Do not widen envPrefix to an empty string.
  • Create React App. REACT_APP_ variables are embedded into the build; CRA says not to store any secrets in the app.
  • Angular. Files in src/environments/ are bundled into the client. Put only public settings in environment.ts; keep keys behind a server-side proxy.
  • Runtime env.js from a Docker entrypoint. Write an allow-list, never the whole environment: name each public variable (API URL, publishable keys, feature flags) and skip everything else. Fail the container start if a name containing SECRET, PASSWORD, PRIVATE or TOKEN would be written.
  • nginx. Refuse dotfiles in the web root: location ~ /\.(env|git) { deny all; } (or location ~ /\. { deny all; } with an exception for /.well-known/). Better still, never copy .env or .git into the image.
  • Source maps. Do not publish production .map files, or upload them to your error tracker and keep them off the public web server.

Rotate first, then remove. Deleting the file does not un-leak the key. Issue a new credential, verify it works, switch every consumer, revoke the old one, check the provider's logs, and only then clean up the file and the build. The secret rotation order planner sequences several keys, and the leaked credential response walks the whole incident. Add CI secret scanning (such as the secret scanner or GitHub push protection) so it does not happen again.

Frequently asked questions

What is env.js and why is it a risk?

env.js is a small script many single-page apps load before the main bundle so one Docker image can run in several environments. A container entrypoint writes it at start-up, usually as window._env_ = { ... }. It is a normal public file, so everything in it can be read by anyone. The risk is an entrypoint that writes every environment variable, including database URLs, secret API keys and signing secrets, instead of an allow-list of public values.

Is it legal to check a site for exposed env.js files?

Check only sites you own or are authorised to test. The checker sends ordinary GET requests for well-known public paths, the same requests a browser makes, but you still need permission, and the tool asks you to confirm it before every check.

Which keys are safe to have in front-end code?

Keys built to be public: Stripe publishable keys (pk_), Clerk publishable keys, Firebase web API keys (Firebase says they only identify the project; Security Rules and App Check protect the data), Supabase anon or publishable keys (protected by Row Level Security) and Sentry DSNs. Google Maps browser keys are fine only if restricted to your domains. Anything called secret, service_role, private, password or a database URL must never reach the browser.

I found a secret in env.js. Should I delete the file first?

Rotate first. Deleting the file does not un-leak the key: crawlers, archives and anyone who already fetched it keep a copy. Issue a new credential, move every consumer to it, revoke the old one and check the provider logs for use you did not make. Then fix the entrypoint or build so the secret never reaches the file again.

Does NEXT_PUBLIC_ or VITE_ make a variable safe?

No, it does the opposite. Next.js inlines NEXT_PUBLIC_ variables into the JavaScript sent to the browser at build time, Vite exposes VITE_ variables to client code, and Create React App embeds REACT_APP_ variables in the build. The prefix marks a value as public. Never put a secret behind one.

Why does the checker say a path is a fallback page?

Many single-page apps answer every unknown URL with their index.html and status 200. The checker compares each response with the homepage and with a made-up missing file, and ignores HTML pages, so a 200 that is really the app shell is not reported as an exposed file.

The tools people use most on PlayCISO.

All tools