Attacks and Exploits

A tester reports stored cross-site scripting in the comment field of a client's web app. Which four recommendations would reduce the risk? (Choose four.)

Choose 4 answers

Show the answer

Correct answersA. Encode output for the HTML context where it is renderedB. Set the HttpOnly flag on session cookiesC. Deploy a restrictive Content Security PolicyF. Validate input against an allowlist of expected characters

AWhy this is right: Context-aware output encoding makes injected markup display as text instead of executing.

BWhy this is right: HttpOnly stops injected script from reading the session cookie, limiting the damage.

CWhy this is right: A restrictive CSP blocks inline and untrusted scripts from executing in the browser.

DWhy not this: Anti-CSRF tokens counter forged requests, and injected script on the same site can often read them.

EWhy not this: Parameterized queries prevent SQL injection and do nothing about script rendered in the browser.

FWhy this is right: Allowlist validation rejects unexpected characters before they are stored.

Output encoding, allowlist input validation and a restrictive CSP stop or limit injected script, and HttpOnly keeps scripts from reading session cookies. Parameterized queries address SQL injection, and anti-CSRF tokens address forged requests; neither stops script from running in the browser.