問題描述想通過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。
- 1 回答
- 0 關注
- 672 瀏覽
添加回答
舉報
0/150
提交
取消
