{
    "title": "File inclusion (LFI / RFI)",
    "seo_title": "File inclusion (LFI, RFI): definition and prevention",
    "h1": "File inclusion (LFI / RFI)",
    "description": "LFI and RFI: how PHP file inclusion works, the role of allow_url_include and wrappers, and how to protect a WordPress site.",
    "lead": "File inclusion is a PHP vulnerability in which an attacker controls the path passed to include or require. With LFI (local file inclusion), they load a file already on the server; with RFI (remote file inclusion), a file hosted elsewhere. It leads to leaked secrets or code execution.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-feint.com/glossary/file-inclusion/",
    "canonical": "https://www.wp-feint.com/glossary/file-inclusion/",
    "markdown": "https://www.wp-feint.com/glossary/file-inclusion/index.md",
    "json": "https://www.wp-feint.com/glossary/file-inclusion/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-11-22T12:07:43+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "File inclusion (LFI / RFI)",
            "url": "https://www.wp-feint.com/glossary/file-inclusion/",
            "markdown": "https://www.wp-feint.com/glossary/file-inclusion/index.md",
            "json": "https://www.wp-feint.com/glossary/file-inclusion/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Inclusion de fichiers (LFI / RFI)",
            "url": "https://www.wp-feint.com/fr/definitions/inclusion-de-fichiers/",
            "markdown": "https://www.wp-feint.com/fr/definitions/inclusion-de-fichiers/index.md",
            "json": "https://www.wp-feint.com/fr/definitions/inclusion-de-fichiers/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Inclusión de archivos (LFI / RFI)",
            "url": "https://www.wp-feint.com/es/glosario/inclusion-de-archivos/",
            "markdown": "https://www.wp-feint.com/es/glosario/inclusion-de-archivos/index.md",
            "json": "https://www.wp-feint.com/es/glosario/inclusion-de-archivos/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Dateieinbindung (LFI / RFI)",
            "url": "https://www.wp-feint.com/de/glossar/dateieinbindung/",
            "markdown": "https://www.wp-feint.com/de/glossar/dateieinbindung/index.md",
            "json": "https://www.wp-feint.com/de/glossar/dateieinbindung/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "File inclusion (LFI e RFI)",
            "url": "https://www.wp-feint.com/it/glossario/file-inclusion/",
            "markdown": "https://www.wp-feint.com/it/glossario/file-inclusion/index.md",
            "json": "https://www.wp-feint.com/it/glossario/file-inclusion/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Inclusão de arquivos (LFI / RFI)",
            "url": "https://www.wp-feint.com/pt/glossario/inclusao-de-arquivos/",
            "markdown": "https://www.wp-feint.com/pt/glossario/inclusao-de-arquivos/index.md",
            "json": "https://www.wp-feint.com/pt/glossario/inclusao-de-arquivos/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Bestandsinclusie (LFI / RFI)",
            "url": "https://www.wp-feint.com/nl/woordenlijst/bestandsinclusie/",
            "markdown": "https://www.wp-feint.com/nl/woordenlijst/bestandsinclusie/index.md",
            "json": "https://www.wp-feint.com/nl/woordenlijst/bestandsinclusie/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "File inclusion (LFI / RFI)"
        },
        {
            "level": 2,
            "text": "How the attack works"
        },
        {
            "level": 2,
            "text": "The role of PHP configuration"
        },
        {
            "level": 2,
            "text": "How to protect against it"
        },
        {
            "level": 2,
            "text": "For WordPress"
        }
    ],
    "body": "In PHP, the `include` and `require` statements (and their `_once` variants) load a file and run the code it contains. They are used everywhere, for example to load a theme template. The danger arises when the file path depends on data sent by the visitor without sufficient validation. MITRE's catalog lists this weakness as CWE-98, with two common names: RFI for remote inclusion, LFI for local inclusion.\n\n## How the attack works\n\nCode like this lets the visitor choose which file gets loaded:\n\n```\n// Don't do this\ninclude( __DIR__ . '/templates/' . $_GET['view'] . '.php' );\n```\n\n- **LFI (Local File Inclusion)**: with `../` sequences, the attacker climbs up the directory tree and gets a file that already exists on the server loaded. At best, they read a file they shouldn't see; if they manage to include a file whose content they control (a log, an uploaded file), they get [remote code execution](https://www.wp-feint.com/glossary/remote-code-execution/).\n- **RFI (Remote File Inclusion)**: the attacker supplies a URL pointing to their own server, and PHP includes their code directly. It is the most direct form, but it requires a setting that is rarely enabled.\n\n![Three-column comparison: LFI (including a file from the server, reading or executing wp-config.php through ../ paths, php://filter and phar:// wrappers, works with the default configuration), RFI (including an http or ftp URL containing the attacker's code, requires allow_url_include to be enabled, a setting off by default and deprecated in PHP 7.4) and defenses (fixed list of allowed files, never a path taken from the request, open_basedir and allow_url_include off, updates)](https://www.wp-feint.com/media/2026/10/lfi-rfi-en.webp)\n\n## The role of PHP configuration\n\nThe PHP documentation is clear about two directives:\n\n- `allow_url_include` allows URLs in `include` and `require`. It defaults to `0`, can only be changed in the system configuration (php.ini) and has been deprecated since PHP 7.4.0. It also requires `allow_url_fopen` to be enabled.\n- `allow_url_fopen` lets PHP open URLs as if they were files; it is enabled by default, because many scripts need it.\n\nDisabling RFI doesn't solve everything: PHP wrappers such as `php://filter` can turn some LFI flaws into code execution on a default configuration, and `phar://` was long used to trigger [insecure deserialization](https://www.wp-feint.com/glossary/insecure-deserialization/). [Our article on the php://filter and phar wrappers](https://www.wp-feint.com/php-file-inclusion-lfi-rfi-wrappers/) covers these techniques in detail.\n\n*Video: “Web Hacker Basics 04 (Local and Remote File Inclusion)” (Netsec Explained)*\n\n## How to protect against it\n\nThe best defense, recommended by MITRE, is to never build a path from received data, but to map fixed values to known files:\n\n```\n$views = array( 'list' => 'list.php', 'grid' => 'grid.php' );\n$view  = isset( $views[ $_GET['view'] ?? '' ] ) ? $views[ $_GET['view'] ] : 'list.php';\ninclude __DIR__ . '/templates/' . $view;\n```\n\n- Keep included files outside the web root when possible.\n- Limit what PHP can read with `open_basedir`: a hijacked include won't be able to leave the allowed directories. Hardening PHP on your hosting explains this setting and its effects.\n- A [web application firewall](https://www.wp-feint.com/glossary/waf/) blocks typical patterns (`../`, `php://`), as an extra layer only.\n\n## For WordPress\n\nWordPress core doesn't build its includes from visitor parameters: the risk comes from plugins and themes that load a template, a language file or a module based on a URL or AJAX parameter. The favorite LFI target is `wp-config.php`, which holds the database credentials and the security keys; a sensitive file forgotten in the web root, such as a `.env` file or a backup, is another easy catch, as [our article on exposed sensitive files](https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/) shows. Finally, check that your host keeps `allow_url_include` disabled.\n\n## Related terms\n\n- [Remote code execution (RCE)](https://www.wp-feint.com/glossary/remote-code-execution/)\n- [Insecure deserialization](https://www.wp-feint.com/glossary/insecure-deserialization/)\n- [WAF (web application firewall)](https://www.wp-feint.com/glossary/waf/)\n- [Backdoor](https://www.wp-feint.com/glossary/backdoor/)\n\n\n## Sources\n\n- [MITRE CWE-98 : PHP Remote File Inclusion](https://cwe.mitre.org/data/definitions/98.html)\n- [PHP Manual : Filesystem and Streams Configuration Options](https://www.php.net/manual/en/filesystem.configuration.php)\n- [PHP Manual : Backward Incompatible Changes in PHP 8.0 (Phar)](https://www.php.net/manual/en/migration80.incompatible.php)",
    "definition": "File inclusion is a PHP vulnerability in which an attacker controls the path passed to include or require. With LFI (local file inclusion), they load a file already on the server; with RFI (remote file inclusion), a file hosted elsewhere. It leads to leaked secrets or code execution.",
    "group": "Web security",
    "aka": [
        "LFI",
        "RFI",
        "local file inclusion",
        "remote file inclusion",
        "path traversal",
        "CWE-98"
    ],
    "related": [
        {
            "title": "Remote code execution (RCE)",
            "url": "https://www.wp-feint.com/glossary/remote-code-execution/",
            "markdown": "https://www.wp-feint.com/glossary/remote-code-execution/index.md"
        },
        {
            "title": "Insecure deserialization",
            "url": "https://www.wp-feint.com/glossary/insecure-deserialization/",
            "markdown": "https://www.wp-feint.com/glossary/insecure-deserialization/index.md"
        },
        {
            "title": "WAF (web application firewall)",
            "url": "https://www.wp-feint.com/glossary/waf/",
            "markdown": "https://www.wp-feint.com/glossary/waf/index.md"
        },
        {
            "title": "Backdoor",
            "url": "https://www.wp-feint.com/glossary/backdoor/",
            "markdown": "https://www.wp-feint.com/glossary/backdoor/index.md"
        }
    ],
    "sources": [
        {
            "title": "MITRE CWE-98 : PHP Remote File Inclusion",
            "url": "https://cwe.mitre.org/data/definitions/98.html"
        },
        {
            "title": "PHP Manual : Filesystem and Streams Configuration Options",
            "url": "https://www.php.net/manual/en/filesystem.configuration.php"
        },
        {
            "title": "PHP Manual : Backward Incompatible Changes in PHP 8.0 (Phar)",
            "url": "https://www.php.net/manual/en/migration80.incompatible.php"
        }
    ],
    "format": "application/json"
}