The presented mitigation is absolutely insufficient. It’s not just possible to include any file from the current directory but also from any directory depending on the file system (i. e., \..
still works on Windows) or by using an absolute path (e. g., /…
on Unix-like systems, or \…
on Windows) as well via different protocols/wrappers (e. g., http://…
, file://…
, ftp://…
, etc.), allowing the execution of arbitrary PHP code.
If you don’t want this, you should validate the parameter value. For example, if you only want to allow certain values, use an array and check whether the given value is in it:
$validValues = array();
if (!in_array($page, $validValues, true)) {
die("invalid 'page' value");
}
If you want to allow any file within a certain directory, you could check whether the resulting absolute path is still pointing to a file within that directory using the technique described in Preventing Directory Traversal in PHP but allowing paths.