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)

Comments

bart jansens’s picture

Title: Cookie Path needs to reflect drupal path (security issue that people are NOT understanding) » Cookie Path needs to reflect drupal path
Version: 6.2 » 7.x-dev

Re-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.

dx9s’s picture

Yes 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)

lilou’s picture

Status: Active » Needs work

Patch no longer applies.

valthebald’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
Issue tags: +Needs backport to D7
StatusFileSize
new4.26 KB

Status: Needs review » Needs work
Issue tags: -Needs backport to D7

The last submitted patch, session-cookie-path-289145.patch, failed testing.

Joe.U.Questionmark’s picture

Status: Needs work » Needs review
Issue tags: -Needs backport to D7

#4: session-cookie-path-289145.patch queued for re-testing.

Issue tags: +Needs backport to D7

The last submitted patch, session-cookie-path-289145.patch, failed testing.

Joe.U.Questionmark’s picture

Version: 8.x-dev » 7.23
Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: +Needs backport to D7

This could be a major security issue. Is there any reason why this hasn't been integrated into core?

a.ross’s picture

Because setting the path offers little to no security.

rob230’s picture

Issue summary: View changes

It 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.

a.ross’s picture

Yes, 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".

gapple’s picture

Version: 7.23 » 7.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.82 KB

As I understand the code, multiple sites across root and subdirectories should not conflict if $cookie_domain is 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_domain is 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.

joelpittet’s picture

What about adding that into $conf instead of including another global variable?

liam morland’s picture

StatusFileSize
new2.77 KB

Re-roll.

liam morland’s picture

Title: Cookie Path needs to reflect drupal path » Allow path for Drupal cookies to be configured
StatusFileSize
new1.93 KB

This version of the patch uses $conf as suggested in #13.

liam morland’s picture

StatusFileSize
new1.13 KB

This patch uses the existing $base_path instead 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.

liam morland’s picture

Issue summary: View changes
liam morland’s picture

StatusFileSize
new1.11 KB

This is #16 with a better comment.

liam morland’s picture

Title: Allow path for Drupal cookies to be configured » Allow cookie_path for session cookies to be configured
Version: 7.x-dev » 9.2.x-dev
Category: Task » Feature request
darren oh’s picture

Liam, have you confirmed that this issue exists in Drupal 9?

liam morland’s picture

Yes, 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:

ini_set('session.cookie_path', '/' . '/site/path');

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ashish.dubey07’s picture

Raised 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.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new165 bytes

The 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

prudloff’s picture

Some more explanation about why this would not be a security measure: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#security