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 | AText typed into a login form that makes the query's check always true, so the attacker gets in without a password | |
| 2'; DROP TABLE users; -- | Bcursor.execute("SELECT * FROM users WHERE name=?", (name,)) | |
| 3Joining user input straight into a query string lets typed text become part of the SQL command | CInjected input that ends the query and adds a command to delete a table, so data is destroyed | |
| 4A parameterised query keeps input as data only, so it cannot run as a command | DThe password typed by the user is joined straight into the query, so an attacker can type SQL commands that run. Use a parameterised query instead. | |
| 5sql = "SELECT * FROM users WHERE pass='" + password + "'" | Equery = "SELECT * FROM users WHERE name='" + name + "'" | |
| 6db.run("DELETE FROM posts WHERE id=" + id) | FThe id from the user is added directly to the query, so someone could type extra commands and delete data. Use a placeholder such as id=? and pass the value separately. |
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 database commands are typed into an input field and run because the program joins the input straight into a query. Parameterised queries stop it.Password typed: ' OR '1'='1sql = "SELECT * FROM users WHERE n = ?"
cur.execute(sql, (name,))name = input("Username: ")
sql = "SELECT * FROM users WHERE n='"
sql = sql + name + "'"Input: '; DROP TABLE users; --username = input("Username: ")
sql = "SELECT * FROM users WHERE n = ?"
cur.execute(sql, (username,))