admin管理员组文章数量:1302328
This is the message I am getting using a Leaflet.js heatmap, and I can't see my circle markers, and I believe this is most likely the issue.
Because a cookie’s SameSite attribute was not set or is invalid, it defaults to SameSite=Lax, which prevents the cookie from being sent in a cross-site request. This behavior protects user data from accidentally leaking to third parties and cross-site request forgery. Resolve this issue by updating the attributes of the cookie: Specify SameSite=None and Secure if the cookie should be sent in cross-site requests. This enables third-party use. Specify SameSite=Strict or SameSite=Lax if the cookie should not be sent in cross-site requests.
I am using Javascript, and the video from Chrome said to do:
Set-Cookie: cname=cvalue; SameSite = None; Secure
But where do I do this?
This is the message I am getting using a Leaflet.js heatmap, and I can't see my circle markers, and I believe this is most likely the issue.
Because a cookie’s SameSite attribute was not set or is invalid, it defaults to SameSite=Lax, which prevents the cookie from being sent in a cross-site request. This behavior protects user data from accidentally leaking to third parties and cross-site request forgery. Resolve this issue by updating the attributes of the cookie: Specify SameSite=None and Secure if the cookie should be sent in cross-site requests. This enables third-party use. Specify SameSite=Strict or SameSite=Lax if the cookie should not be sent in cross-site requests.
I am using Javascript, and the video from Chrome said to do:
Set-Cookie: cname=cvalue; SameSite = None; Secure
But where do I do this?
Share asked Feb 25, 2021 at 3:25 Ryan LindseyRyan Lindsey 1231 gold badge1 silver badge5 bronze badges 7-
1
When you set cookies, you can set attributes that the browser will read, such as
Expires
orMax-Age
(Cookie: a=b; Expires=Wed, 21 Oct 2021 07:28:00 GMT
).Same-Site
andSecure
are such attributes. So if you're setting cookies, be that on the server-side or from JS, you'll have to add; SameSite=None; Secure
at the end. – Andreu Botella Commented Feb 25, 2021 at 3:29 - 1 So I put (Cookie: a=b; Expires=Wed, 21 Oct 2021 07:28:00 GMT; SameSite=None; Secure) at the top of my JS file? What specifically do I put? Sorry for my ignorance lol – Ryan Lindsey Commented Feb 25, 2021 at 3:36
-
If you're using cookies, you must be either setting
document.cookie
on your javascript, or you must have some server-side code (PHP, Node.js, Flask, Django, etc) that adds aSet-Cookie
header. The value ofdocument.cookie
or of theSet-Cookie
header is what you have to change. – Andreu Botella Commented Feb 25, 2021 at 3:41 - I'm not using document.cookie, because I have no clue what that is. I'm sending http requests via MapBox API that are getting blocked, so assuming it would be document.cookie, which I have not specified in my JS document, what would I do? I need literal code haha – Ryan Lindsey Commented Feb 25, 2021 at 3:52
-
This is probably not your fault, since that's something the MapBox API would have to change. The requirement for cookies to be marked either
SameSite=None
orSecure
is a recent change in all browsers, needed because anything else would have a high risk of exposing your cookies (and so your login sessions) to someone who shouldn't have them. That said, make sure you're calling that API over HTTPS, rather than HTTP – Andreu Botella Commented Feb 25, 2021 at 3:57
1 Answer
Reset to default 0// set cookie
app.get("/set-cookie", (req, res) => {
res.header("Set-Cookie", `username="john doe"; Path=/; HttpOnly; Secure; SameSite=None;`);
res.status(200).json({ message: "Cookie has been set" });
});
// clear cookie
app.get("/clear-cookie", (req, res) => {
res.clearCookie("username");
res.status(200).json({ message: "Cookie has been cleared" });
});
本文标签:
版权声明:本文标题:javascript - Chrome is blocking third party cookies; asking me to set Same Site attribute = None and Secure, but does not specif 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741714784a2394043.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论