Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1' OR '1'='1 | AThe user input is joined straight into the SQL string, so an attacker could type extra commands like 1 OR 1=1 and delete every note. Use a parameterised query instead. | |
| 2cursor.execute("SELECT * FROM users WHERE name = ?", (name,)) | Bcursor.execute("SELECT * FROM users WHERE id = ?", (user_id,)) | |
| 3Code injection happens when a program joins user input straight into a query string, so typed text becomes part of the command | Cquery = "SELECT * FROM users WHERE name = '" + name + "'" | |
| 4A parameterised query stops SQL injection by sending the command and the input separately | DEven though execute is used, the name is still joined into the query text, so it is not parameterised and injected SQL can still run. | |
| 5query = "DELETE FROM notes WHERE id = " + user_input | EInjected text that makes a login check always true, so the attacker gets in without a password | |
| 6cursor.execute("SELECT * FROM users WHERE name = '" + name + "'") | FA parameterised query that treats the input only as data, so injected SQL cannot run |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
SQL injection — An attack where SQL commands typed into an input box run because the program joins the input straight into a query. Parameterised queries stop it by treating input only as data.q = "SELECT * FROM users WHERE id=" + uidname = "x' OR '1'='1"sql = "SELECT * FROM users WHERE id=?"
cur.execute(sql, (uid,))sql = "SELECT * FROM users WHERE id=?"
cur.execute(sql, (uid,))sql = "SELECT * FROM users WHERE id=?"
cur.execute(sql, (uid,))