SQL Injection
Improper Neutralization of Special Elements used in an SQL Command (SQL Injection)
CWE-89 · Critical severity · Updated November 6, 2026
What it is
CWE-89 occurs when an application constructs SQL queries by concatenating user input rather than using parameterized queries or prepared statements. An attacker who controls part of the query can modify its meaning: read arbitrary data, modify data, run administrative commands, or in the worst case execute arbitrary code via DBMS-specific features.
Why it matters
SQL injection has been in the CWE Top 25 every year it has been published. Despite three decades of disclosure, parameterized-query adoption is still incomplete, especially in legacy code, dynamically-built filter expressions, and ORM escape hatches. A single SQL injection in a customer database is sufficient for mass credential exfiltration, ransomware staging, or breach disclosure under HIPAA, PCI-DSS, GDPR, and SOX.
Common patterns
- String concatenation: 'SELECT * FROM users WHERE id = ' + req.params.id
- f-string or template-string queries in Python or Node that interpolate user input.
- Dynamic WHERE-clause construction for filter UIs without proper parameter binding.
- ORM .raw() / .query() / .execute() calls that bypass the ORM's own parameterization.
- Stored procedures that use EXEC or sp_executesql on dynamically-built strings.
Languages affected
Python, JavaScript, TypeScript, Java, Go, Ruby, PHP, C#
What Deva detects
Deva tracks data flow from request inputs through query builder calls to database driver execution. The scanner has language-specific rules for Sequelize, Knex, TypeORM, pg, mysql2, SQLAlchemy text(), Django raw(), Active Record connection.execute(), and JDBC PreparedStatement misuse. Findings show the call site and generic parameterization guidance. On Pro, an AI fix can propose a rewrite.
Example
Vulnerable
def get_user(user_id):
query = f"SELECT * FROM users WHERE id = {user_id}"
with db.cursor() as cur:
cur.execute(query)
return cur.fetchone()Fixed
def get_user(user_id):
query = "SELECT * FROM users WHERE id = %s"
with db.cursor() as cur:
cur.execute(query, (user_id,))
return cur.fetchone()The vulnerable version uses an f-string that interpolates user_id directly into the SQL. An attacker passing 1 OR 1=1 -- gets back a row they should not see, and a UNION payload can pull data from other columns and tables. The fix passes user_id as a parameter with the database driver's placeholder syntax (varies by driver: %s for psycopg2, ? for sqlite3, $1 for asyncpg), so the value cannot change the structure of the query.
Where this fits in OWASP Top 10
- A05 InjectionUntrusted input interpreted as code or commands by a downstream interpreter.
Compliance framework references
These references explain how the weakness relates to control topics. They do not mean Deva offers evaluation for every framework listed. CMMC evaluation and SPRS scoring are currently unavailable. See the FAQ for offered frameworks and preview status. Deva provides code-level evidence for your assessment, without certifying compliance.
| Framework | Controls |
|---|---|
| OWASP Top 10:2025 | A05:2025 Injection |
| NIST 800-53 Rev 5 | SI-10 Information Input Validation |
| PCI-DSS v4.0.1 | 6.2.4 Software engineering techniques |
| HIPAA Security Rule | 164.312(a)(1) Access Control, 164.312(c)(1) Integrity |
| CMMC L2 | SI.L2-3.14.1 Flaw remediation |