What is injection (e.g. SQL injection) in the context of APIs, and how do you defend against it?
Last updated
Injection happens when untrusted input is interpreted as part of a query or command (SQL, NoSQL, shell, LDAP), letting attackers alter logic, read/modify data, or run code (e.g.
' OR '1'='1).Primary defense: parameterized queries (prepared statements with bound parameters) or a vetted ORM, so data is sent separately and never becomes executable code.
Defense in depth: validate input at the API boundary (type, length, allowlist), use least-privilege DB accounts, and avoid building shell commands from input.
- https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
- https://dev.to/davjesse/full-stack-interview-prep-1-sql-injection-explained-simply-with-go-nodejs-examples-lg6
- https://api-security.owasp.org/editions/2019/en/0xa8-injection/
- https://www.oligo.security/academy/owasp-top-10-cheat-sheet-of-cheat-sheets
- https://medium.com/devsecops-ai/protect-restful-apis-from-sql-injection-a-guide-with-examples-624e32aa1e1b
- https://www.baeldung.com/sql-injection
- https://www.esmglobalconsulting.com/blog/defending-your-api-7-best-practices-to-prevent-sql-injection
- https://owasp.org/API-Security/editions/2019/pt-pt/0xa8-injection/