使用带有凭据的 Fetch 的跨源 AJAX 请求:'include' 和使用 SameSite=None 设置的 cookie 在 Firefox 中不会发送

问题描述 投票:0回答:1

我正在尝试使用从attacker.local到defender.local的提取来发出跨域AJAX请求,并且我希望该请求包含在defender.local上设置的cookie。

我已遵循本指南:https://stackoverflow.com/a/67001424

https://defender.local已使用此标头设置cookie:

Set-Cookie: secure-cookie=secure-cookie-value; Max-Age=86400; Domain=.defender.local; Path=/; Expires=Sat, 21 Sep 2024 16:50:02 GMT; Secure; SameSite=None

我的获取请求(来自attacker.local)是通过以下方式完成的:

fetch('https://defender.local', {
  method: 'post',
  credentials: 'include',
});

defender.local 使用这些标头进行响应:

Access-Control-Allow-Origin: https://attacker.local
Access-Control-Allow-Credentials: true

使用 Chrome v129 发出此请求可以,但使用 Firefox v130 则不行。

为什么POST请求中不包含cookie?

ajax firefox cors fetch-api
1个回答
0
投票

当启用增强跟踪保护时,Firefox 将禁止这些跨源请求中的 cookie,从而保护用户免受使用目标 cookie 的跨源请求的影响:

Firefox does not send cookie with cross origin request when Enhanced Tracking Protection is on

关闭增强跟踪保护后,Firefox 将发送 cookie:

Firefox sends cookie with cross origin request when Enhanced Tracking Protection is off

© www.soinside.com 2019 - 2024. All rights reserved.