Skip to content

Commit e3eb311

Browse files
committed
fix(api): re-check result permission in submission export
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent 3a78bee commit e3eb311

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/Controller/ApiController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,14 @@ public function deleteSubmission(int $formId, int $submissionId): DataResponse {
16131613
#[ApiRoute(verb: 'POST', url: '/api/v3/forms/{formId}/submissions/export')]
16141614
public function exportSubmissionsToCloud(int $formId, string $path, string $fileFormat = Constants::DEFAULT_FILE_FORMAT) {
16151615
$form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS);
1616+
1617+
// canSeeResults() (used by getFormIfAllowed) also accepts submitters;
1618+
// exporting every submission needs the strict PERMISSION_RESULTS grant.
1619+
$permissions = $this->formsService->getPermissions($form);
1620+
if (!in_array(Constants::PERMISSION_RESULTS, $permissions, true)) {
1621+
throw new OCSForbiddenException('The current user has no permission to get the results for this form');
1622+
}
1623+
16161624
$file = $this->submissionService->writeFileToCloud($form, $path, $fileFormat);
16171625

16181626
return new DataResponse($file->getName());

tests/Unit/Controller/ApiControllerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,28 @@ public function testExportSubmissionsToCloud_invalidForm() {
469469
$this->apiController->exportSubmissionsToCloud(1, '');
470470
}
471471

472+
public function testExportSubmissionsToCloud_noExportPermissions() {
473+
$form = new Form();
474+
$form->setId(1);
475+
$form->setOwnerId('someoneElse');
476+
477+
$this->formsService->expects($this->once())
478+
->method('getFormIfAllowed')
479+
->with(1, Constants::PERMISSION_RESULTS)
480+
->willReturn($form);
481+
482+
$this->formsService->expects($this->once())
483+
->method('getPermissions')
484+
->with($form)
485+
->willReturn([Constants::PERMISSION_SUBMIT]);
486+
487+
$this->submissionService->expects($this->never())
488+
->method('writeFileToCloud');
489+
490+
$this->expectException(OCSForbiddenException::class);
491+
$this->apiController->exportSubmissionsToCloud(1, '/', 'csv');
492+
}
493+
472494
public function testCreateNewForm_notAllowed() {
473495
$this->configService->expects($this->once())
474496
->method('canCreateForms')

0 commit comments

Comments
 (0)