Skip to main content
InfoInfo disclosureOWASP A05:2021CWE-538

How to fix: env.js / environment.js referenced (verify contents)

A reference to env.js or environment.js was found in the page source. These files are commonly placed in the public directory as a deployment-time configuration injection point, and sometimes carry secrets, but just as often only carry a public deployment-stage flag (e.g. window.ENV = 'production'). This finding only matches the filename, it does not inspect the file's actual contents.

Why it matters

If this file does contain database URLs, API keys, or OAuth client secrets in plain text, any visitor can request it directly and extract credentials. A filename match alone does not confirm this: fetch the file directly and review its contents before treating it as a confirmed leak.

A common pattern in containerized deployments is to generate env.js at startup from environment variables and serve it as a static file. When secrets are included alongside frontend configuration, anyone who knows the file path (or finds the script tag) can read them. This check flags the reference for manual review.

How to fix it

  1. 1Never serve env.js from a public web root path.
  2. 2For non-secret frontend config, use build-time injection (NEXT_PUBLIC_*, VITE_*, etc.).
  3. 3For runtime config, serve a minimal JSON endpoint that requires authentication or returns only non-sensitive values.
  4. 4If env.js already exists, audit it immediately and rotate any exposed credentials.

Code examples

Docker entrypoint (safe pattern: non-secrets only)

bash
#!/bin/sh
# Only inject non-secret public config into env.js
cat > /app/public/env.js <<EOF
window.__ENV__ = {
  API_URL: "${API_URL}",
  FEATURE_FLAG_X: "${FEATURE_FLAG_X}"
};
EOF
# Secrets like DB_URL, SECRET_KEY must NEVER appear here

Nginx (block env.js from public access)

nginx
location ~* /env\.js$ {
  deny all;
  return 404;
}

References

Detected automatically by VulnRadar. The check id is env-js-leaked, stable across every scan so you can filter or diff on it.

See every info disclosure check

Questions

How severe is env.js / environment.js referenced (verify contents)?
VulnRadar rates this info severity in the info disclosure category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id env-js-leaked, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does env.js / environment.js referenced (verify contents) map to?
It maps to CWE-538. In the OWASP Top 10 it falls under A05:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for env.js / environment.js referenced (verify contents)

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

env.js / environment.js referenced (verify contents) | VulnRadar