|
2 | 2 |
|
3 | 3 | namespace SimpleSAML\Module\drupalauth\Auth\Source; |
4 | 4 |
|
| 5 | +use Drupal\Component\Utility\Crypt; |
5 | 6 | use Drupal\user\Entity\User; |
6 | 7 | use SimpleSAML\Auth\Source; |
7 | 8 | use SimpleSAML\Auth\State; |
@@ -122,14 +123,17 @@ private function getUser() |
122 | 123 | $cookie_name = $this->config->getCookieName(); |
123 | 124 | if (isset($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name]) { |
124 | 125 | $strCookie = $_COOKIE[$cookie_name]; |
125 | | - list($hash, $uid) = explode(':', $strCookie); |
| 126 | + list($cookie_hash, $uid) = explode(':', $strCookie); |
126 | 127 |
|
127 | 128 | // make sure the hash matches |
128 | 129 | // 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))) { |
130 | 131 | // 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)) { |
133 | 137 | throw new Exception( |
134 | 138 | 'Cookie hash invalid. This indicates either tampering or an out of date drupal4ssp module.' |
135 | 139 | ); |
|
0 commit comments