Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

reactjs - Chrome isn't saving Cookies in development

I'm trying to set an HTTPOnly token sent from a backend server written in golang into my browser. Before testing on my application I used postman to ensure that my API was working as expected and, like I was planning, the app was saving my refresh token in an HTTPOnly cookie. However, after performing the login, if I check in the application section of Chrome dev tools I can't find my cookie. By searching online I found that this might be an issue with the SameSite parameter, but setting it to Lax didn't solve my problem.

What I have to do to ensure that my token is stored by the browser?

Update: By checking the network of the browser I got this error

This Set-Cookie was blocked because it has the "SameSite=Lax" attribute
but came from a cross-site response which was not the response to a
top-level navigation.

There is a possibility to allow chrome to store SameSite="None" with secure=false or something that allows me to test during development?

//NOTICE: I DON'T WANT TO DISABLE CORS

Update 2: After a lot of research, I found this shortcut to allow chrome to save cookies with SameSite=None even if secure=false.

  1. Go to chrome://flags/

  2. Search for Cookies without SameSite must be secure

  3. Disable and restart your browser.

This will allow you to accept unsecure cookies with None same site policy.

Notice that this approach might open yourself to vulnerabilities if you are using app not properly secured, so it's suggested to use it only during development and re-activate it after testing your application.

I didn't put this part on the answer section since, as I said, it's not a secure solution and maybe exists a better approach to achieve this result.

question from:https://stackoverflow.com/questions/66055788/chrome-isnt-saving-cookies-in-development

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...