CAS-001 · Question #90
Which of the following potential vulnerabilities exists in the following code snippet? var myEmail = document.getElementById("formInputEmail").value; if (xmlhttp.readyState==4 &&…
The correct answer is C. DOM-based XSS. This is a textbook example of DOM-based Cross-Site Scripting (XSS). The vulnerability has two parts: (1) the data source is the DOM itself-the value of a form input field is read directly via document.getElementById(), and (2) the sink is innerHTML-the unsanitized value is…
Question
Which of the following potential vulnerabilities exists in the following code snippet? var myEmail = document.getElementById("formInputEmail").value; if (xmlhttp.readyState==4 && xmlhttp.status==200) { Document.getElementById("profileBox").innerHTML = "Emails will be sent to " + myEmail + xmlhttp.responseText; }
Options
- AJavascript buffer overflow
- BAJAX XHR weaknesses
- CDOM-based XSS
- DJSON weaknesses
How the community answered
(31 responses)- A6% (2)
- B23% (7)
- C61% (19)
- D10% (3)
Explanation
This is a textbook example of DOM-based Cross-Site Scripting (XSS). The vulnerability has two parts: (1) the data source is the DOM itself-the value of a form input field is read directly via document.getElementById(), and (2) the sink is innerHTML-the unsanitized value is written directly into the page's HTML. If an attacker can control the value of the email field (e.g., by crafting a malicious URL with a prefilled form), they can inject arbitrary HTML or JavaScript (e.g., <script>maliciousCode()</script>) that the browser will execute. Because the exploit occurs entirely in the client-side DOM without a server round-trip, it is specifically classified as DOM-based XSS rather than reflected or stored XSS. JavaScript does not have traditional buffer overflows, and no AJAX response parsing or JSON deserialization is the root cause here.
Topics
Community Discussion
No community discussion yet for this question.