When hosting multiple Drupal sites on a shared domain, users are unable to log into more than one site because all the sites use the same session cookie name. The cookie can only contain the session of the last site they log into.
The session cookie prefix should be configurable in settings.php for upstream processing by a reverse proxy, and a database hash should be included in the cookie name so even sites that do not set a custom cookie prefix will not overwrite another site's session cookie. The current prefix is SESS for HTTP connections and SSESS for secure-only cookies. Our fix allows a configurable prefix to be added before the SESS or SSESS prefix.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | drupal-core-1361742-allow-configurable-cookie.patch | 4.4 KB | martygraphie |
Issue fork drupal-1361742
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
erikwebb commentedComment #2
erikwebb commentedComment #3
erikwebb commented#1: allow-configurable-cookie-prefix-1361742-1.patch queued for re-testing.
Comment #4
cashwilliams commented+1
Comment #5
ultimateboy commented#1: allow-configurable-cookie-prefix-1361742-1.patch queued for re-testing.
Comment #5.0
ultimateboy commentedUpdated wording to mention secure cookies, rather than HTTPS.
Comment #16
botanic_spark commentedI refactored the patch so that it's applicable to 8.9 and D9
Comment #17
botanic_spark commentedComment #19
BS Pavan commentedFixed fail test cases.
Comment #20
rockthedrop commentedComment #24
darren ohAnother use for a custom cookie prefix is to prevent sites that don't have their subdomains set up hierarchically from overwriting each other's cookies. Example:
site.a.example.com and site.b.example.com are different locales for the same site. They use .example.com as their cookie domain.
anothersite.a.example.com and anothersite.b.example.com also share the .example.com cookie domain, and they overwrite the other site's cookies.
Comment #25
darren ohComment #28
ambient.impactI'm glad to see some movement on this issue, but please don't prefix "S" or anything else in a secure context, as it defeats the main reason I and possibly many others need this configurability: the
__Secure-and__Host-prefixes which allow a higher level of security in all modern browsers.To quote the MDN article on the
Set-Cookieheader:To quote Tough Cookies by Scott Helme:
Comment #29
darren ohComment #30
darren ohComment #32
darren ohComment #33
ambient.impactJust tested this out and it works great for my use case as described above! My only suggestion is to rephrase the docblock slightly as the wording feels off. Current one:
I suggest this, which adds a first line to match other docblocks and also rewrites the first sentence to flow a bit better and not use "create" twice in a way that felt ambiguous:
Comment #34
ambient.impactWhoops, did not mean to change these.
Comment #35
smustgrave commentedTagging for framework manager reviews for their thoughts.
Either way think this will require a test case for the new feature.
Also MR has failures.
Comment #37
poker10 commentedThanks for working on this @Darren Oh!
I would say we need to split the patch, because it seems to me that it is combining two separate changes:
Adding a cookie prefix:
Fixing a problem with overwriting site cookies:
I think the second change (seems like a bug-fix?) should be in a separate issue. Or the issue title + summary needs to be updated and explained why there are these two changes together. Thanks!
Comment #38
darren ohComment #39
darren ohpoker10, I have updated the issue description. Both changes are addressing the same bug. The configurable prefix was the original solution, but it requires site owners to take action to prevent the bug. I added the database hash as a more reliable solution that does not require action from site owners. I believe both solutions are required because the same bug affects reverse proxies that filter cookies, and the database hash does not fix that.
Comment #40
darren ohComment #41
darren ohComment #42
damienmckennaThis could be tested by leaving the prefix blank, logging into the site, changing the prefix, reloading the site and confirming that the session is no longer logged in, then removing the prefix and confirming the original session is logged in again; might be a little fiddly to do, but it'd be simpler than trying to create concurrent installs of core.
And I suspect the test coverage failures are related to the addition of the hash_salt setting to the session name, maybe this should be optional and it should just use the prefix?
Comment #43
sadikyalcin commentedWhat's the state with this? I see the last activity was 2 years ago. I've got the same issue right now. This change should be in core IMO.
Comment #45
martygraphie commentedHi,
I am attaching a proposed patch for this issue, including a unit test to validate the behavior.
The implementation has been tested successfully on a Drupal 11 instance and appears to work correctly.
For maintainability reasons and to ease compatibility with future Drupal core updates, I am proposing a version of the patch that does not rely on the hash salt, along with dedicated test coverage.
I was not able to update the issue repository, which is still based on an older Drupal version (Drupal 10), so I am providing the patch file directly.
Marc