Skip to content

Commit 1e145d5

Browse files
committed
Fixing ACL checks for delete-attachment endpoint to verify the selected file belongs to the selected exercise.
1 parent fdbd4d3 commit 1e145d5

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

app/V1Module/presenters/ExerciseFilesPresenter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Helpers\MetaFormats\Validators\VMixed;
88
use App\Helpers\MetaFormats\Validators\VString;
99
use App\Helpers\MetaFormats\Validators\VUuid;
10+
use App\Exceptions\BadRequestException;
1011
use App\Exceptions\ForbiddenRequestException;
1112
use App\Exceptions\InvalidApiArgumentException;
1213
use App\Exceptions\NotFoundException;
@@ -330,6 +331,10 @@ public function actionGetAttachmentFiles(string $id)
330331
public function checkDeleteAttachmentFile(string $id, string $fileId)
331332
{
332333
$exercise = $this->exercises->findOrThrow($id);
334+
$file = $this->attachmentFiles->findOrThrow($fileId);
335+
if (!$file->getExercises()->contains($exercise)) {
336+
throw new BadRequestException("Selected file is not an attachment file for given exercise.");
337+
}
333338
if (!$this->exerciseAcl->canUpdate($exercise)) {
334339
throw new ForbiddenRequestException("You cannot delete attachment files for this exercise.");
335340
}

0 commit comments

Comments
 (0)