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

Add mysqli.execute-query as sink for TaintedSql #11021

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions stubs/extensions/mysqli.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class mysqli
* @var int<-1, max>|numeric-string
*/
public int|string $affected_rows;

/**
* @psalm-taint-sink sql $query
*/
public function execute_query(string $query, ?array $params = null): mysqli_result|bool {}
}

/**
Expand Down Expand Up @@ -190,6 +195,11 @@ class mysqli_stmt
public string $sqlstate;
}

/**
* @psalm-taint-sink sql $query
*/
function mysqli_execute_query(mysqli $mysql, string $query, ?array $params = null): mysqli_result|bool {}

/**
* @psalm-taint-sink callable $class
*
Expand Down
16 changes: 16 additions & 0 deletions tests/TaintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,22 @@ public static function getPrevious(string $s): string {
$function->invoke();',
'error_message' => 'TaintedCallable',
],
'taintedExecuteQueryFunction' => [
'code' => '<?php
$userId = $_GET["user_id"];
$query = "delete from users where user_id = " . $userId;
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$result = mysqli_execute_query($link, $query);',
'error_message' => 'TaintedSql',
],
'taintedExecuteQueryMethod' => [
'code' => '<?php
$userId = $_GET["user_id"];
$query = "delete from users where user_id = " . $userId;
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$result = $mysqli->execute_query($query);',
'error_message' => 'TaintedSql',
],
];
}

Expand Down
Loading