-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Do not create a session if no cookie was provided #3372
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3372 +/- ##
==========================================
+ Coverage 76.98% 77.02% +0.04%
==========================================
Files 227 227
Lines 8697 8697
==========================================
+ Hits 6695 6699 +4
+ Misses 2002 1998 -4
🚀 New features to boost your workflow:
|
|
I think this is partially intended behavior, in that |
|
Yep agree with @gwynne here, if you have a global sessions middleware you should see a |
Gotcha, so the check in
Happy to update the logic, but what is the desired behavior? |
|
@czechboy0 My take is that when creating a new session ( |
|
Yeah I think if we have a session cookie, then we should always set the session. If there's no session cookie in the request, then we're in a fresh state to decide whether to set the |
|
The problem is that when you have an
And then, since the session already exists, the I'm trying to avoid the session being created in the driver at all. What specifically do you think should change? |
Summary
When using
SessionsMiddlewareand a customAsyncSessionAuthenticatortogether, we were seeing that even in cases when no cookie is provided in the request, and no error was thrown by e.g. a guard middleware or the handler, we were still seeing aset-cookieheader in the response, which isn't desired.This lead to many sessions created in the sessions driver for calls that didn't require authentication, nor did it provide any.
This seemed to be a side effect of the way
AsyncSessionAuthenticatorchecked if the session already contained an authenticated value - by using the getterrequest.session, a session was created lazily.The fix is to prepend a check to
request.hasSessionand only usingrequest.session...if one indeed exists.Test Plan
A regression test was added which exercises this scenario - and it fails without the fix.