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
- 1Never serve env.js from a public web root path.
- 2For non-secret frontend config, use build-time injection (NEXT_PUBLIC_*, VITE_*, etc.).
- 3For runtime config, serve a minimal JSON endpoint that requires authentication or returns only non-sensitive values.
- 4If env.js already exists, audit it immediately and rotate any exposed credentials.
Code examples
Docker entrypoint (safe pattern: non-secrets only)
#!/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 hereNginx (block env.js from public access)
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.
More info disclosure checks
- MediumRails Session Cookie Missing HttpOnly Flag
- InfoServer header truncated
- InfoPHP session cookie naming exposes runtime
- Infoconfig.js / settings.js referenced (verify contents)
- InfoSitemap.xml publicly accessible
- InfoOpenAPI schema version exposed in URL
- LowCORS exposes internal CDN hostname
- InforeCAPTCHA site key exposure
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.