Remediation Steps
Follow the steps below to remediate this finding on Generic / Developer guidance.
SQL injection occurs when untrusted input is concatenated into SQL queries without proper parameterisation.
Remediation:
- Always use parameterised queries / prepared statements:
PDO (PHP):
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id'); $stmt->execute([':id' => $userId]); mysqli: $stmt = $mysqli->prepare('SELECT * FROM users WHERE id = ?'); $stmt->bind_param('i', $userId); $stmt->execute(); • Use an ORM (Eloquent, Doctrine, SQLAlchemy) that handles parameterisation by default. • Validate input types before use (e.g., cast to int for numeric IDs). • Apply the principle of least privilege — database users should only have the permissions they need.