← PHP / Laravel · Contents

PHP-096 / Intermediate

XPath injection

A03:2021 Injection · CWE-643 XPath Injection

Why is this a problem?

Conditions are altered to retrieve arbitrary user nodes.

How to fix it

php
$nodes = $xp->query('//user[name=$n]', null, ['n' => $name]);   // Use an API supporting variable binding or an input allowlist

Further reading