Safeguard
Application Security•

CWE-219 Sensitive Files Under the Web Root: Find and Fix

Database files, credentials and backups inside the document root can be fetched by URL. CWE-219 explained with server config to block them.

Safeguard Security Team
2 min read

CWE-219, Storage of File with Sensitive Data Under Web Root, means the product keeps sensitive data inside the web document root without enough access control, so untrusted parties may be able to fetch it.

MITRE points out that besides public pages and code, products often leave sensitive data, code that is not meant to be invoked directly, and other files under the document root. If the server is not set up to block direct access, an attacker can request them by URL.

How it happens

A developer puts a data file, backup, config or database next to the pages that use it because it is convenient. The web server serves whatever is in the root unless told otherwise. MITRE's observed examples:

What an attacker gains

MITRE lists confidentiality: reading application data. A fetched database or credential file can be the whole breach.

How to find it

MITRE lists no detection methods. Check for it directly:

  1. List the files under each document root and flag anything that is not meant to be public: databases, dumps, backups, .env files, config, logs.
  2. Request those paths from outside, without logging in.
  3. Run a dynamic scan against the deployed site, which tries common file names for you.

How to fix it

MITRE gives two mitigations:

  1. Avoid storing information under the web root. Keep data and configuration in a directory the server does not serve.
  2. Set access control permissions to prevent reading or writing of sensitive files inside or outside the web directory.
# Defence in depth: refuse common sensitive extensions
location ~* \.(sqlite|db|bak|sql|env|log)$ {
    deny all;
}

This is a backstop. The real fix is moving the files out of the served directory.

Quick check

Is an unlinked file safe under the web root?

No. If the server serves it and the name can be guessed or found, it can be fetched.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.