{
    "title": "PHP file inclusion: LFI, RFI and the phar and php://filter wrappers",
    "seo_title": "PHP file inclusion: LFI, phar, php://filter",
    "h1": "PHP file inclusion: LFI, RFI and the phar and php://filter wrappers",
    "description": "LFI, RFI and the phar:// and php://filter wrappers: how a file inclusion turns into code execution, and how to protect yourself.",
    "lead": "How a simple PHP file inclusion turns into code execution through php://filter or phar://, and the settings that close the door.",
    "language": "en",
    "locale": "en-US",
    "type": "article",
    "url": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/",
    "canonical": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/",
    "markdown": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/index.md",
    "json": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/index.json",
    "published": "2026-10-31T08:00:00+00:00",
    "modified": "2026-11-22T14:34:36+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "PHP file inclusion: LFI, RFI and the phar and php://filter wrappers",
            "url": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/",
            "markdown": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/index.md",
            "json": "https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Inclusion de fichiers en PHP : LFI, RFI et wrappers phar et php://filter",
            "url": "https://www.wp-feint.com/fr/inclusion-fichiers-php-wrappers/",
            "markdown": "https://www.wp-feint.com/fr/inclusion-fichiers-php-wrappers/index.md",
            "json": "https://www.wp-feint.com/fr/inclusion-fichiers-php-wrappers/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Inclusión de archivos en PHP: LFI, RFI y los wrappers phar y php://filter",
            "url": "https://www.wp-feint.com/es/inclusion-archivos-php-wrappers/",
            "markdown": "https://www.wp-feint.com/es/inclusion-archivos-php-wrappers/index.md",
            "json": "https://www.wp-feint.com/es/inclusion-archivos-php-wrappers/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Dateieinbindung in PHP: LFI, RFI und die Wrapper phar und php://filter",
            "url": "https://www.wp-feint.com/de/php-dateieinbindung-lfi-rfi-wrapper/",
            "markdown": "https://www.wp-feint.com/de/php-dateieinbindung-lfi-rfi-wrapper/index.md",
            "json": "https://www.wp-feint.com/de/php-dateieinbindung-lfi-rfi-wrapper/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "Inclusione di file in PHP: LFI, RFI e i wrapper phar e php://filter",
            "url": "https://www.wp-feint.com/it/inclusione-file-php-wrapper/",
            "markdown": "https://www.wp-feint.com/it/inclusione-file-php-wrapper/index.md",
            "json": "https://www.wp-feint.com/it/inclusione-file-php-wrapper/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Inclusão de arquivos em PHP: LFI, RFI e os wrappers phar e php://filter",
            "url": "https://www.wp-feint.com/pt/inclusao-arquivos-php-wrappers/",
            "markdown": "https://www.wp-feint.com/pt/inclusao-arquivos-php-wrappers/index.md",
            "json": "https://www.wp-feint.com/pt/inclusao-arquivos-php-wrappers/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Bestandsinclusie in PHP: LFI, RFI en de wrappers phar en php://filter",
            "url": "https://www.wp-feint.com/nl/bestandsinclusie-php-wrappers/",
            "markdown": "https://www.wp-feint.com/nl/bestandsinclusie-php-wrappers/index.md",
            "json": "https://www.wp-feint.com/nl/bestandsinclusie-php-wrappers/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "PHP file inclusion: LFI, RFI and the phar and php://filter wrappers"
        },
        {
            "level": 2,
            "text": "LFI and RFI: two close relatives"
        },
        {
            "level": 2,
            "text": "PHP wrappers, or how a read becomes an execution"
        },
        {
            "level": 2,
            "text": "Why WordPress is affected"
        },
        {
            "level": 2,
            "text": "How to protect yourself"
        },
        {
            "level": 2,
            "text": "What a masking tool does not do"
        },
        {
            "level": 2,
            "text": "Spotting an attempt in your logs"
        },
        {
            "level": 2,
            "text": "A family of flaws that will not go away"
        },
        {
            "level": 3,
            "text": "Key takeaways"
        },
        {
            "level": 2,
            "text": "Sources"
        }
    ],
    "body": "File inclusion is one of the oldest families of PHP vulnerabilities, yet it is still very much alive, driven by modern techniques that turn a simple file read into code execution. This article explains what LFI and RFI are, how the `php://filter` and `phar://` wrappers come into play, and above all how to protect yourself on WordPress hosting.\n\n## LFI and RFI: two close relatives\n\nThe problem starts with an inclusion function (`include`, `require` and their variants) whose path depends on user-supplied data, with no validation. Code such as `include($_GET['page'] . '.php');` opens the door, depending on what the attacker slips into the parameter.\n\n- **LFI (Local File Inclusion)**: the attacker gets the application to include a file that already exists on the server. At best, they read files they should not see; at worst, they manage to get code executed.\n- **RFI (Remote File Inclusion)**: the attacker gets the application to include a remote file hosted on their own server. This is the most direct form, because the file then contains their code.\n\nGood news about RFI: it depends on a configuration option that is disabled by default. The `allow_url_include` directive is set to `0` on a standard installation, and it has even been deprecated since PHP 7.4. Without it, including a remote URL fails. That is why attention has shifted to techniques that work even with the default configuration.\n\n## PHP wrappers, or how a read becomes an execution\n\nPHP exposes special streams, called wrappers, that can be used anywhere a file name is expected. Some are harmless, others can be abused. Two deserve particular attention.\n\n![Four-step sequence: unfiltered user input passed to include, php://filter wrapper chaining conversions, PHP code built in memory, then execution on the server.](https://www.wp-feint.com/media/lfi-rce-en.webp)\n\nThe `php://filter` wrapper applies transformations to a stream. By chaining character set conversions, an attacker can build a valid piece of PHP code, character by character, directly in memory, without ever needing a writable file or an upload. Key point: this technique does not depend on `allow_url_include` and works on a default configuration. That is what has made it so dangerous in recent years.\n\nThe `phar://` wrapper raises a different problem. When a file operation receives a path starting with `phar://`, PHP reads the archive's metadata and, under certain conditions, deserializes it. If the application code contains an exploitable \"gadget chain\" (the same mechanism as [object injection](https://www.wp-feint.com/glossary/insecure-deserialization/)), this deserialization can trigger code. The attacker must first drop a booby-trapped archive, then get the application to open it through this wrapper.\n\n| Wrapper | Abuse | Condition |\n| --- | --- | --- |\n| php://filter | Building code through conversions | Works by default, no special option needed |\n| phar:// | Triggering object deserialization | Accessible booby-trapped archive + gadget present |\n| data:// | Supplying content to include directly | Requires allow_url_include to be enabled |\n| http:// and ftp:// | Remote inclusion (RFI) | Requires allow_url_include to be enabled |\n\n*The wrappers most often involved and what it takes to exploit them.*\n\n## Why WordPress is affected\n\nWordPress core does not include files from user input in this way. The risk almost always comes from a poorly written plugin or theme that builds an inclusion path from a URL parameter, a form field or a header. That is why inclusion flaws keep showing up in plugin vulnerability reports, year after year.\n\nIt is also worth keeping things in perspective: not every inclusion flaw leads to code execution. Many are limited to reading files, which is still serious when those files contain secrets (for example `wp-config.php`), but does not directly hand over control of the server. Severity depends on context and configuration.\n\n## How to protect yourself\n\nDefense happens at two levels: the code and the server configuration.\n\n- **Never include user input.** This is the real fix. A developer should use an allowlist of permitted files rather than concatenating a parameter into a path. For a site owner, this translates into: choose quality plugins and keep them up to date.\n- **Keep allow_url_include and allow_url_fopen disabled** if your plugins do not need them, to shut down RFI and the `data://` wrapper.\n- **Restrict PHP with open_basedir**, which limits accessible files to a given directory tree, and with `disable_functions` for dangerous functions you do not use.\n- **Block PHP execution in upload folders**, to cut off the route by which an attacker drops an archive or a script.\n- **Monitor your plugins' vulnerabilities** and apply fixes quickly, because an inclusion flaw is often exploited at scale as soon as it is published.\n\n## What a masking tool does not do\n\nLet's be precise about the limits. WP Feint changes public signatures and offers access restrictions, but it does not fix vulnerabilities in code. Its guide says so explicitly: rewriting file addresses is not protection against the exploitation of a vulnerable plugin, and the highest level does not block all of a plugin's PHP files. Hiding a path can make automated recognition of a target harder, but an inclusion flaw in an installed plugin remains exploitable once the request has been crafted.\n\nThe right approach is therefore defense in depth. [Hardening](https://www.wp-feint.com/features/hardening/) and access restrictions reduce the attack surface and the noise; keeping plugins up to date and properly configured PHP hosting address the root cause. None of these replaces the others. To go further on server configuration, our article on PHP hardening covers `disable_functions`, `open_basedir` and the other useful settings.\n\n## Spotting an attempt in your logs\n\nInclusion attempts often leave recognizable traces in access logs. URL parameters containing `php://filter`, `phar://`, sequences of `../` or references to `wp-config.php` are signals to take seriously. They do not prove a compromise, and most of them fail, but they show that your site is being probed for this type of flaw.\n\nA useful habit is to watch for requests to plugin entry points followed by these patterns, especially right after a vulnerability has been published. The response is the same as for other families of flaws: check that the plugin in question is up to date, and deactivate it if no fix exists. On the server side, logging and blocking these patterns with a [web application firewall](https://www.wp-feint.com/glossary/waf/) reduces the noise, without replacing a fix in the code.\n\n## A family of flaws that will not go away\n\nWhy do these flaws persist when the principle has been known for years? Because they stem from a simple and tempting mistake: using user data directly to build a path. Every new plugin, every feature that dynamically loads a template or a page, can reintroduce the defect. And exploitation techniques keep advancing: the `php://filter` conversion chain in particular has revived interest in flaws once considered harmless, by turning them into code execution with no file to drop.\n\nFor a site owner, the practical takeaway is reassuring: you do not need to master these techniques to protect yourself. Choosing quality plugins, keeping them up to date, hardening the PHP configuration and monitoring your logs cover most of the risk. The rest is up to plugin developers, who must stop including unchecked input.\n\n### Key takeaways\n\n- RFI requires allow_url_include, which is disabled by default and deprecated since PHP 7.4.\n- The php://filter wrapper can build code without a writable file, even with a default configuration.\n- phar:// can trigger object deserialization if a gadget exists in the code.\n- The real fix is to never include user input; masking does not fix a flaw in the code.\n\n## Sources\n\n- [PHP, Runtime configuration (allow_url_fopen, allow_url_include)](https://www.php.net/manual/en/filesystem.configuration.php)\n- [PHP, php:// wrappers](https://www.php.net/manual/en/wrappers.php.php)\n- [OWASP, Path Traversal](https://owasp.org/www-community/attacks/Path_Traversal)\n- [OWASP, PHP Object Injection](https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection)",
    "categories": [
        "PHP vulnerabilities"
    ],
    "format": "application/json"
}