Configuration Files Exposed

Configuration files containing settings and secrets, such as .env files, can be downloaded from the web server without authentication.

SeverityHigh
CVSS 3.17.5 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N Open in the calculator
CVSS 4.08.7 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-219: Storage of File with Sensitive Data Under Web Root
OWASP Top 10A01:2025 Broken Access Control
MITRE ATT&CKT1552.001 Credentials In Files
CategoryInformation Disclosure

Description

Configuration files are reachable through the web server and returned as plain text. Common examples are the .env files used by many frameworks and container deployments, appsettings.json, application.properties and application.yml, config.json, docker-compose.yml, .npmrc, and copies of files such as wp-config.php. The usual cause is a web server whose document root is the project directory rather than the framework's public directory, so that files beside the code become downloadable, and files with extensions the server does not run as code, such as .env, .yml, .json and .ini, are then returned as they are. Other causes are configuration files copied into static content folders and storage buckets used to host the site.

The files typically hold secrets, and an attacker who downloads them, without authentication, gains access that often extends well beyond the application. Database connection strings can give direct access to stored data, cloud access keys to the hosting account, and API tokens to payment, email, storage and other services. The secret keys an application uses to sign or encrypt sessions and cookies can allow session tokens or cookies to be forged, which in some frameworks can lead to code execution. The impact depends on the secrets present, but a single exposed file commonly leads to a significant compromise.

The weakness is identified by requesting common configuration file names at the site root and in likely subdirectories with content discovery tools and wordlists, which most web scanners also include.

Remediation

Move configuration out of reach of the web server, and treat its secrets as compromised:

  • Set the web server's document root to the framework's public directory only, such as public in Laravel and Symfony projects, so that configuration and code sit outside it.
  • Keep secrets out of files deployed with the code: supply them at run time from environment variables set by the platform, or from a secrets manager.
  • Block requests for hidden files and common configuration file names at the web server as defence in depth, as below.
  • Rotate every credential, token and key in the exposed files, invalidate sessions signed with exposed keys, and review the logs of the affected services for misuse.
# nginx: refuse hidden files such as .env, but keep ACME challenges working location ~ /\.(?!well-known/) { deny all; } # Apache: refuse files whose names begin with a dot <FilesMatch "^\."> Require all denied </FilesMatch>

Confirm the fix by requesting the exposed files and common configuration names again: each should return 404 or 403, and the rotated credentials should no longer work.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding