Interview Prep/DevSecOps/Foundations, Threat Modeling and OWASP

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.

All DevSecOps questions Roadmap: Security in the pipeline

More on Foundations, Threat Modeling and OWASP