Skip to content

Commit 0f7e893

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

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
@@ -465,6 +465,28 @@ public function testExportSubmissionsToCloud_invalidForm() {
465465
$this->apiController->exportSubmissionsToCloud(1, '');
466466
}
467467

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

0 commit comments

Comments
 (0)