Include path built from a variable
Why it matters
A variable include path is only safe if the variable can never hold user input. It is worth confirming, because the value often comes from a request further up the code.
include $template;
$allowed = ['list', 'detail'];
if (!in_array($template, $allowed, true)) {
$template = 'list';
}
include __DIR__ . '/templates/' . $template . '.php';
How to fix
Make sure the variable can only hold known file names. Prefer __DIR__ with a fixed path.
Scan my code
Scan my code β
Paste a file and PHP Safe points to every line that matches this rule.