QuickDevGuide

Home › OWASP Top 10

Injection: SQL & OS Commands — OWASP Top 10

Injection happens when untrusted data is concatenated into a command that an interpreter executes: SQL, NoSQL, OS shell, LDAP, XPath, template engines. SQL injection "SELECT FROM users WHERE name = '" + name + "'" with name = "' OR '1'='1" returns every user. The fix is parameterised queries — the driver sends data separately from the SQL text, so it can never change the query's structure. Language Safe form Python DB-API cur.execute("... WHERE id = ?", (id,)) Java JDBC PreparedStatement with setString C# ADO.NET SqlCommand + Parameters.AddWithValue Node (pg) client.query("...

QuickDevGuide
", [id]) Identifiers (column/table names, ORDER BY) cannot be parameters — map them through an allow-list. OS command injection Never pass user input through a shell. Call the program with an argument list…

Key Takeaways