-
Notifications
You must be signed in to change notification settings - Fork 143
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
Be able to have different strategies of session storage between logged users or anonymous ones #623
Comments
@Will956 , I just tested a recent version of this SDK and did not see any anonymous sessions hit my custom session store. If you clone this repo and do the following you should be able to replicate it:
You should see the following two lines when you first startup the app + begin a login (at localhost:3000):
And then you shouldn't see any other memorystore logs until after the login is complete, like this:
The auth verification response cookies this SDK creates for anonymous sessions doesn't hit the custom store, they are always stateless sessions signed with the PS - I tested this in the context of other workflows like calling |
Hello @madaster97, thanks for looking! There is something that I forgot to mention and, I think, it's important: we persist a session ID in the session object for anonymous sessions. EDIT: that's what I said here, sorry maybe it was not clear
That's what's triggering the storage of that anonymous session I guess 😅 Did you try adding something to the anonymous session? |
Ah yep I see what you mean. I see the same behavior if I try to set a req.appSession value before login. Not sure how difficult it would be to accommodate what you're asking for. One word of warning, how are you using your session ID? Is it for CSRF protection/something similar? If that's the case, you probably want to toss that out on login anyway, so that you don't get some sort of session fixation vulnerability. General idea is someone could walk up to a computer and start a session/get the ID, and if someone else comes and logs in then the initial person would know their session ID. If it was specifically CSRF you had in mind, you should check out a rejected PR 453 of mine discussing CSRF in this library. TLDR - the library's cookie attributes are generally good enough for CSRF protection (as long as you don't do stateful GETs). |
Mainly to link previous anonymised actions from an anonymous user to his analytics profile when he logs in. And yes we create a new one when the user logs in to prevent what you described! Yes, that's quite a custom approach that this library may not want to cover. I'll let that open for a couple of days and will close if no one jumps on it. Thanks for your input! |
Checklist
Describe the problem you'd like to have solved
We use this library to handle our sessions and store them in Redis. The drawback of that is those anonymous requests persist anonymous sessions in our Redis, and that can be huge (crawlers, scrapper, data scripts, etc...). We still want to persist those sessions somewhere because we attribute a session id for them.
Our Redis cluster is so full of anonymous session and we have memory issues.
Describe the ideal solution
I guess the ideal solution will be to have different storage strategies based on logged-in or anonymous users.
Alternatives and current workarounds
At the moment, we init different instances of this library based on cookie value: if we know that we have a cookie of a logged-in user, we init the auth middleware that has Redis configuration (so logged-in sessions are persisted within Redis). If we know that we have a cookie of anonymous users, we init the auth middleware that persists sessions within the cookie.
Additional context
Our workaround works, but it seems hacky and the logic to know if it's a cookie from a logged-in user or not is not fully bullet-proof.
Maybe I'm missing something here and there is an obvious way of achieving that without this complexity.
Thanks!
The text was updated successfully, but these errors were encountered: