【发布时间】:2020-07-13 13:15:03
【问题描述】:
A cookie associated with a cross-site resource at http://tetris-back-end.herokuapp.com/ was set without the `SameSite` attribute.
当我尝试在前端设置 cookie 时出现该错误。以下是我在后端设置 cookie 的方式:
const sessionOptions: Options = {
store: new RedisStore({
client: redis as any,
}),
name: "qid",
secret: String(process.env.SECRET),
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: process.env.NODE_ENV === "development",
secure: process.env.NODE_ENV === "production",
sameSite: "none",
maxAge: 1000 * 60 * 60 * 24 * 7 * 365, // 7 years
},
};
所以同一个站点被设置为无,但我仍然收到该错误。
我在我的开始消息中进行了一些探索并安慰了我的节点环境。
app.listen(process.env.PORT, () => {
console.log(message, `NODE ENV: ${process.env.NODE_ENV} ????`);
});
它在本地打印development,在 Heroku 日志中打印production。
当我在本地设置 cookie 时,它可以工作,但出现错误:
A cookie associated with a resource at http://localhost/ was set with `SameSite=None` but without `Secure`. A future release of Chrome will only deliver cookies marked `SameSite=None` if they are also marked `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5633521622188032.
所以在本地是相同的代码(我在 master 上,它都已同步)。当我这样做时它可以工作,但是由于 NODE_ENV === "development" 它将安全设置为 false。
我认为重要的是,它确实看到我在本地设置了 SameSite=None,但它并没有在生产时接受它。
为什么相同的站点属性会在本地被识别为已设置,但在生产版本中却没有???
任何帮助都将是巨大的!谢谢!
【问题讨论】:
标签: cookies https session-cookies backend production