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 | |
|---|---|---|
| 1if len(username) > 20: | AChecks that the input contains only digits, so it is the expected type | |
| 2age.isdigit() | BThe server does no validation and trusts the browser check, which an attacker can bypass | |
| 3Reject unexpected characters by allowing only letters and numbers | Cif not name.isalnum(): reject() | |
| 4Validate on the server as well as in the browser, because browser checks can be bypassed | DChecks the length of the input and rejects it if it is too long | |
| 5query = "SELECT * FROM users WHERE name='" + name + "'" | EThe input is used straight away without being validated, so a user could type harmful characters that change the query | |
| 6// Browser only: if (age < 0) stop(); // Server: save(age) | Fdef save(form): if not valid(form): return error() |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
input validation — Checking that data a user enters is the expected type, length and format before the program uses it, so bad or harmful input is rejected.<input type="text" maxlength="20">if not age.isdigit():
print("Numbers only")if "<" in comment:
print("Not allowed")if len(name) > 20:
print("Too long")# Server: check again
if not name.isalpha():
return "Rejected"