Whenever the site is loaded, your web browser will try to load an image from the URL /missing_image
. Because your application responds with an HTTP error, the JavaScript code in the onerror
handler is invoked.
Note that there is no user interaction required to invoke the error handler.
Granted, this code merely annoys the user by showing alert boxes over and over again but the error handler may contain any malicious JavaScript code. An attacker may, for example, load an external script and collect cookies from logged-in users to impersonate them. Depending on the functionality of your website, the consequences of this may be very serious.
And because this XSS attack is stored on the server, once this change is published, it affects your editors and website visitors alike.