【问题标题】:Allow cookies to be used from different origin subdomain允许从不同的源子域使用 cookie
【发布时间】:2021-10-20 15:29:06
【问题描述】:

如果我的浏览器地址栏上的 url 是 dev.example.com 并且如果我向 sub1.dev.example.com 发出请求,它会使用具有以下属性的 set-cookie 进行响应:

  • httpOnly
  • 安全
  • 没有同站点属性(默认为宽松)
  • 域=dev.example.com

虽然仍在dev.example.com 上,但如果我调用sub2.dev.example.com,cookie 会在请求中发送过来,这正是我所期望的。

但是,如果我的浏览器地址栏上的 url 是 sub3.dev.example.com 并且我调用 sub2.dev.example.com,则不会发送 cookie。

(已在 chrome 92 和 firefox 90 上验证)

有没有办法在原点sub3.dev.example.com 上向sub2.dev.example.com 发送一个cookie,其中特定的cookie 是在来自sub1.dev.example.com 而在原点dev.example.com 的请求响应中设置的?

或者更好的是,允许将 cookie 发送到 **.dev.example.com 的所有子域,同时位于 **.dev.example.com 的任何源子域上,而与最初请求或设置 cookie 的源无关。

【问题讨论】:

    标签: http cookies subdomain


    【解决方案1】:

    在测试了一些之后,我好像忘记在我的请求中添加“withCredentials”标志了。

    对于偶然发现此问题的任何人,如果您使用 axios,请确保在调用中将“withCredentials”设置为 true,如果您使用 fetch,请确保将“credentials: 'include'”设置为 true。

    【讨论】:

      猜你喜欢
      • 2021-01-19
      • 2015-12-19
      • 2016-12-07
      • 2023-04-04
      • 2021-12-22
      • 1970-01-01
      • 2011-11-15
      • 2016-05-15
      • 1970-01-01
      相关资源
      最近更新 更多