> 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/dom-xss-document-write-with-location-search.md).

# XSS DOM document.write com location.search

### XSS de DOM no destino document.write usando a fonte location.search

Este laboratório contém uma vulnerabilidade de DOM do lado do XSS no recurso de rastreamento da consulta de pesquisa. A página usa `document.write` para escrever dados de `location.search` no DOM, que pode ser controlado pela URL.

**Descrição da vulnerabilidade**/ `document.write` é chamada com a `location.search` string sem sanitização. Como a entrada vem diretamente da URL, um invasor pode injetar HTML/JS na página manipulando `location.search`.

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

**Objetivo para resolução** Realize um ataque XSS no lado do DOM que chame a `alert()` função quando a página for carregada.

**Comentários/dicas**/ O código gera algo como uma `<img>` tag contendo um `searchTerms` parâmetro entre aspas, por exemplo:

```html
<img src="/resources/images/tracker.gif?searchTerms=Jordan">
```

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

Se você fechar a `<img>` tag e as aspas, você pode inserir conteúdo HTML/JS arbitrário.

**Exemplos de payloads testados (fornecidos)**/ Feche a tag e injete HTML:

```html
"><h1>hack</h1>
```

<figure><img src="/files/044c8f8bbe03c834497f962637f44004b319caf4" alt=""><figcaption></figcaption></figure>

Feche a tag e injete um script para acionar `alert`:

```javascript
"><script>alert("xss")</script>
```

<figure><img src="/files/c6c55d791a0eb8c7e4fff3dd13253bef9144b854" 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/dom-xss-document-write-with-location-search.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.
