phpsafe 𝕏 GitHub
Official CA 421DTkQ3TSG3n7F9SkNZj9NxvdFGbypwkctPd2uupump This is the only official address.

Include path built from a variable

Severity: Medium CWE-98 OWASP A03:2021 Injection rule: include_var

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.

βœ• Vulnerable
include $template;
βœ“ Secure
$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

Paste a file and PHP Safe points to every line that matches this rule.

Scan my code β†’