A simple diagram of the PHP File Inclusion risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for PHP File Inclusion
Testing path: establish a baseline, make one controlled change, and verify the effect.

01Issue

Overview

PHP’s include and require statements load a file into the running program. Applications use them for fixed templates and shared code. A file-inclusion weakness occurs when request data can choose a file that the application loads, rather than selecting from a controlled set. This differs from path traversal: traversal reaches an unintended path, while inclusion means PHP processes the selected file as part of the application.

Common causes

  • A request parameter is passed directly to include or require.
  • A partial string check is used instead of resolving and validating the final path.
  • Remote stream wrappers or URL inclusion are enabled and user input can influence the target.
  • The PHP worker can read more files than the feature requires.

References: PHP: include ↗PHP: filesystem configuration ↗OWASP WSTG: Directory Traversal and File Include ↗

02Examples

EXAMPLE

Illustrative route: GET /page?name=help should map help to a fixed file such as templates/help.php. In a test deployment, compare it with GET /page?name=unknown. The safe result is a controlled not-found response. If a marker fixture is used, its appearance must be confirmed in the rendered response; an include warning alone is not proof of sensitive file access.

03Impact

User-controlled data must reach an include operation. The selected target must be reachable under PHP’s configuration and the process’s file permissions. For an impact beyond an error, the included file must affect execution or expose information through the application.

A local file inclusion may reveal source or configuration content, or execute PHP code if the selected file contains executable PHP and is included in an executable context. Remote file inclusion requires particular configuration and network conditions. A path in a request, a warning message, or a blank response does not prove that a file was included.

04Testing

Test cases

1. Check whether input changes the included file

Identify a parameter used to choose a PHP template or file. Compare a normal request with a path to a controlled marker and inspect the resulting output.

Example: A known marker can show that an unintended file was included. A generic error does not show which file was loaded.

GET /page?template=..%2Ftest-marker.txt HTTP/1.1
Host: app.example.test

2. Check alternative file selection paths

Compare relevant parameter locations, encoding, and configured file handling in the actual application. Review whether remote includes or wrappers are enabled before testing them.

Example: A path parser may normalize separators differently. Record the exact requested and resolved paths.

GET /page?template=..%252Ftest-marker.txt HTTP/1.1
Host: app.example.test

3. Review inclusion controls

Inspect code and configuration for dynamic include or require calls and check whether names map to a fixed allowlist. Separate file read, inclusion, and execution claims.

Example: Reading a marker is not proof of PHP execution. Report only the behavior observed.

Testing references: PHP: include ↗PHP: filesystem configuration ↗OWASP WSTG: Directory Traversal and File Include ↗

05Mitigation

Replace request-derived file paths with an allowlist that maps short identifiers to fixed files. If dynamic paths are unavoidable, resolve the final canonical path and verify it remains below the intended directory before including it. Disable remote inclusion, avoid executing user-uploaded files, reduce the PHP worker’s filesystem permissions, and return generic errors while keeping useful diagnostics in protected logs.

Retest

Repeat the valid, unknown, and marker-file cases. Confirm only allowlisted templates load, no external location is included, and normal page selection still works.