SQL Injection
Domain: Security
π― Motivation
Building SQL queries with string concatenation lets attackers inject commands that steal or destroy data. Parameterized queries separate code from data, making injection impossible.
π Concrete Example
Never do f"SELECT * FROM users WHERE name = '{name}'". Use cursor.execute("SELECT * FROM users WHERE name = ?", (name,)) so the database treats name purely as a value.
π Analogy
A form letter with blanks is safe β you fill in names without changing the letterβs instructions. If you rewrite the letter for each person, a clever βnameβ could add new sentences.