An SQL query is built from request input

tx0/php:sql-from-requestdefaulterrorsecurity/injectiondepth fastsecurity, cwe-89

What it finds

mysqli_query($db, "SELECT * FROM users WHERE id = $_GET[id]"): an SQL query built from what the request sent lets the sender change the query. The query functions of the mysqli, mysql, pg and sqlite extensions, the query, exec and prepare methods of PDO and similar objects, WordPress's $wpdb methods and the raw-query methods of Laravel's query builder are checked; values belong in bound parameters. Input that a condition checked on the way, as a table prefix matched against a pattern with preg_match before the query, and numbers put in with %d of sprintf, do not count.

From the rule's source, sql_from_request.rs.

Example from the rule's tests
<?phpfunction find($db, $pdo, $wpdb){    $a = mysqli_query($db, "SELECT * FROM users WHERE id = $_GET[id]");tx0 reports: request input from $_GET reaches the SQL query    $name = $_POST['name'];    $sql = 'SELECT * FROM users WHERE name = \'' . $name . '\'';    $b = $pdo->query($sql);tx0 reports: request input from $_POST reaches the SQL query    $c = $wpdb->get_results($wpdb->prepare('SELECT * FROM t WHERE id = %d', $_GET['id']));    $id = (int) $_GET['id'];    $d = $pdo->query("SELECT * FROM t WHERE id = $id");    $e = $pdo->query('SELECT 1');    return [$a, $b, $c, $d, $e];} function framework($request, $db){    return $db->whereRaw('name = ' . $request->input('name'));tx0 reports: request input from $request->input('name') reaches the SQL query}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/php:sql-from-request" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/php:sql-from-request] reason="..."

tx0 explain tx0/php:sql-from-request shows the same in the terminal. Found a false positive? Report it.