Why it matters
A quote in the value changes which nodes the expression selects.
How to fix it
Validate the value against a strict pattern (for example digits only) before it is placed in the expression, or walk the DOM instead of building a query string.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
<?php
$doc = new DOMDocument();
$doc->load('catalog.xml');
$xp = new DOMXPath($doc);
$items = $xp->query("//item[@sku='" . $_GET['sku'] . "']");<?php
$doc = new DOMDocument();
$doc->load('catalog.xml');
$xp = new DOMXPath($doc);
$items = $xp->query("//item[@id=" . intval($_GET['id']) . "]");What TrustIvan reads
Runs on repository scans of PHP source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- LDAP injection from request input (PHP)
PHPSeverity: High
trustivan-php-taint-ldap-injection - Code injection from request input (PHP)
PHPSeverity: High
trustivan-php-taint-code-injection - Open redirect from request input (PHP)
PHPSeverity: Medium
trustivan-php-taint-open-redirect - Regex injection from request input (PHP)
PHPSeverity: Medium
trustivan-php-taint-regex-injection - Deserialization from request input (PHP)
PHPSeverity: High
trustivan-php-taint-deserialization - Template injection from request input (PHP)
PHPSeverity: High
trustivan-php-taint-template-injection
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation