nerdexam
CompTIACompTIA

SY0-501 · Question #414

SY0-501 Question #414: Real Exam Question with Answer & Explanation

The correct answer is C: The attacker is replacing a document.. The attacker is using the JavaScript document.location.replace() method to change the current URL, which causes the browser to replace the currently loaded document with another.

Submitted by daniela_cl· Mar 4, 2026

Question

An attacker exploited a vulnerability on a mail server using the code below. <HTML><body onload=document.location.replace "URL:" +"document.location) ; /> </body> </HTML> Which of the following BEST explains what the attacker is doing?

Options

  • AThe attacker is replacing a cookie.
  • BThe attacker is stealing a document.
  • CThe attacker is replacing a document.
  • DThe attacker is deleting a cookie.

Explanation

The attacker is using the JavaScript document.location.replace() method to change the current URL, which causes the browser to replace the currently loaded document with another.

Common mistakes.

  • A. The code snippet does not interact with document.cookie or any other cookie-specific functions; it targets the location object to change the page URL.
  • B. Stealing a document would typically involve extracting its content (e.g., via document.body.innerHTML) or sensitive data and sending it to an attacker-controlled server, not using document.location.replace() for redirection.
  • D. Deleting a cookie involves manipulating the document.cookie property with an expired date or an empty string, actions not present in the provided code.

Concept tested. Cross-Site Scripting (XSS) document redirection

Reference. https://learn.microsoft.com/en-us/javascript/api/dom/html-dhtml/location

Community Discussion

No community discussion yet for this question.

Full SY0-501 PracticeBrowse All SY0-501 Questions