cookies - 为什么我得到 "Indicate whether to send a cookie in a cross-site request by specifying its SameSite attribute"?

标签 cookies express-session

在 Chrome 警告中,它说“如果 cookie 应该在跨站点请求中发送,则指定 SameSite=None 和 Secure。这允许第三方使用。”如何使用 express-session 正确执行此操作?

app.use(
  cors({
    credentials: true,
    origin: ["http://localhost:3000", "https://elated-jackson-28b73e.netlify.app"] //Swap this with the client url 
  })
);
var sess = {
  secret: 'keyboard cat',
  cookie: {}
}

if (app.get('env') === 'production') {
  app.set('trust proxy', 1) // trust first proxy
  sess.cookie.secure = true // serve secure cookies
  sess.cookie.sameSite = 'none'
}

app.use(session(sess))

最佳答案

您之所以收到此消息,是因为您正在使用来自另一个站点的资源,并且该服务器正在尝试设置“cookie”,但是它没有设置 SameSite 属性,这是在较新版本的浏览器中报告的。
这(可能)也显示 如果您尝试从 访问服务器页面本地计算机 (xampp),通常没有安装 SSL;
在您的服务器页面中设置标题行(如果在 PHP 中)如下:header("Set-Cookie: cross-site-cookie=whatever; SameSite=None; Secure"); (记住:这必须从服务器端解决。)

关于cookies - 为什么我得到 "Indicate whether to send a cookie in a cross-site request by specifying its SameSite attribute"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63273838/

相关文章:

macos - Google Chrome Cookie存储

javascript - cookie 域上的点前缀阻止 CORS 请求

Javascript 设置 Cookie 以记住表单提交

php - PHP 中跨 HTTP 和 HTTPS 的 Cookie

node.js - 如何通过 MongoStore 查找存储在 Mongo 中的 session ?

javascript - 我如何拥有两个 Express session ?

performance - 通过移动网络的 HTTP/2 浏览器请求一次往返有多少字节?

Javascript 如何在客户端引用 Express-Session

node.js - 使用express-session和express-socket.io-session NodeJs时出错