Skip to content

Commit

Permalink
fix: deleting images does not have any permission checks
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Jul 29, 2024
1 parent 2a6e199 commit d946f77
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Api/Controllers/DeletePollImageByNameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Flarum\Http\RequestUtil;
use FoF\Polls\Events\PollImageDeleting;
use FoF\Polls\Poll;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
Expand All @@ -26,6 +27,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$actor = RequestUtil::getActor($request);
$fileName = Arr::get($request->getQueryParams(), 'fileName');

$actor->assertCan('edit', new Poll());

if ($this->uploadDir->exists($fileName)) {
$this->events->dispatch(
new PollImageDeleting($fileName, $actor)
Expand Down
2 changes: 2 additions & 0 deletions src/Api/Controllers/DeletePollImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
/** @var Poll $poll */
$poll = Poll::find($pollId);

$actor->assertCan('edit', $poll);

$this->events->dispatch(
new PollImageDeleting($poll->image, $actor)
);
Expand Down
2 changes: 2 additions & 0 deletions src/Api/Controllers/DeletePollOptionImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
/** @var PollOption $option */
$option = PollOption::find($optionId);

$actor->assertCan('edit', $option->poll);

// if the image_url is a fully qualified URL, we just set it to null
if (filter_var($option->image_url, FILTER_VALIDATE_URL)) {
} else {
Expand Down

0 comments on commit d946f77

Please sign in to comment.