vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 659 forks source link

Consider system_secret/user_secret acting as sink #5162

Open ohader opened 3 years ago

ohader commented 3 years ago

https://psalm.dev/r/adf4fa4aea

<?php // --taint-analysis

/**
 * @param string $value
 * @param string $pepper
 * @return string
 * @psalm-taint-sink system_secret $value
 */
function signature(string $value, string $pepper = ''): string
{
    $key = 'secret_key_from_dotEnv';
    return hash_hmac('sha512', $value, $key . $pepper);
}

echo signature('static-command'); // expected usage, internal value
echo signature($_GET['command']); // possibility, to generate arbitrary valid signatures

It seems system_secret and user_secret currently can only be used as @psalm-taint-source - assigning @psalm-taint-sink system_secret seems to be ignored.

psalm-github-bot[bot] commented 3 years ago

I found these snippets:

https://psalm.dev/r/adf4fa4aea ```php
ohader commented 3 years ago

Alright... gave it some more thoughts...

Conditional psalm-taint-source <taint-type | conditional>

(yay, more conditionals)

/**
 * @psalm-taint-source ($value is-source input ? 'system_secret' : null)
 */
function signature(string $value, string $pepper = ''): string {}