Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric type hints and casts not considered in taint analysis #6991

Closed
ohader opened this issue Nov 25, 2021 · 2 comments · Fixed by #6993
Closed

Numeric type hints and casts not considered in taint analysis #6991

ohader opened this issue Nov 25, 2021 · 2 comments · Fixed by #6993

Comments

@ohader
Copy link
Contributor

ohader commented Nov 25, 2021

https://psalm.dev/r/8fa14c18fc

Related aspects:

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8fa14c18fc
<?php // --taint-analysis
function main()
{
    $value = $_GET['value'];
    // using `(int)$_GET['value']` works, avoids "tainted SQL"
    $result = fetch($value);
}
// `int` type not considered, still "tainted SQL"
function fetch(int $id): string
{
    // `(int)` cast not considered, still "tainted SQL"
    return query('SELECT ... FROM ... WHERE id=' . (int)$id);
}
/**
 * @return string
 * @psalm-taint-sink sql $sql
 * @psalm-taint-specialize
 */
function query(string $sql) {}
Psalm output (using commit 55b2b6b):

ERROR: TaintedSql - 19:23 - Detected tainted SQL

@ohader
Copy link
Contributor Author

ohader commented Nov 25, 2021

I've just added some tests to reproduce this behavior in #6992:

  • function fetch(int $id): string { return query("SELECT * FROM table WHERE id=" . $id); } fails
  • function fetch($id): string { return query("SELECT * FROM table WHERE id=" . (int)$id); } works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants