SQL injection in order lookup
CWE-89 · PHP & web agent · Exploitability 8.9
Exploit path
The id query parameter is interpolated directly into SQL. An unauthenticated request can read any row in the orders table.
Why the fix works
Validates the parameter as an integer and replaces string interpolation with a prepared statement bound by type.
$id = $_GET['id'];$res = mysqli_query($db, "SELECT * FROM orders WHERE id = $id");$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);$stmt = $db->prepare('SELECT * FROM orders WHERE id = ?');$stmt->bind_param('i', $id);$stmt->execute();$order = $stmt->get_result()->fetch_assoc();- Injection payloads rejected
- Integration tests pass (48)
- No behavior change for valid IDs