cookie_session: set path to / so router wildcards don't mess up sessions #387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is currently a bug (one example is in #307) where the cookie sessions are not persisted when they are set from within a wildcard route. The issue seems to be that
Cookie.set_cookie
, when not given apath
argument, defaults to usingRouter.prefix request
. This means that if you have code like:The field
"foo"
is lost, since the cookie that is set is scoped to/somepath
, and is thus not loaded by the session middleware.A complete reproduction is the following repo:
https://github.com/dbp/dream-session-bug-repro
I'm not sure why the cookies default to the router prefix (perhaps that is a bug), but if that is intended behavior, the included patch fixes this behavior by making the cookie session set the path to be
"/"
, so it does not use a default.If the cookie_sessions middleware is intended to be able to work on scoped subsites, then this is not the right fix, but also, if that is the case, then there needs to be a larger restructuring of the code, as there would need to be some way of the code indicating which session the field was being written to.