CCyberwiki

Exposed sensitive files

Exposed sensitive files
ClassSecurity misconfiguration; Reconnaissance
Also known asBackup and unreferenced files; sensitive information in an externally accessible file
CWECWE-538: Insertion of Sensitive Information into Externally-Accessible File or Directory; CWE-530: Exposure of Backup File to an Unauthorized Control Sphere
OWASP Top 10A02:2025 Security Misconfiguration; CWE-538 itself is listed under A01:2025 Broken Access Control
ATT&CKT1595.003 Wordlist Scanning
AffectsAny site whose document root contains .env, .git, backup copies, archives or database dumps

Exposed sensitive files hold secrets or source code and sit in the folder a web server publishes, so anyone who guesses the name can download them. Visitors are allowed to open the file, yet the secret inside was never meant for them.1 The usual cases are the environment variable file, the .git folder and backup copies. Pages and features left enabled without need are a listed cause of security misconfiguration, and these files are one form of it.2

Description

A web server publishes a folder, the document root, and sends a visitor any file it can reach by mapping a URL to a path.3 It has no idea which of those files are secret, so a dotfile in the published folder goes out like an image.

The folder is often published by mistake. A Laravel project keeps .env in its root, and publishing the whole project folder puts many private configuration files on the open Internet; the document root has to be the public folder.4 In Next.js, every file inside public/ is served from the base URL.5

Backups appear when someone copies a file to keep it. Editors such as emacs write file~ while editing, and a copy renamed to login.asp.old is served as plain text instead of being run, so a visitor downloads the source.6 Other common backup extensions are .~bk and .BAK, and the source code of old files left in the webroot can often be retrieved.7 Archives (.tar, .zip, .gz) can hold copies of all files in or even outside the webroot.6

Mechanism

The attacker needs no flaw in the application, only a list of likely file names. In wordlist scanning, content discovery tools such as Dirb, DirBuster and GoBuster request every name on a stock or hand-made list and note which pages and folders exist.8 One request is enough:

GET /.env HTTP/1.1
Host: example.com

HTTP/1.1 200 OK

DB_PASSWORD=...
STRIPE_SECRET_KEY=...

An open .git folder lets an attacker download every commit ever made, along with the repository's settings, branches and refs. Its config file can contain a remote address of the form https://<user>:<token>@github.com/<user>/<repo>.git, which includes an access token.9

Impact

The attacker gets whatever the files hold: database passwords, cloud keys, source code and, in a dump, the data itself. Old files can also contain vulnerabilities fixed in the current version; viewdoc.old.jsp may hold a directory traversal flaw that viewdoc.jsp no longer has.6

Notable incidents

Extortion through .env files (2024)

The campaign that Unit 42 described scanned more than 230 million unique targets and 110,000 domains and collected over 90,000 unique variables from .env files. About 7,000 were keys to company cloud services, and 1,500 were linked to social media accounts. A malicious Lambda function requested http://<target>/.env from each domain and stored the credentials it found in an attacker-controlled S3 bucket. With those keys the attackers took data from victims' cloud storage and left a ransom note without encrypting anything first. Unit 42 traced the initial access to exposed .env files in the victims' own web applications; the cloud providers' services had no flaw.10

EMERALDWHALE (2024)

Between August and September 2024, an operation reported by Sysdig scanned for servers with exposed Git configuration files. It took over 15,000 cloud service credentials, plus logins for more than 10,000 private repositories.9 The scans covered an estimated 500 million IP addresses with the open-source tools httpx and Masscan and also looked for .env files in Laravel applications. Lists of exposed URLs sold on Telegram for about $100.11 In Sysdig's view, secret management alone cannot prevent this, because credentials can leak from too many places.9

Detection

Request the paths from outside the network and read the status code: /.env, /.git/config, /index.php.bak, /site.zip. A 200 with file content means the file is exposed. A fuller path list adds editor backups, .old and .bak copies, archives, snapshot folders and log files, which may hold session IDs and visited URLs.6

Prevention

Publish only what is meant to be public

Point the document root at a folder that holds only public files, such as Laravel's public.4 In Next.js, put in public/ only files that are meant to be downloaded, and keep .env* in .gitignore; the default create-next-app template already does this.512 Remove editor backups, .old and .bak copies, archives and snapshots from the web tree, and do not edit files in place on a production server.6 Across the organization, make it a rule that backups of the site's source code never sit inside the webroot.7

nginx

Laravel's deployment page ends its server block with this rule, which denies every path segment that starts with a dot except /.well-known:4

location ~ /\.(?!well-known).* {
    deny all;
}

Apache

Deny access to the whole file system by default, then grant access only to the directories that are published:3

<Directory "/">
    Require all denied
</Directory>

Express

The dotfiles option of serve-static controls requests for files that begin with a dot. allow gives them no special treatment, deny answers 403, and ignore answers as if the file did not exist (404).13 Set it to deny.

After an exposure

Every credential in an exposed file counts as leaked: rotation it, as Responding to a leaked API key describes.

In SecFlash

The Security page reports SF-SEC-617 for a readable .env, SF-SEC-618 for a readable backup or old copy, and SF-SEC-652 for a hidden file or folder such as .git. The Exposure page reports SF-EXP-307 for a readable environment file, SF-EXP-308 for a config backup, SF-EXP-411 for backups, dumps, logs or settings files, SF-EXP-412 for a backup archive, SF-EXP-413 for a database dump and SF-EXP-414 for a .DS_Store file that lists the names next to it.

See also

References

  1. back MITRE. "CWE-538: Insertion of Sensitive Information into Externally-Accessible File or Directory". Common Weakness Enumeration.
  2. back "A02:2025 Security Misconfiguration". OWASP Top 10:2025. OWASP Foundation.
  3. a b "Security Tips". Apache HTTP Server 2.4 documentation.
  4. a b c "Deployment". Laravel 12.x documentation.
  5. a b "public Folder". Next.js Docs. Vercel.
  6. a b c d e "WSTG-CONF-04 Review Old Backup and Unreferenced Files for Sensitive Information". OWASP Web Security Testing Guide v4.2.
  7. a b MITRE. "CWE-530: Exposure of Backup File to an Unauthorized Control Sphere". Common Weakness Enumeration.
  8. back MITRE. "Active Scanning: Wordlist Scanning, T1595.003". MITRE ATT&CK.
  9. a b c Sysdig Threat Research Team (30 October 2024). "EMERALDWHALE: 15k Cloud credentials stolen in operation targeting exposed Git config files". Sysdig.
  10. back Unit 42 (15 August 2024). "Leaked Environment Variables Allow Large-Scale Extortion Operation in Cloud Environments". Palo Alto Networks.
  11. back Toulas, Bill (30 October 2024). "Hackers steal 15,000 cloud credentials from exposed Git config files". BleepingComputer.
  12. back "How to use environment variables in Next.js". Next.js Docs. Vercel.
  13. back "serve-static". Express middleware documentation.