Opened 14 years ago
Closed 14 years ago
#15618 closed (fixed)
django.contrib.messages.storage.fallback.CookieStorage does not behave properly with subdomains
Reported by: | Chris Lamb | Owned by: | nobody |
---|---|---|---|
Component: | Contrib apps | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Chris Lamb, niels.busch@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Imagine you have two domains "www.example.com" and "special.example.com". Your SESSION_COOKIE_DOMAIN
is set to ".example.com" so that users are logged-in across these two subdomains.
The problem arises when a page on "www.example.com" sets a django.contrib.message
and redirects to "special.example.com", the user will not see it unless they return to "www.example.com" as the default domain of the cookie is the current one. This naturally causes confusion as actions users have performed in the past suddenly are being confirmed (!).
This happens with FallbackStorage
too as it wraps CookieStorage
.
Patch attached that sets the domain of the CookieStorage cookie to SESSION_COOKIE_DOMAIN. Whilst this works, it might be better to not couple sessions
and messages
in this way, so we could alternatively introduce a new setting under a the MESSAGE_STORAGE_
namespace.
Attachments (3)
Change History (9)
by , 14 years ago
Attachment: | 03-domain-of-messages-cookie.diff added |
---|
comment:1 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
Note that I opted to use SESSION_COOKIE_DOMAIN here even though this technically isn't for django.contrib.sessions. I didn't want to add another setting, and I couldn't think of a case where you might want the cookie domain to be different for messages vs. sessions. Down the road we may want to rename SESSION_COOKIE_DOMAIN to COOKIE_DOMAIN.
comment:3 by , 14 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Oops, we need to delete the cookie from the right domain too. Attaching patch.
by , 14 years ago
Attachment: | 03-delete-cookie-from-correct-domain.diff added |
---|
comment:4 by , 14 years ago
Cc: | added |
---|
by , 14 years ago
Attachment: | 15618_message_cookies_domain.diff added |
---|
comment:5 by , 14 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
Thanks for spotting this. See attached patch with the final fix and tests for the whole thing.
In [15848]: