> 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/pt-br/web/xss/xss-in-a-javascript-string-with-apostrophe-and-backslash-escaped.md).

# XSS em uma String JavaScript com Apóstrofo e Barra Invertida Escapados

### XSS refletido em uma string JavaScript com aspas simples e barra invertida escapadas

XSS refletido no recurso de rastreamento de termos de pesquisa. O valor refletido é inserido em uma string JavaScript; apóstrofos simples e barras invertidas foram escapados, dificultando escapar.

Objetivo

* Saia da string JavaScript escapada e chame `alert()`.

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

Observações atuais

* Se `teste` é enviado, o valor é armazenado no `searchTerm` variável do script.
* Tentar introduzir uma nova variável:/ `testing'; var=test='thisIsATest`/ → Observa-se que aspas e barras invertidas () são injetadas/presentes e impedem a injeção direta.

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

* Basta inserir a tag de fechamento do script para encerrar o contexto do script: `</script>`

```javascript
</script>
```

<figure><img src="/files/8cd96b090c9572f45c0c5b481632575638bf6005" alt=""><figcaption></figcaption></figure>

* Após o fechamento, texto HTML simples pode ser renderizado: `</script><h1>HACK</h1>`

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

<figure><img src="/files/99c3ad8875dacb7e5249bf7ad84d6d6a787dc6a5" alt=""><figcaption></figcaption></figure>

* E, por fim, é possível executar um `alert` ao adicionar um novo `<script>` após o fechamento: `</script><script>alert(0)</script>`

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

<figure><img src="/files/4ba3a150cd253a27d445041b4347fa1290748970" 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/pt-br/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.
