Skip to content

Commit 8b172e8

Browse files
pringelmannbackportbot[bot]
authored andcommitted
fix(api): re-check result permission in submission export
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent fdcaff7 commit 8b172e8

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
@@ -1569,6 +1569,14 @@ public function deleteSubmission(int $formId, int $submissionId): DataResponse {
15691569
#[ApiRoute(verb: 'POST', url: '/api/v3/forms/{formId}/submissions/export')]
15701570
public function exportSubmissionsToCloud(int $formId, string $path, string $fileFormat = Constants::DEFAULT_FILE_FORMAT) {
15711571
$form = $this->formsService->getFormIfAllowed($formId, Constants::PERMISSION_RESULTS);
1572+
1573+
// canSeeResults() (used by getFormIfAllowed) also accepts submitters;
1574+
// exporting every submission needs the strict PERMISSION_RESULTS grant.
1575+
$permissions = $this->formsService->getPermissions($form);
1576+
if (!in_array(Constants::PERMISSION_RESULTS, $permissions, true)) {
1577+
throw new OCSForbiddenException('The current user has no permission to get the results for this form');
1578+
}
1579+
15721580
$file = $this->submissionService->writeFileToCloud($form, $path, $fileFormat);
15731581

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

tests/Unit/Controller/ApiControllerTest.php

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

485+
public function testExportSubmissionsToCloud_noExportPermissions() {
486+
$form = new Form();
487+
$form->setId(1);
488+
$form->setOwnerId('someoneElse');
489+
490+
$this->formsService->expects($this->once())
491+
->method('getFormIfAllowed')
492+
->with(1, Constants::PERMISSION_RESULTS)
493+
->willReturn($form);
494+
495+
$this->formsService->expects($this->once())
496+
->method('getPermissions')
497+
->with($form)
498+
->willReturn([Constants::PERMISSION_SUBMIT]);
499+
500+
$this->submissionService->expects($this->never())
501+
->method('writeFileToCloud');
502+
503+
$this->expectException(OCSForbiddenException::class);
504+
$this->apiController->exportSubmissionsToCloud(1, '/', 'csv');
505+
}
506+
485507
public function testCreateNewForm_notAllowed() {
486508
$this->configService->expects($this->once())
487509
->method('canCreateForms')

0 commit comments

Comments
 (0)