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

IDP-634 Use cookies not session to store token #154

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jason-jackson
Copy link
Contributor

Changed

  • Use cookies not session to store token
@jason-jackson jason-jackson requested a review from a team May 14, 2024 14:54
@forevermatt
Copy link
Contributor

I'm a little concerned about this approach, because if we're setting it in a cookie that means it's getting passed back and forth with every web request to that host. We might have already been doing that (we probably were... it's the user's access token, after all), but does this mean we will now be including it twice in the request? I'm concerned that there may be leftover code that will make debugging harder if we just switch this from sessionStorage to a cookie: there are probably other code changes needed in order to update our overall approach to be based on storing (and passing) this in a cookie, rather than however our code was doing so before.

Don't get me wrong: This is a great start. It just might not be complete.

sessionStorage.removeItem('token_type')
sessionStorage.removeItem('access_token')
Cookies.remove('token_type')
Cookies.remove('access_token')
Copy link
Contributor

@hobbitronics hobbitronics May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should include the same path and sameSite as when we set them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, since('/') is the default we don't really need it.

Copy link
Contributor

@hobbitronics hobbitronics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions. Use secure: true in production and staging and sameSite: 'strict', but will need to specify these when removing cookies as well.

@hobbitronics
Copy link
Contributor

I'm a little concerned about this approach, because if we're setting it in a cookie that means it's getting passed back and forth with every web request to that host. We might have already been doing that (we probably were... it's the user's access token, after all), but does this mean we will now be including it twice in the request? I'm concerned that there may be leftover code that will make debugging harder if we just switch this from sessionStorage to a cookie: there are probably other code changes needed in order to update our overall approach to be based on storing (and passing) this in a cookie, rather than however our code was doing so before.

Don't get me wrong: This is a great start. It just might not be complete.

For cookies to be (relatively) secure from xss, I think they need to be set by the server and httpOnly. That would mean moving this code over to the server side. Does that seem right or is there something I'm missing. That's what I got from reading this article anyways.

@forevermatt
Copy link
Contributor

For cookies to be (relatively) secure from xss, I think they need to be set by the server and httpOnly. That would mean moving this code over to the server side. Does that seem right or is there something I'm missing. That's what I got from reading this article anyways.

Yes, that sounds correct. And bonus points for citing Jeff Atwood. 😁

@hobbitronics
Copy link
Contributor

hobbitronics commented May 16, 2024 via email

@forevermatt
Copy link
Contributor

So what's the next step for this? Was there work being done to try to switch to setting the cookie server-side? (I might be combining separate issues in my mind...)

Copy link

sonarcloud bot commented Jun 5, 2024

@hobbitronics
Copy link
Contributor

So what's the next step for this? Was there work being done to try to switch to setting the cookie server-side? (I might be combining separate issues in my mind...)

I think that's the direction we need to go. Regular cookies are still available to client side JS so not really more secure.

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