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,20 @@ 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 ))) {
131
+ $ drupalHelper = new DrupalHelper ();
132
+ $ drupalHelper ->bootDrupal ($ this ->config ->getDrupalroot ());
133
+
130
134
// 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 ) {
135
+ $ hash = Crypt::hmacBase64 (
136
+ $ uid ,
137
+ $ this ->config ->getCookieSalt () . \Drupal::service ('private_key ' )->get ()
138
+ );
139
+ if (!Crypt::hashEquals ($ hash , $ cookie_hash )) {
133
140
throw new Exception (
134
141
'Cookie hash invalid. This indicates either tampering or an out of date drupal4ssp module. '
135
142
);
@@ -145,9 +152,6 @@ private function getUser()
145
152
}
146
153
147
154
if (!empty ($ drupaluid )) {
148
- $ drupalHelper = new DrupalHelper ();
149
- $ drupalHelper ->bootDrupal ($ this ->config ->getDrupalroot ());
150
-
151
155
// Load the user object from Drupal.
152
156
$ drupaluser = User::load ($ uid );
153
157
if ($ drupaluser ->isBlocked ()) {
0 commit comments