Skip to content

Commit 8e66336

Browse files
committed
Backport 1.1 security fixes
1 parent 873c041 commit 8e66336

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

modules/backend/models/User.php

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class User extends UserBase
2727
public $rules = [
2828
'email' => 'required|between:6,255|email|unique:backend_users',
2929
'login' => 'required|between:2,255|unique:backend_users',
30-
'password' => 'required:create|between:4,255|confirmed',
31-
'password_confirmation' => 'required_with:password|between:4,255'
30+
'password' => 'required:create|min:4|confirmed',
31+
'password_confirmation' => 'required_with:password|min:4'
3232
];
3333

3434
/**
@@ -209,4 +209,66 @@ public function unsuspend()
209209
{
210210
BackendAuth::findThrottleByUserId($this->id)->unsuspend();
211211
}
212+
213+
//
214+
// Impersonation
215+
//
216+
217+
/**
218+
* Returns an array of merged permissions based on the user's individual permissions
219+
* and their group permissions filtering out any permissions the impersonator doesn't
220+
* have access to (if the current user is being impersonated)
221+
*
222+
* @return array
223+
*/
224+
public function getMergedPermissions()
225+
{
226+
if (!$this->mergedPermissions) {
227+
$permissions = parent::getMergedPermissions();
228+
229+
// If the user is being impersonated filter out any permissions the impersonator doesn't have access to already
230+
if (BackendAuth::isImpersonator()) {
231+
$impersonator = BackendAuth::getImpersonator();
232+
if ($impersonator && $impersonator !== $this) {
233+
foreach ($permissions as $i => $permission) {
234+
if (!$impersonator->hasAccess($permission)) {
235+
unset($permissions[$i]);
236+
}
237+
}
238+
$this->mergedPermissions = $permissions;
239+
}
240+
}
241+
}
242+
243+
return $this->mergedPermissions;
244+
}
245+
246+
/**
247+
* Check if this user can be impersonated by the provided impersonator
248+
* Super users cannot be impersonated and all users cannot be impersonated unless there is an impersonator
249+
* present and the impersonator has access to `backend.impersonate_users`, and the impersonator is not the
250+
* user being impersonated
251+
*
252+
* @param \Winter\Storm\Auth\Models\User|false $impersonator The user attempting to impersonate this user, false when not available
253+
* @return boolean
254+
*/
255+
public function canBeImpersonated($impersonator = false)
256+
{
257+
if (
258+
$this->isSuperUser() ||
259+
!$impersonator ||
260+
!($impersonator instanceof static) ||
261+
!$impersonator->hasAccess('backend.impersonate_users') ||
262+
$impersonator === $this
263+
) {
264+
return false;
265+
}
266+
267+
// Clear the merged permissions before the impersonation starts
268+
// so that they are correct even if they had been loaded prior
269+
// to the impersonation starting
270+
$this->mergedPermissions = null;
271+
272+
return true;
273+
}
212274
}

modules/cms/models/ThemeLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function add(HalcyonModel $template, $type = null)
8787
$record->content = $isDelete ? '' : $newContent;
8888
$record->old_content = $oldContent;
8989

90-
if ($user = BackendAuth::getUser()) {
90+
if ($user = BackendAuth::getRealUser()) {
9191
$record->user_id = $user->id;
9292
}
9393

0 commit comments

Comments
 (0)