浏览器未设置安全的 httpOnly cookie,提示“域属性对于当前主机 url 无效”

问题描述

我的网络客户端部署在 https://web-xxxxxxxx-uw.a.run.app(由 Google cloud run 部署),后端 API 部署在 https://api-xxxxxxxx-uw.a.run.app

此处的后端负责设置 httpOnly secure cookie,但浏览器不允许。我不是在 cookie 域上设置 API 的实际 url,而是一个域。

我浏览了一些 SO 帖子,其中提到如果我们想从跨 url 设置 cookie,那么它们都必须属于同一个域。就我而言,它是 .a.run.app。后端仅设置此域,但仍获得 this set-cookie domain attribute was invalid with regards to the current host url

https://serverfault.com/questions/153409/can-subdomain-example-com-set-a-cookie-that-can-be-read-by-example-com
Set cookies for cross origin requests
Set-Cookie was blocked because its Domain attribute was invalid with regards to the current host url

这是饼干:

set-cookie: authToken=eyJ0eXAiOiJKV.1ZmkuY29tIiwiZXhwIj.h7g7jib4_orn; Path=/; Domain=.a.run.app; Max-Age=864000; Expires=Fri,09 Apr 2021 13:51:57 GMT; Secure; HttpOnly; SameSite=None

后端代码是用Spring boot写的:

ResponseCookie cookie = ResponseCookie.from(AUTH_COOKIE_NAME,token)
        .httpOnly(true)
        .maxAge(EXPIRATION_TIME_SEC)
        .path("/")
        .sameSite("None")
        .secure(true)
        .domain(".a.run.app")
        .build();
httpServletresponse.addheader(HttpHeaders.SET_COOKIE,cookie.toString());

在这里做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...