問題描述想通過samesite防止csrf攻擊,但是寫了個(gè)demo,cookie始終能別拿到。問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法我啟動(dòng)了兩個(gè)網(wǎng)站,端口分別是3001和3002,3001設(shè)置cookie,3002請(qǐng)求3001的服務(wù)。3001的cookie設(shè)置了samesite為strict,但是3002發(fā)出的請(qǐng)求仍能拿到cookie。相關(guān)代碼開發(fā)語言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">百元大獎(jiǎng)</a>期待的結(jié)果點(diǎn)擊“百元大獎(jiǎng)”發(fā)出的請(qǐng)求,服務(wù)端接收到請(qǐng)求后不應(yīng)該攜帶cookie。
1 回答

縹緲止盈
TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
samesite并不遵循同源策略,而是Public Suffix List
所以不同端口號(hào)、不同子域名都被認(rèn)為是同站
- 1 回答
- 0 關(guān)注
- 664 瀏覽
添加回答
舉報(bào)
0/150
提交
取消