How to Check for Exposed Secrets in .env Git and Source Maps

How to Check for Exposed Secrets in .env Git and Source Maps EduTechBuddy.com © edutechbuddy.com
How to Check for Exposed Secrets in .env Git and Source Maps © edutechbuddy.com
Learn how to quickly test if your app is leaking sensitive secrets through public .env files, exposed .git folders, or JavaScript source maps, and what steps to take if you find a vulnerability.

Simple oversights can leave sensitive secrets open to anyone with a browser. Publicly accessible .env files, open .git directories, and unprotected JavaScript source maps often slip through in fast-moving app development and deployment. These mistakes can put API keys, credentials, and internal logic at risk without attackers needing to breach your server or use special tools. The OWASP Web Security Testing Guide flags publicly served .env files as a type of forgotten or unreferenced deployment artifact that can leak credentials and secrets. Other risky files include private-key files like .pem and .key, infrastructure state files such as .tfstate, password files, package-manager configs, and container credentials. These files often end up exposed through deployment routines, backup uploads, cloud storage, or build artifacts, not through any intended app feature.

Testing for Publicly Exposed Secrets

To see if your app leaks secrets, try visiting https://yourapp.com/.env and https://yourapp.com/.env.local. A 404 error or your usual app page means your environment files are not exposed. If you get plain text with KEY=value pairs, every value is visible to the public. In that case, rotate all affected keys right away and update your deployment process to block these files from being served again. OWASP advises that credentials and secrets should never be publicly served, and a public .env response signals a configuration and deployment failure, not just a coding slip.

Then, check for an exposed .git directory by opening https://yourapp.com/.git/HEAD. If you see something like ref: refs/heads/main, your repository metadata is out in the open. Attackers can rebuild your source code and access earlier commits, including secrets that may have been removed from later versions. Block access to the .git path at your hosting provider and rotate any credentials that ever appeared in your repository history. OWASP points out that fixing this means tracking artifact inventories and past deployment locations, not just removing the current URL. Cloud storage and CI/CD build artifacts may keep copies of .env files or compiled packages with embedded secrets even after the original deployment is fixed.

Check your main JavaScript file for a //# sourceMappingURL= comment at the end. If you find one, try downloading the matching .map file. If you succeed, your original source code, comments, and file names are exposed. Source maps alone do not directly leak secrets, but they make it much easier for someone to search for keys or hidden routes. OWASP defines a source map as a file linking a minified or transformed JavaScript or CSS asset to its original source. When a map includes sourcesContent, the original source can be rebuilt for review, including file names, comments, route names, and implementation details. Public maps may reveal API endpoints, internal routes, authentication logic, expected response structures, hidden fields, API keys, tokens, or configuration values. OWASP recommends turning off source maps in production and checking bundles for sensitive values before release (OWASP excessive-data-exposure guidance).

Responding to an Exposure

If you find any of these exposures, act fast. Rotate every key or credential that could have been in the exposed file or repository history before removing the file from your deployed output. Do not just delete the file from your repository; make sure it is gone from your production environment. After redeploying, check the same URLs in a fresh browser session to confirm the fix. OWASP’s secure-development material places exposed credentials within the larger secrets-management challenge, alongside API-key protection, credential storage, vault integration, and rotation practices. Removing the file from the current deployment does not erase copies kept in repository history, backups, storage buckets, build artifacts, browser caches, logs, or third-party systems.

Security Checks When Acquiring an App

Before buying an app, run these checks. If any of the URLs return a valid response, ask the seller in writing when the exposure happened and which credentials were rotated after. Consider adding a rotation clause to your contract for protection. OWASP specifically lists .env files among the artifact types testers should check during reviews of old, backup, and unreferenced files, and notes that the technical risk goes beyond one application setting because a single artifact can hold database credentials, cloud keys, signing material, deployment variables, or internal service configuration.

Limitations of These Checks

These tests only show what an unauthenticated user can reach from a browser. They do not check server-side code, authenticated behavior, or private infrastructure. A clean result lowers risk but does not guarantee full security. OWASP guidance treats secret exposure as a documented application-security weakness that needs fixing, but it is not a legally binding requirement unless adopted by a specific jurisdiction or sector regulation.

For more on how repository exposures can lead to security threats, see this earlier breakdown on spotting malicious code in Git repositories.

Camila Ferreira Editor EduTechBuddy.com
Co-Founder

Camila Ferreira

Camila Ferreira is the Co-Founder of EduTechBuddy, where her editorial focus is programming education and practical software development skills. Her primary subjects include Python programming, Git version control, and the fundamental concepts beginners need to understand when working with code.