Back to Psalm

Avoiding false-negatives

docs/security_analysis/avoiding_false_negatives.md

6.16.1510 B
Original Source

Avoiding false-negatives

Unescaping statements

Post-processing previously escaped/encoded statements can cause insecure scenarios. @psalm-taint-unescape <taint-type> allows to declare those components insecure explicitly.

php
<?php

/**
 * @psalm-taint-unescape html
 */
function decode(string $str): string
{
    return str_replace(
        ['&lt;', '&gt;', '&quot;', '&apos;'],
        ['<', '>', '"', '"'],
        $str
    );
}

$safe = htmlspecialchars($_GET['text']);
echo decode($safe);