Skip to content
Snippets Groups Projects
Commit aa8c20b2 authored by Carlos Romero's avatar Carlos Romero
Browse files

Validate toolbar subtrees hash in AJAX responses

parent 73fbc455
No related branches found
No related tags found
1 merge request!11753Validate toolbar subtrees hash in AJAX responses
......@@ -37,10 +37,13 @@ public function __construct(
*
* @return \Drupal\Core\Ajax\AjaxResponse
*/
public function subtreesAjax() {
public function subtreesAjax($hash) {
[$subtrees] = toolbar_get_rendered_subtrees();
$expected_hash = _toolbar_get_subtrees_hash()[0];
$response = new AjaxResponse();
if (hash_equals($expected_hash, $hash)) {
$response->addCommand(new SetSubtreesCommand($subtrees));
}
// The Expires HTTP header is the heart of the client-side HTTP caching. The
// additional server-side page cache only takes effect when the client
......@@ -67,8 +70,7 @@ public function subtreesAjax() {
* The access result.
*/
public function checkSubTreeAccess($hash) {
$expected_hash = _toolbar_get_subtrees_hash()[0];
return AccessResult::allowedIf($this->currentUser()->hasPermission('access toolbar') && hash_equals($expected_hash, $hash))->cachePerPermissions();
return AccessResult::allowedIf($this->currentUser()->hasPermission('access toolbar'))->cachePerPermissions();
}
/**
......
......
......@@ -293,6 +293,6 @@ function toolbar_get_rendered_subtrees() {
*/
function _toolbar_get_subtrees_hash() {
[$subtrees, $cacheability] = toolbar_get_rendered_subtrees();
$hash = Crypt::hashBase64(serialize($subtrees));
$hash = Crypt::hashBase64(serialize(array_keys($subtrees)));
return [$hash, $cacheability];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment