> 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/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.md).

# XSS réfléchi dans une chaîne JavaScript avec chevrons encodés en HTML

### XSS réfléchi dans une chaîne JavaScript avec les chevrons encodés en HTML

Ce laboratoire contient une vulnérabilité de type XSS répercutée dans le mécanisme de suivi de la requête de recherche : les chevrons (`<` et `>`) sont encodés en HTML, mais la valeur répercutée est insérée dans une \*\*chaîne JavaScript\*\*. L'objectif est de sortir de cette chaîne JS et d'appeler `alert()`.

**Extrait pertinent du code observé**

{% code overflow="wrap" %}

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

{% endcode %}

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

La valeur de recherche (`searchTerms`) est concaténée dans une `document.write` instruction dans une chaîne HTML construite en JavaScript. En injectant une apostrophe (`'`) dans la valeur, vous pouvez fermer la chaîne JavaScript en cours et exécuter du code arbitraire.

```javascript
hello'
```

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

En envoyant la chaîne suivante comme valeur de recherche, vous fermez la chaîne, exécutez `alert(0)` puis fermez :

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

<figure><img src="/files/848689361b7fdaad7c63db69c184025181eaf6d7" 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/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.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.
