How do you prevent SQL injection?
BeginnerConceptFoundations, Threat Modeling and OWASP
Answer
Use parameterised queries or an ORM that binds parameters, so user input is always data, never part of the SQL grammar.
cur.execute("SELECT * FROM users WHERE email = %s", (email,)) # safe
cur.execute(f"SELECT * FROM users WHERE email = '{email}'") # vulnerable
Add input validation with allow-lists, least-privilege database accounts (no DROP, no superuser), and SAST rules (Semgrep, CodeQL) to catch string-built queries in review.
More on Foundations, Threat Modeling and OWASP
What is DevSecOps, and how is it different from DevOps?BeginnerWhat does "shift-left" mean?BeginnerIf we shift left, why do we still need "shift-right" controls?IntermediateWhat are the phases of a secure SDLC and a security activity for each?BeginnerExplain the CIA triad with a DevOps example for each property.BeginnerWhat is threat modeling and when should you do it?Beginner