> 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/web/oauth-authentication/forced-oauth-profile-linking.md).

# Forced OAuth Profile Linking

Forced OAuth Profile Linking notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### JForced OAuth Profile Linking

**Description of lab**

This lab offers a functionality to link a social network profile to a user account to connect via OAuth instead of using traditional authentication. / Due to an unsecured implementation of the client-side OAuth stream, an attacker can divert this mechanism to associate its own social profile with another user's account.

Objective:/ Conduct a CSRF attack to link your social network profile to the site administrator account, then access the admin panel and delete user **carlos**.

Contraintes :

* The administrator systematically opens any content sent from the operating server.
* The administrator always has an active session on the blog site.

**Comptes disponibles**

* Site account: `wiener / peter`
* Social network profile: `peter.wiener / hotdog`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f035e4e95319e6757c7a1e87077265181f1037c5%2F%7B9B021944-FC9E-4C73-9DB7-08132E7AB7A7%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analysis of the OAuth mechanism**

* The site allows a classic connection via login and password.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ba26aa06f7e7a6eb53ec0e16036cac8d7c821788%2F%7BBDD5638A-9B29-4D3C-9D5D-18C54D3C0CCD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

A connection via OAuth (social network) is also available.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-94127a5d88b079dc764f6d5a1958c3ab1a4c3470%2F%7B89AC4528-028A-406A-BC4C-451101EF9EE2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* An existing user can link a social network profile to his or her account.

During the link, an OAuth query is sent to the authentication point:

{% code overflow="wrap" %}

```http
GET /auth?client_id=s4z8vs36ubaet908r8qfn&redirect_uri=https://0ac30047040d749984bf3b740088002a.web-security-academy.net/oauth-linking&response_type=code&scope=openid%20profile%20email HTTP/2
```

{% endcode %}

After authentication, the user is redirected to a URL containing an OAuth code:

```http
GET /oauth-linking?code=pYNeIWIFHaUh_fmTub7fAYLzcyNAEvDoKMh9iljTU1Q HTTP/2
```

This code:

* Is for single use
* To link the OAuth profile to the currently authenticated account

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-692233e9b1403f7ec3737a434e7922743f4c53d2%2F%7BA9D8B5BA-F9CD-40E4-BD38-AFF0BBAC7822%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Exploitation of vulnerability**

1. Start the link procedure between your account and your social network profile.
2. Intercept and copy the `/OAuth-linking?code=...` URL.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e6470d69b54bb159a57db680b2c5c21efab01392%2F%7BECCD32A8-D5CE-4500-839C-4FB22D160CDE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Drop the request so that the code is not consumed.

From the operating server, send this URL to the administrator via a CSRF attack, for example using an iframe

{% code overflow="wrap" %}

```javascript
<iframe src="https://0ac30047040d749984bf3b740088002a.web-security-academy.net/oauth-linking?code=pYNeIWIFHaUh_fmTub7fAYLzcyNAEvDoKMh9iljTU1Q"></iframe>
```

{% endcode %}

The administrator loads the page:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e7b2d3569773c57462ea3dac9900b7f5bd3d69da%2F%7B330F7921-1FBF-42B5-B2E6-1092A03CEAF4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

OAuth code is consumed

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-81b2b362756a441e936a6a63f69152ede9210982%2F%7B90C1F5AB-FC90-4ABF-A46B-A30DD3BA4409%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The attacker's OAuth profile is linked to the administrator account

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-19ed647e1493f7cf7e48fdd225ddb53ac8e15212%2F%7B1FF37DFD-0799-4E65-B448-ABD61F14B3AF%7D.png?alt=media" 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 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/web/oauth-authentication/forced-oauth-profile-linking.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.
