Skip to content

Commit

Permalink
fix(1.x,suspend): suspended users can abuse avatar upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Sep 20, 2023
1 parent e03ca44 commit a5ed6a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions extensions/suspend/src/Access/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ public function suspend(User $actor, User $user)
return $this->deny();
}
}

public function uploadAvatar(User $actor, User $user)
{
if ($actor->suspended_until && $actor->suspended_until->isFuture()) {
return $this->deny();
}
}
}
11 changes: 11 additions & 0 deletions framework/core/src/User/Access/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,15 @@ public function editCredentials(User $actor, User $user)
return $this->allow();
}
}

public function uploadAvatar(User $actor, User $user)
{
if ($actor->id === $user->id) {
return $this->allow();
}

if ($actor->id !== $user->id) {
return $actor->can('edit', $user);
}
}
}
4 changes: 1 addition & 3 deletions framework/core/src/User/Command/UploadAvatarHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public function handle(UploadAvatar $command)

$user = $this->users->findOrFail($command->userId);

if ($actor->id !== $user->id) {
$actor->assertCan('edit', $user);
}
$actor->assertCan('uploadAvatar', $user);

$this->validator->assertValid(['avatar' => $command->file]);

Expand Down

0 comments on commit a5ed6a8

Please sign in to comment.