Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden update restrictions #750

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,20 @@ public function updateForm(int $id, array $keyValuePairs): DataResponse {
throw new OCSForbiddenException();
}

// Make sure we only store id
// Don't allow empty array
if (sizeof($keyValuePairs) === 0) {
$this->logger->info('Empty keyValuePairs, will not update.');
throw new OCSForbiddenException();
}

// Don't allow to change params id, hash, ownerId, created
if (key_exists('id', $keyValuePairs) || key_exists('hash', $keyValuePairs) ||
key_exists('ownerId', $keyValuePairs) || key_exists('created', $keyValuePairs)) {
$this->logger->info('Not allowed to update id, hash, ownerId or created');
throw new OCSForbiddenException();
}

// Make sure we only store id of shares
try {
if (array_key_exists('access', $keyValuePairs)) {
$keyValuePairs['access']['users'] = array_map(function (array $user): string {
Expand Down Expand Up @@ -496,7 +509,20 @@ public function updateQuestion(int $id, array $keyValuePairs): DataResponse {
throw new OCSForbiddenException();
}

if (array_key_exists('order', $keyValuePairs)) {
// Don't allow empty array
if (sizeof($keyValuePairs) === 0) {
$this->logger->info('Empty keyValuePairs, will not update.');
throw new OCSForbiddenException();
}

//Don't allow to change id or formId
if (key_exists('id', $keyValuePairs) || key_exists('formId', $keyValuePairs)) {
$this->logger->debug('Not allowed to update id or formId');
throw new OCSForbiddenException();
}

// Don't allow to reorder here
if (key_exists('order', $keyValuePairs)) {
$this->logger->debug('Key \'order\' is not allowed on updateQuestion. Please use reorderQuestions() to change order.');
throw new OCSForbiddenException('Please use reorderQuestions() to change order');
}
Expand Down Expand Up @@ -632,6 +658,18 @@ public function updateOption(int $id, array $keyValuePairs): DataResponse {
throw new OCSForbiddenException();
}

// Don't allow empty array
if (sizeof($keyValuePairs) === 0) {
$this->logger->info('Empty keyValuePairs, will not update.');
throw new OCSForbiddenException();
}

//Don't allow to change id or questionId
if (key_exists('id', $keyValuePairs) || key_exists('questionId', $keyValuePairs)) {
$this->logger->debug('Not allowed to update id or questionId');
throw new OCSForbiddenException();
}

// Create OptionEntity with given Params & Id.
$option = Option::fromParams($keyValuePairs);
$option->setId($id);
Expand Down