在响应标头上显示时未设置HttpOnly Cookie

时间:2020-10-31 20:25:33

标签: javascript node.js cookies next.js samesite

遵循此SO

HTTPOnly cookie存在于获取响应中,但未设置且在浏览器检查器中不可见。

  • 客户端:尝试https://localhost:3000https://127.0.0.1:3000(在本地主机上进行本地SSL设置以进行安全通信)
  • 服务器端:https://api.example.comSSL

服务器端代码段(Express js):

//Cors config
let domains = new Array();
domains[0] = 'https://localhost:3000';
domains[1] = 'https://127.0.0.1:3000';

let corsOptions = {
    origin: domains,
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE, OPTION',
    credentials: true,
};

app.use(cors(corsOptions));
// Set-Cookie
res.cookie('jid', refreshToken, {
    expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
    httpOnly: true,
    secure: true, 
    sameSite: 'None',
    path: '/api/v1/login',
});

客户端代码段(下一个js):

fetch('https://api.example.com/endpoint', {
    method: 'GET',
    credentials: 'include',
});

浏览器检查器显示jid中存在Response headers cookie:

inspector net

但是未设置cookie,并且在“存储”标签下看不到该cookie:

enter image description here

这已经在Firefox和Chrome上尝试过,显示出相同的结果。

与SameSite Cookies或Corn相关的控制台上未显示任何错误或警告,因此我认为我们的服务器端配置有效。

与此有关的另一个问题是,如果没有首先设置jid cookie,该如何在Request headers中发送它?那是谁来的?

更新0(2020/11/01)

现在无需进行任何更改,看来did cookie在控制台上在Google Chrome下可见,但在Firefox上仍然不存在。

0 个答案:

没有答案
相关问题