Information Security Basics
A bulletin-board web application had a vulnerability in which scripts contained in text posted by users were executed in other visitors' browsers. Which combination correctly gives the name of this vulnerability and its fundamental countermeasure?
- ASQL injection. Lengthen the password used to connect to the database
- BCross-site scripting (XSS). Escape characters with special meaning, such as < and >, when outputting posted text as HTML
- CCross-site scripting (XSS). Encrypt communication between the server and the browser with HTTPS
Show answer and explanation
Answer: B. Cross-site scripting (XSS). Escape characters with special meaning, such as < and >, when outputting posted text as HTML
Cross-site scripting (XSS) is a vulnerability in which a web application outputs user input into HTML as is, so a script contained in the input runs in visitors' browsers as part of the page. Because the script runs as a page of that site, it may steal the visitor's session information (cookies) or display fake input fields. The fundamental countermeasure is to escape characters with special meaning, such as <, >, & and quotation marks, according to where they are output (for example, converting < to <) so they are displayed as plain characters. Supplementary measures include giving cookies the HttpOnly attribute so scripts cannot read them, and restricting which scripts may run with a Content Security Policy. HTTPS protects the communication channel and cannot prevent a script embedded in a legitimate page from running.
- A. Scripts running in the browser is not SQL injection, and lengthening the connection password is irrelevant.
- B. Correct. The cause is outputting input as is, so escaping on output is the fundamental countermeasure.
- C. The name is correct, but HTTPS protects the communication channel and cannot stop a script embedded in a legitimate page from running.