Skip to content

Commit fc5cf63

Browse files
authored
Merge pull request #3426 from nextcloud/fix/disallow-update-accessEnum
fix: disallow update accessEnum directly
2 parents c898a20 + 0defa9c commit fc5cf63

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

lib/Controller/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ private function storeAnswersForQuestion(Form $form, $submissionId, array $quest
18751875
*/
18761876
private function checkForbiddenKeys(array $keyValuePairs): void {
18771877
$forbiddenKeys = [
1878-
'id', 'hash', 'ownerId', 'created', 'lastUpdated', 'lockedBy', 'lockedUntil'
1878+
'id', 'hash', 'ownerId', 'created', 'lastUpdated', 'lockedBy', 'lockedUntil', 'accessEnum'
18791879
];
18801880
foreach ($forbiddenKeys as $key) {
18811881
if (array_key_exists($key, $keyValuePairs)) {

tests/Integration/Api/ApiV3Test.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,24 @@ public function testUpdateFormProperties(array $expected): void {
701701
$this->testGetFullForm($expected);
702702
}
703703

704+
public function testUpdateFormRejectsForbiddenKeys(): void {
705+
$before = $this->OcsResponse2Data($this->http->request('GET', "api/v3/forms/{$this->testForms[0]['id']}"));
706+
707+
$resp = $this->http->request('PATCH', "api/v3/forms/{$this->testForms[0]['id']}", [
708+
'json' => [
709+
'keyValuePairs' => [
710+
'id' => 999,
711+
],
712+
],
713+
'http_errors' => false,
714+
]);
715+
716+
$this->assertEquals(403, $resp->getStatusCode());
717+
718+
$after = $this->OcsResponse2Data($this->http->request('GET', "api/v3/forms/{$this->testForms[0]['id']}"));
719+
$this->assertEquals($before, $after);
720+
}
721+
704722
public function testDeleteForm() {
705723
$resp = $this->http->request('DELETE', "api/v3/forms/{$this->testForms[0]['id']}");
706724
$data = $this->OcsResponse2Data($resp);

tests/Unit/Controller/ApiControllerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,38 @@ public function testUpdateFormAllowsValidConfirmationEmailQuestionId(): void {
11741174
$this->assertSame(7, $form->getConfirmationEmailQuestionId());
11751175
}
11761176

1177+
public static function dataUpdateFormRejectsForbiddenKeys(): array {
1178+
return [
1179+
'id' => [['id' => 2]],
1180+
'hash' => [['hash' => 'new-hash']],
1181+
'created' => [['created' => 123456]],
1182+
'lastUpdated' => [['lastUpdated' => 123456]],
1183+
'lockedBy' => [['lockedBy' => 'anotherUser']],
1184+
'lockedUntil' => [['lockedUntil' => 123456]],
1185+
'accessEnum' => [['accessEnum' => 2]],
1186+
];
1187+
}
1188+
1189+
/**
1190+
* @dataProvider dataUpdateFormRejectsForbiddenKeys
1191+
*/
1192+
public function testUpdateFormRejectsForbiddenKeys(array $keyValuePairs): void {
1193+
$form = new Form();
1194+
$form->setId(1);
1195+
$form->setOwnerId('currentUser');
1196+
$form->setHash('hash');
1197+
1198+
$this->formsService
1199+
->method('getFormIfAllowed')
1200+
->with(1, Constants::PERMISSION_EDIT)
1201+
->willReturn($form);
1202+
1203+
$this->formMapper->expects($this->never())->method('update');
1204+
1205+
$this->expectException(OCSForbiddenException::class);
1206+
$this->apiController->updateForm(1, $keyValuePairs);
1207+
}
1208+
11771209
public static function dataUpdateFormRejectsInvalidConfirmationEmailQuestionId(): array {
11781210
return [
11791211
'invalid-question-id' => ['Invalid question ID'],

0 commit comments

Comments
 (0)