> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/web/xss/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.md).

# XSS reflejado en una cadena JavaScript con signos de menor y mayor codificados en HTML

Notas de XSS reflejado en una cadena JavaScript con signos de menor y mayor codificados en HTML para laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payloads, validación con Burp Suite y contexto de remediación.

### XSS reflejado en una cadena de JavaScript con los signos de ángulo codificados en HTML

Este laboratorio contiene una vulnerabilidad de tipo XSS reflejada en el mecanismo de seguimiento de la consulta de búsqueda: los signos de ángulo (`<` y `>`) están codificados en HTML, pero el valor reflejado se inserta dentro de una \*\*cadena de JavaScript\*\*. El objetivo es salir de esta cadena de JS y llamar `alert()`.

**Extracto relevante del código observado**

{% code overflow="wrap" %}

```javascript
var searchTerms = 'hello';
   document.write('<img src="/resources/images/tracker.gif?searchTerms='+encodeURIComponent(searchTerms)+'">');
```

{% endcode %}

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d63c624dccd988c20d69f5c1a1c22cd950ab46ff%2F%7BF4D7F7B2-0557-41E0-A2B0-85CCD872B93F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

El valor de búsqueda (`searchTerms`) se concatena en una `document.write` instrucción dentro de una cadena HTML construida con JavaScript. Al inyectar un apóstrofo (`'`) en el valor, puedes cerrar la cadena actual de JavaScript y ejecutar código arbitrario.

```javascript
hello'
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a1d42efd972c9f1970689ef4445a2d0836d8d6de%2F%7B4C4E6FD2-56BF-4B1F-A489-67C396363992%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Al enviar la siguiente cadena como valor de búsqueda, cierras la cadena, ejecutas `alert(0)` y luego cierras:

```javascript
hello' ; alert(0);'
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8029beebb7a4c9902dd1bfee11320e7bf6e2a932%2F%7B0F4D322D-7C96-4F38-AC0A-BDA64E513A17%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/es/web/xss/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
