Problem/Motivation

As a security hardening measure, the SessionHandler hashes the session id before storing it into the database. SessionCacheContext should do the same.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Issue priority Major
Prioritized changes The main goal of this issue is security hardening

Comments

znerol created an issue. See original summary.

znerol’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes

Status: Needs review » Needs work

The last submitted patch, 2: hash_session_id_before-2575829-2.patch, failed testing.

znerol’s picture

Status: Needs work » Needs review
StatusFileSize
new787 bytes

0 bytes patch :/

berdir’s picture

Should we write a unit test for this? Can we?

znerol’s picture

Interdiff is test-only patch.

The last submitted patch, 6: hash_session_id_before-2575829-6-TEST-ONLY.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 6: hash_session_id_before-2575829-6.patch, failed testing.

The last submitted patch, 6: hash_session_id_before-2575829-6-TEST-ONLY.patch, failed testing.

The last submitted patch, 6: hash_session_id_before-2575829-6.patch, failed testing.

znerol’s picture

Status: Needs work » Needs review
StatusFileSize
new2.92 KB
new3.69 KB
new530 bytes

The last submitted patch, 11: hash_session_id_before-2575829-11-TEST-ONLY.patch, failed testing.

The last submitted patch, 11: hash_session_id_before-2575829-11-TEST-ONLY.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Needs review » Reviewed & tested by the community
Issue tags: +D8 cacheability

This looks great!

+++ b/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php
@@ -0,0 +1,90 @@
+    $this->assertSame(FALSE, strpos($context1, $session_id), 'Session ID not contained in cache context');
...
+    $this->assertSame(FALSE, strpos($context1, $session1_id), 'Session ID not contained in cache context');
+    $this->assertSame(FALSE, strpos($context2, $session2_id), 'Session ID not contained in cache context');

Nit: should use assertFalse().

wim leers’s picture

Category: Bug report » Task
Issue tags: -Security +Security improvements

However, this is a task, not a bug. Everything works fine, this is just security hardening, which is an improvement.

znerol’s picture

Nit: should use assertFalse().

Nope, that would be wrong. We need strict comparison in combination with strpos.

wim leers’s picture

You're right. Man I hate our incredibly confusing assertion function names. They so often don't do what you expect.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed c3b3ec1 and pushed to 8.3.x. Thanks!

diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php
index 978c753..b621b2d 100644
--- a/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php
+++ b/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php
@@ -1,10 +1,5 @@
 <?php
 
-/**
- * @file
- * Contains \Drupal\Tests\Core\Cache\Context\SessionCacheContextTest
- */
-
 namespace Drupal\Tests\Core\Cache\Context;
 
 use Drupal\Core\Cache\Context\SessionCacheContext;

Fixed on commit.

  • alexpott committed c3b3ec1 on 8.3.x
    Issue #2575829 by znerol: Hash session id before using it as a cache...
alexpott’s picture

Category: Task » Bug report

After discussing with @catch we decided to backport this as bugfix to 8.2.x since it is "not working as well as it could". Committed 9025843 and pushed to 8.2.x. Thanks!

  • alexpott committed 9025843 on 8.2.x
    Issue #2575829 by znerol: Hash session id before using it as a cache...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.