Fix leak of private information when updating users

This commit is contained in:
Toby Zerner 2018-11-09 21:21:21 +10:30
parent c6aeeeb3c1
commit 0536b208e1

View File

@ -11,6 +11,8 @@
namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Core\Command\EditUser;
use Flarum\Core\Exception\PermissionDeniedException;
use Illuminate\Contracts\Bus\Dispatcher;
@ -22,7 +24,7 @@ class UpdateUserController extends AbstractResourceController
/**
* {@inheritdoc}
*/
public $serializer = 'Flarum\Api\Serializer\CurrentUserSerializer';
public $serializer = UserSerializer::class;
/**
* {@inheritdoc}
@ -51,6 +53,10 @@ class UpdateUserController extends AbstractResourceController
$actor = $request->getAttribute('actor');
$data = array_get($request->getParsedBody(), 'data', []);
if ($actor->id == $id) {
$this->serializer = CurrentUserSerializer::class;
}
// Require the user's current password if they are attempting to change
// their own email address.
if (isset($data['attributes']['email']) && $actor->id == $id) {