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

cookie_session: set path to / so router wildcards don't mess up sessions #387

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dbp
Copy link

@dbp dbp commented Feb 25, 2025

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 a path argument, defaults to using Router.prefix request. This means that if you have code like:

Dream.scope "/somepath" [
  Dream.get "/**" (fun req -> ... Dream.set_session_field req "foo" "bar"
]

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.

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 this pull request may close these issues.

1 participant