Skip to content

Commit d592188

Browse files
committed
Avoid possible length extension attack.
See https://www.drupal.org/project/drupalauth4ssp/issues/3020308
1 parent 65f9291 commit d592188

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/Auth/Source/External.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SimpleSAML\Module\drupalauth\Auth\Source;
44

5+
use Drupal\Component\Utility\Crypt;
56
use Drupal\user\Entity\User;
67
use SimpleSAML\Auth\Source;
78
use SimpleSAML\Auth\State;
@@ -122,14 +123,17 @@ private function getUser()
122123
$cookie_name = $this->config->getCookieName();
123124
if (isset($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name]) {
124125
$strCookie = $_COOKIE[$cookie_name];
125-
list($hash, $uid) = explode(':', $strCookie);
126+
list($cookie_hash, $uid) = explode(':', $strCookie);
126127

127128
// make sure the hash matches
128129
// make sure the UID is passed
129-
if ((isset($hash) && !empty($hash)) && (isset($uid) && !empty($uid))) {
130+
if ((isset($cookie_hash) && !empty($cookie_hash)) && (isset($uid) && !empty($uid))) {
130131
// Make sure no one manipulated the hash or the uid in the cookie before we trust the uid
131-
$cookie_salt = $this->config->getCookieSalt();
132-
if (sha1($cookie_salt . $uid) !== $hash) {
132+
$hash = Crypt::hmacBase64(
133+
$account->id(),
134+
$this->config->getCookieSalt() . \Drupal::service('private_key')->get()
135+
);
136+
if (!Crypt::hashEquals($hash, $cookie_hash)) {
133137
throw new Exception(
134138
'Cookie hash invalid. This indicates either tampering or an out of date drupal4ssp module.'
135139
);

0 commit comments

Comments
 (0)