phpsafe 𝕏 GitHub
Official CA 421DTkQ3TSG3n7F9SkNZj9NxvdFGbypwkctPd2uupump This is the only official address.

SQL built with variables (SQL injection)

Severity: Critical CWE-89 OWASP A03:2021 Injection rule: sql

Why it matters

Joining input into SQL lets an attacker rewrite the query itself and read, change or delete anything in the database. Prepared statements send the query and the values separately, so input can never become SQL.

βœ• Vulnerable
$id = $_GET['id'];
$rows = $db->query("SELECT * FROM users WHERE id = $id");
βœ“ Secure
$stmt = $db->prepare('SELECT * FROM users WHERE id = ?');
$stmt->execute([$_GET['id']]);
$rows = $stmt->fetchAll();

How to fix

Use prepared statements: $db->prepare('... WHERE id = ?') then execute([$id]).

Scan my code

Paste a file and PHP Safe points to every line that matches this rule.

Scan my code β†’