Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Local and Remote File Inclusion?

File inclusion flaws let an attacker choose which file an application loads and executes, reading local files or, in the remote variant, running code fetched from elsewhere.

Illustration for the cybersecurity term Local and Remote File Inclusion
Home / Blog / Cybersecurity Terms / What Is Local and Remote File Inclusion?
17 November 2026

What Is Local and Remote File Inclusion?

What Is Local and Remote File Inclusion?

File inclusion vulnerabilities arise when an application decides which file to load based on a value the user supplies. Local file inclusion (LFI) reads and often executes a file already on the server; remote file inclusion (RFI) fetches one from a URL the attacker controls. The difference sounds small and the consequence is not: RFI is immediate code execution, while LFI is a file read that an attacker then works to escalate.

The Pattern

A page that renders sections with include($_GET['page'] . '.php') invites a request for ?page=../../../../etc/passwd%00 or, where the null byte no longer helps, a path that resolves to something useful without the appended extension. The same shape appears in template selectors, language and theme switchers, document viewers, and report generators in every language, not only PHP. Java applications expose it through RequestDispatcher paths and classloader resource lookups, and .NET through file-backed view resolution.

LFI and path traversal share a mechanism and differ in outcome. Traversal reads a file and returns its bytes. Inclusion passes the file to an interpreter, so a readable file can become executed code.

Turning a File Read into Code Execution

Remote Inclusion and Why It Became Rare

RFI depends on the runtime being willing to treat a URL as a file path. In PHP this requires allow_url_include, which has defaulted to off since PHP 5.2 in 2006, so genuinely remote inclusion is now found mainly in old applications and in appliances running unmaintained interpreters. Where it exists, exploitation is trivial: host a file, point the parameter at it, and the server executes whatever it fetches. An SMB path can achieve the same on Windows hosts without any HTTP request leaving the network.

Related Vulnerabilities Worth Knowing

Two recent flaws show the pattern surviving in different forms. CVE-2021-41773 in Apache HTTP Server 2.4.49, published on 5 October 2021, allowed path traversal outside the document root and, where CGI scripts were enabled, remote code execution; the first fix was incomplete and CVE-2021-42013 followed within days. CVE-2024-4577, disclosed on 6 June 2024, allowed argument injection into PHP-CGI on Windows under certain locales, again reaching execution through the way a path and its arguments were parsed.

Prevention

  1. Never build an include path from user input. Map a short identifier to a fixed path through a lookup table, so the request selects a key rather than supplying a path.
  2. If a path must be constructed, canonicalise it and verify the result is inside the intended directory, after decoding and resolving symbolic links rather than before.
  3. Separate code from content. Uploaded and generated files belong outside any directory the interpreter will execute.
  4. Disable the dangerous runtime options: allow_url_include and allow_url_fopen off, and restrict filesystem access with open_basedir or an equivalent.
  5. Keep interpreters and web servers patched, because the examples above were not application bugs at all.
  6. Run the application as an unprivileged account inside a container, so a successful inclusion reads very little of interest.

Testing is a matter of trying traversal sequences, encoded variants, wrapper prefixes, and absolute paths against every parameter that might reach the filesystem, then checking whether the result is read or executed. Our web application security testing covers inclusion paths and the escalation routes above, and SAST rules on include and require calls catch the simplest cases before they ship.

FAQ – Frequently Asked Questions

What Is the Difference Between LFI and Path Traversal?

The mechanism is the same: user input influences a file path. The difference is what the application does with the file. Path traversal reads it and returns the contents, so the impact is disclosure. Local file inclusion passes it to an interpreter, so a file that an attacker can write to, such as a log or an upload, becomes executed code.

Is Remote File Inclusion Still a Realistic Risk?

Rarely in modern PHP, where allow_url_include has defaulted to off since 2006. It persists in legacy applications, embedded appliances running old interpreters, and occasionally in other languages that resolve URLs through a file API. Local inclusion is the far more common finding today, and it reaches the same outcome with more steps.

Does Appending a File Extension Make Inclusion Safe?

No. Concatenating .php to user input narrows the target but does not prevent traversal to another PHP file, including uploaded content, logs renamed by the application, or configuration templates. Historically a null byte truncated the appended extension altogether. Build the path from a fixed lookup table instead of from the request.

How Do We Detect Exploitation Attempts?

Traversal sequences and wrapper prefixes in request parameters are distinctive and worth alerting on, including encoded forms. More telling is the second-order signal: a web process reading files it has never read before, or executing content from a log or temporary directory. File integrity monitoring and process behaviour rules catch the successful cases that request filtering misses.

Related Terms

You May Be Interested In These

What Are Sigma Rules?

Cybersecurity Terms

17 November 2026

What Are Sigma Rules?

Read More
What Is Reflective DLL Injection?

Cybersecurity Terms

17 November 2026

What Is Reflective DLL Injection?

Read More