为什么没有在请求标头中设置 Cookie?

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

我正在更新旧 Symfony REST API / AngularJS App 组合的授权过程。

在身份验证时,服务器提供 cookie,其中包含要存储在浏览器上的几个令牌,以便将它们添加为后续请求中的标头 - 非常标准 - 但自从部署到我的测试服务器。

在本地一切正常,所以我假设我的请求/响应标头中某处缺少一些安全配置。

一些注意事项:

  • API和应用程序在同一个域但不同的子域
  • 两个子域都使用 HTTPS
  • mydomain.com 不在公共后缀列表中
  • 饼干
    • secure
      标志已设置
    • SameSite
      选项设置为
      strict
    • path
      选项设置为
      /
      所以我的 API 的所有路由都应该被命中
    • domain
      选项设置为
      mydomain.com
      。如果我理解正确,它应该允许为所有 mydomain.com 子域设置 cookie。
  • 请求包括
    withcredentials
    header
  • 回复包括
    access-control-allow-credential
    标题

在 DevTools 中,这是登录请求的样子:

General
----------
Request URL: https://subdomain1.mydomain.com/login
Request Method: GET
Status Code: 200 
Remote Address: xxx.xxx.xxx.xxx:xxx
Referrer Policy: strict-origin-when-cross-origin

Response Headers
----------
access-control-allow-credentials: true
access-control-allow-origin: https://subdomain2.mydomain.com
cache-control: private, must-revalidate
content-encoding: br
content-type: application/json
date: Sat, 04 Mar 2023 01:39:21 GMT
expires: -1
host-header: 6b7412fb82ca5edfd0917e3957f05d89
pragma: no-cache
server: nginx
set-cookie: BEARER=<JWT_TOKEN>; expires=Sat, 04-Mar-2023 02:39:21 GMT; Max-Age=3600; path=/; domain=mydomain.com; secure; httponly; samesite=strict
set-cookie: refresh_token=<REFRESH_TOKEN>; expires=Mon, 03-Apr-2023 01:39:21 GMT; Max-Age=2592000; path=/token; domain=mydomain.com; secure; httponly; samesite=strict
vary: Accept-Encoding
vary: Authorization
x-httpd: 1
x-proxy-cache: MISS
x-proxy-cache-info: 0 NC:000000 UP:SKIP_CACHE_SET_COOKIE
x-robots-tag: noindex

Request Headers
----------
:authority: subdomain1.mydomain.com
:method: GET
:path: /login
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: en-CA,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-GB;q=0.6,en-US;q=0.5
authorization: <ACCESS TOKEN>
cache-control: no-cache
origin: https://subdomain2.mydomain.com
pragma: no-cache
referer: https://subdomain2.mydomain.com/
sec-ch-ua: "Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
withcredentials: true

我读了很多其他有相同问题的问题,但我仍然不知道我哪里搞砸了。一些帮助将不胜感激。

javascript cookies cors setcookie
1个回答
0
投票

withcredentials
不是 HTTP 标头。

withCredentials
是 XMLHttpRequest 对象的属性

获取 API 使用

credentials
选项 代替。

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