Skip to content

Commit

Permalink
#7371 Add missing CSRF check (save reordered items)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Oct 19, 2021
1 parent 3018049 commit 169885a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions classes/controllers/grid/GridHandler.inc.php
Expand Up @@ -857,6 +857,9 @@ public function fetchCell(&$args, $request)
*/
public function saveSequence($args, $request)
{
if (!$request->checkCSRF()) {
throw new \Exception('CSRF mismatch!');
}
$this->callFeaturesHook('saveSequence', ['request' => &$request, 'grid' => &$this]);

return \PKP\db\DAO::getDataChangedEvent();
Expand Down
3 changes: 2 additions & 1 deletion classes/controllers/grid/feature/OrderItemsFeature.inc.php
Expand Up @@ -111,7 +111,8 @@ public function setOptions($request, $grid)

$router = $request->getRouter();
$this->addOptions([
'saveItemsSequenceUrl' => $router->url($request, null, null, 'saveSequence', null, $grid->getRequestArgs())
'saveItemsSequenceUrl' => $router->url($request, null, null, 'saveSequence', null, $grid->getRequestArgs()),
'csrfToken' => $request->getSession()->getCsrfToken(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion js/classes/features/OrderGridItemsFeature.js
Expand Up @@ -56,7 +56,7 @@
stringifiedData = JSON.stringify(this.getItemsDataId());
saveOrderCallback = this.callbackWrapper(
this.saveOrderResponseHandler_, this);
$.post(options.saveItemsSequenceUrl, {data: stringifiedData},
$.post(options.saveItemsSequenceUrl, {data: stringifiedData, csrfToken: options.csrfToken},
saveOrderCallback, 'json');

return false;
Expand Down

0 comments on commit 169885a

Please sign in to comment.