Inclusion of Sensitive Information in an Include File

Incomplete Variant
Structure: Simple
Description

This vulnerability occurs when sensitive data like passwords or system details is placed inside a publicly accessible include file. Attackers can directly request these files to steal credentials and compromise the application.

Extended Description

Include files (like .inc, .config, or library files) are often used to store common code or configuration settings. When these files contain hard-coded secrets such as database passwords, API keys, or administrative credentials, and are left in a web-accessible directory, they become a prime target. Attackers can simply browse to the file's URL to download its full source code, bypassing the main application's security controls entirely. To prevent this, never store sensitive information within web-accessible include files. Instead, move configuration containing secrets outside the web root or into environment variables and protected configuration files. Additionally, configure your web server to deny requests to files with common include extensions, and ensure your deployment process cleans directories of development or backup files that might inadvertently expose data.

Common Consequences 1
Scope: Confidentiality

Impact: Read Application Data

Potential Mitigations 2
Phase: Architecture and Design
Do not store sensitive information in include files.
Phase: Architecture and DesignSystem Configuration
Protect include files from being exposed.
Demonstrative Examples 1

ID : DX-104

The following code uses an include file to store database credentials:
database.inc

Code Example:

Bad
PHP
php
login.php

Code Example:

Bad
PHP
php
If the server does not have an explicit handler set for .inc files it may send the contents of database.inc to an attacker without pre-processing, if the attacker requests the file directly. This will expose the database name and password.
Modes of Introduction
Implementation