Reputation: 813
I have a google cloud bucket CDN-Cookie to access my google cloud bucket pictures. On my web server everything is working great with setting the cookies and retrieving the image. But in my development environment, I'm on localhost and it's not sending the cookies because it doesn't have https. What's the go-to approach for a development environment to deal with this kind of issue as making localhost to https://localhost seems quite complex for multiple development environments.
Here the http://localhost cookie error
Migrate entirely to HTTPS to have cookies sent to same-site subresources A cookie was not sent to a secure origin from an insecure context. Because this cookie would have been sent across schemes on the same site, it was not sent. This behavior enhances the SameSite attribute’s protection of user data from request forgery by network attackers. Resolve this issue by migrating your site (as defined by the eTLD+1) entirely to HTTPS. It is also recommended to mark the cookie with the Secure attribute if that is not already the case.
Upvotes: 4
Views: 18101
Reputation: 11
I had a similar problem when i was working on a MERN application where my node js was having a HTTPS server but in developement the frontend react was running on http so the cookies were not getting sent in the request header. Adding following in express-session code solved the issue
app.use(
session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: true,
cookie: {
sameSite: "none",
secure: "auto",
},
})
);
Upvotes: 0
Reputation: 51
To start, it sounds like your localhost development workflow includes some portions on https, otherwise you wouldn't be seeing that message: "A cookie was not sent to a secure origin from an insecure context".
What's the go-to approach for a development environment to deal with this kind of issue
There's not one per-se, it's dependent on your environment. You have a few options that you can consider:
SameSite=Strict
and SameSite=Lax
cookies to SameSite=None; Secure
. Samesite=None cookies are sent freely between schemes.SameSite=None
must be Secure
requirement" and "Unspecified SameSite is treated as SameSite=Lax
", see the links for more info there.Upvotes: 4