想通过samesite防止csrf攻击,但是写了个demo,cookie始终能别拿到。
我启动了两个网站,端口分别是3001和3002,3001设置cookie,3002请求3001的服务。
3001的cookie设置了samesite为strict,但是3002发出的请求仍能拿到cookie。
开发语言nodejs,框架express,chrome浏览器
// 3001代码
app.get("/main", (req, res) => {
res.cookie("name", "wenmu", { sameSite: "strict" });
res.set({ "Content-Type": "text/html" });
res.sendFile("main.html", { root: __dirname });
});
app.get("/setVal", (req, res) => { console.log(req.headers.cookie); console.log(req.headers.referer);
res.send([req.headers.referer, req.headers.cookie]);
});
app.listen(3001, () => { console.log("app start on port 3001");
});//3002代码
<a href="http://localhost:3001/setVal">百元大奖</a>
点击“百元大奖”发出的请求,服务端接收到请求后不应该携带cookie。
元芳怎么了
缥缈止盈
随时随地看视频慕课网APP
相关分类