Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
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.

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.
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.
php://filter/convert.base64-encode/resource=config returns the source of a PHP file rather than executing it, which exposes database credentials and API keys. The data:// and expect:// wrappers go further where they are enabled./tmp/sess_<id> can be included once the session identifier is known from a cookie./proc/self/environ and framework configuration files are standard targets for credentials and environment variables.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.
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.
allow_url_include and allow_url_fopen off, and restrict filesystem access with open_basedir or an equivalent.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.
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.
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.
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.
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.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.