Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Login response Cookies (for refresh token, etc) #147

Closed
Ojisama opened this issue Sep 1, 2023 · 2 comments · Fixed by #149
Closed

Use Login response Cookies (for refresh token, etc) #147

Ojisama opened this issue Sep 1, 2023 · 2 comments · Fixed by #149

Comments

@Ojisama
Copy link

Ojisama commented Sep 1, 2023

There is an issue with how the frontend handles cookies from the login.

getAccessFromResponse(await apiClient.post<unknown>(ApiRoutes.login, data)),

should instead read

getAccessFromResponse(await apiClient.post<unknown>(ApiRoutes.login, data, { withCredentials: true })),

Currently, according to XMLHttpRequest specs (which Axios uses behind the scenes), if the request doesn't have withCredentials: true, the Cookies in the response headers (set by Set-Cookie) are simply ignored.

Spent hours debugging why my browser wouldn't use the cookies from the headers, when they were clearly there...
By the way, I guess you should also add the AccessToken in the response cookies, since you'd want to send it via getStaticProps to have authentication for SSR.

@Ojisama
Copy link
Author

Ojisama commented Sep 26, 2023

@LeoAnesi ?

@LeoAnesi
Copy link
Collaborator

@Jeremie-Chauvel FYI
You're right we should add the withCredentials to this call. I'll do a PR this afternoon.

But adding the access token to the cookies would be a security flaw in my opinion, it exposes you to CSRF attack. We can not simply add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants