Session cookies set by Drupal should have their path property set to the base path of the site.
One problem we have observed with this occurs when there are multiple Drupal sites on the same host. A user will get a separate session cookie for each one. All cookies get sent to all sites. We were getting errors as a result of having too many cookies.
Original report
I've attached my patch file and you can see it better if you view it (try kompare [or similar] on the patch file so you can see the changes better).
The cookie used by the session path should limit itself to the same path as the installed instance of Drupal (instead of the whole website). There are three places where session hijacking can occur, client, on the wire, and on the server. This patch helps close the hole that I found on the server!
I am a little tired of trying to explain this issue and figure it's best to SHOW what it is. I'm submitting the patch in hopes that somebody can view it and SEE what I am talking about. (sometimes seeing patch files is only way to fully understand / communicate between developers).
I assume this patch file will also work on 6.3 and assume the problem still exist in 6.3 ... I know security patches should be submitted via *other* means... and I already tried that many months ago (and have apparently been ignored). Please don't flame me for releasing a patch into the open that is security related.
UNDERSTAND, this security hole only exist if you are not the only one running code on a web server (for a particular host).
--Doug (dx9s)
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 289145-nr-bot.txt | 165 bytes | needs-review-queue-bot |
| #18 | drupal-cookie_path-289145-18-D7.patch | 1.11 KB | liam morland |
| #16 | drupal-cookie_path-289145-16-D7.patch | 1.13 KB | liam morland |
| #15 | drupal-cookie_path-289145-15-D7.patch | 1.93 KB | liam morland |
| #14 | drupal-cookie_path-289145-14-d7.patch | 2.77 KB | liam morland |
Comments
Comment #1
bart jansens commentedRe-published this issue and moved it to D7.
Summary of #456 on s.d.o:
If drupal is installed in http://www.example.com/drupal, setting the cookie path to /drupal offers little additional security because another application installed in http://www.example.com/evilapp can still access the drupal cookie. See item #3 at http://code.google.com/p/doctype/wiki/ArticleCompartmentalizingApplications
But it might be cleaner to set the right cookie path, so I'll keep this issue active for future versions.
Comment #2
dx9s commentedYes I understand that client side hacks exist, especially when Javascript is enabled (bad Javascript, go sit in the corner) and that this is a minor issue. I agree that it is definitely cleaner setting the cookie path to the application path and look forward to a "cleaner" fix to the code than what I hacked together for demonstration purposes.
--Doug (dx9s)
Comment #3
lilou commentedPatch no longer applies.
Comment #4
valthebaldComment #6
Joe.U.Questionmark commented#4: session-cookie-path-289145.patch queued for re-testing.
Comment #8
Joe.U.Questionmark commentedThis could be a major security issue. Is there any reason why this hasn't been integrated into core?
Comment #9
a.ross commentedBecause setting the path offers little to no security.
Comment #10
rob230 commentedIt might offer no security, but it is still useful for people running multiple Drupal sites on the same domain. Right now I have one site in the root directory, and one site in a subdirectory, and visiting one logs you out of the other because they both create a session on the root path.
Comment #11
a.ross commentedYes, I agree it should still be fixed despite not being a security issue. I was just arguing against the statement that this could be a "major security issue".
Comment #12
gappleAs I understand the code, multiple sites across root and subdirectories should not conflict if
$cookie_domainis not set. Since the subdirectory is included in$base_url, it is also used in determining the session name when the cookie domain is being dynamically determined, and each site should receive a unique hash. Once$cookie_domainis specified, however, all sites will receive the same hash based on only$cookie_domain, and there is no way to prevent a conflict between sessions on multiple sites.Here's a patch with a different approach, as I tried to remove any disturbance for existing sites, but enable use of a path in setting cookies if needed.
Comment #13
joelpittetWhat about adding that into
$confinstead of including another global variable?Comment #14
liam morlandRe-roll.
Comment #15
liam morlandThis version of the patch uses
$confas suggested in #13.Comment #16
liam morlandThis patch uses the existing
$base_pathinstead of having it be configurable. This is the approach used in language_cookie module in #2882384: Set cookie path to the root folder of Drupal installation.Comment #17
liam morlandComment #18
liam morlandThis is #16 with a better comment.
Comment #19
liam morlandComment #20
darren ohLiam, have you confirmed that this issue exists in Drupal 9?
Comment #21
liam morlandYes, I am observing this in Drupal 9.2.x. It can be fixed on a per-site basis by putting this in the site's
settings.php:Comment #25
ashish.dubey07 commentedRaised the same issue @https://www.drupal.org/project/drupal/issues/3268422.
Problem description :-
The application uses a cookie The path attribute is '/' as default which exposes Security Misconfiguration vulnerability
Enable the SECURE attribute to disallow the cookie to be sent over an unencrypted channel.
The 'path' attribute signifies the URL or path for which the cookie is valid. The proper scope of the ‘path’ attribute should be set. Example: If the application resides at /myapp/, then set to ""; path=/myapp/"" and NOT ""; path=/"".
Drupal version : 9.3.x
Attempted Solution :-:-
Tried with ini_set('session.cookie_path', '/' . '/site/path'); in settings.php but didn't work for me.
Help Required :-:-
Looking for a patch which can work for >=9.3 version.
Comment #27
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #30
prudloff commentedSome more explanation about why this would not be a security measure: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#security