nerdexam
CompTIA

SY0-501 · Question #414

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…

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, 2026Threats, vulnerabilities, and mitigations

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.

How the community answered

(51 responses)
  • A
    6% (3)
  • B
    2% (1)
  • C
    80% (41)
  • D
    12% (6)

Why each option

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.

AThe attacker is replacing a cookie.

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.

BThe attacker is stealing a document.

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.

CThe attacker is replacing a document.Correct

The JavaScript `document.location.replace()` method is used to navigate to a new URL, effectively replacing the currently loaded document in the browser window and removing the current URL from the browser's session history. This action directly corresponds to 'replacing a document'.

DThe attacker is deleting a cookie.

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

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

Topics

#XSS#JavaScript injection#web attack#HTML manipulation

Community Discussion

No community discussion yet for this question.

Full SY0-501 Practice