尽管我在express应用程序上进行了以下设置,但控制台中仍显示以下警告。以前有没有人见过这个错误?我的搜索使我找到了https://github.com/expressjs/express/issues/3095
我也在使用express : 4.17.1
let COOKIE_OPTIONS = { httpOnly: true, sameSite: 'None', secure: true };A cookie associated with a cross-site resource at http://MYURL.URL was set
without the `SameSite` attribute. A future release of Chrome will only deliver
cookies with cross-site requests if they are set with `SameSite=None` and
`Secure`. You can review cookies in developer tools under
Application>Storage>Cookies and see more details at
https://www.chromestatus.com/feature/5088147346030592 and
https://www.chromestatus.com/feature/5633521622188032.在使用Insomia (Postman)进行请求时,我看到以下内容
access_token=someToken;
Path=/;
HttpOnly;
Secure;
SameSite=None发布于 2020-02-05 16:17:46
文档链接:https://www.npmjs.com/package/express-session#cookiesamesite
下面的代码将解决您的问题。这也是未来的建议。
const express = require('express');
const session = require('express-session');
const app = express();
const sessionConfig = {
secret: 'MYSECRET',
name: 'appName',
resave: false,
saveUninitialized: false,
store: store,
cookie : {
sameSite: 'strict', // THIS is the config you are looing for.
}
};
if (process.env.NODE_ENV === 'production') {
app.set('trust proxy', 1); // trust first proxy
sessionConfig.cookie.secure = true; // serve secure cookies
}
app.use(session(sessionConfig));在您的示例中,将sameSite设置为'none'
如果你想知道什么是store?我使用我的数据库作为所有cookie的存储。这与OP提出的问题无关。正如@klevis在评论中指出的那样添加。代码如下:
const KnexSessionStore = require('connect-session-knex')(session);
const store = new KnexSessionStore({
tablename: 'session',
knex: kx,
createtable: false
});发布于 2019-10-16 16:58:36
据我所知,这是一个关于未来新的chrome实现的警告。
cookies上的
相同站点选项:从Chrome80开始,未指定samesite属性的cookies将被视为SameSite=Lax,并具有附加行为,即它们仍将包含在POST请求中,以简化现有站点的转换。
欲知详情,请登录:https://www.chromium.org/updates/same-site
如果你想测试你的网页,这篇文章解释了如何设置Chrome标志进行测试。如果您的页面停止工作,您必须检查所有请求并查看"http://“to "https://”更新或检查第三方cookie
发布于 2021-07-14 17:26:30
您可以在不使用任何节点包的情况下设置这些选项。使用Express时,仅如下所示:
app.get('/', (req,res)=>{
//.....Other Code
res.cookie('cookieName', 'cookieValue', { sameSite: 'none', secure: true})
//.....Other Code
})https://stackoverflow.com/questions/58228871
复制相似问题