Problem/Motivation

The toolbar subtrees use a hash to determine if access to the subtree should be allowed in ToolbarController::checkSubTreeAccess(). In certain situations the hash does not match, resulting in a JavaScript error and the subtrees not dynamically loading. Temporarily commenting out the hash check from ToolbarController::checkSubTreeAccess() makes the toggles appear again.

The toolbar module relies on _toolbar_get_subtrees_hash function to generate hash based on admin menu subtrees' length. This information is not same when you call it via `hook_toolbar` and via /toolbar/subtrees Ajax route. This difference is due to multiple reasons, few are:
1. If you are on admin pages, subtree uses stable template to generate html while Ajax uses toolbar module template
2. If there is a customization like adding destination to any of the link then hook_toolbar attaches current page url while Ajax attaches /toolbar/subtrees as destination

Steps to reproduce

  1. Set the admin menu in vertical mode.
  2. Make sure to have a site with 2 languages.
  3. Enable the Account administration pages on Language negotiation > Detection and selection.
  4. Set the default language to something non-english.
  5. Set an admin language in your user profile other than the default site language (e.g. english).
  6. Go to a content page in your content language.
  7. Refresh the cache (I did this from the content page with devel module).
  8. Navigate to an admin page.
  9. Observe that the toolbar submenu toggles (blue arrows) are not shown and there is a JavaScript error.

Proposed resolution

The hash is calculated from the rendered subtrees, but if the rendered content changes, the hash no longer matches with the sent one and the access check fails.

Proposed solution is to use $hash = Crypt::hashBase64(serialize(array_keys($subtrees))); instead of $hash = Crypt::hashBase64(serialize($subtrees));. So that the hash is based on structure, rather than content.

Remaining tasks

  1. Understand the purpose of the hash(?). Is it related to CSRF, MITM, permissions?
  2. Agree on an alternative hash input.

User interface changes

Hopefully none

API changes

Probably none

Data model changes

Release notes snippet

Issue fork drupal-3130197

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ash2303 created an issue. See original summary.

ash2303’s picture

Issue summary: View changes
ash2303’s picture

StatusFileSize
new553 bytes
longwave’s picture

Status: Active » Needs review

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

scottatdrake’s picture

StatusFileSize
new534 bytes

Rerolled patch against 9.4.x

Status: Needs review » Needs work

The last submitted patch, 9: 3130197-9.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

zeeshan_khan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.45 KB

This one fixes the problem for me.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

Will need test coverage showing the problem.

Issue summary is also incomplete, recommend using the standard issue template

neograph734’s picture

Title: Faulty Toolbar Subtree Hash » Faulty toolbar subtree hash breaks asynchonous loading of admin menu content
Issue summary: View changes

I have updated the IS and merged it with the content of #3402656: Toolbar causes a Javascript error if the subtrees content changes between page loads.

The patch from #2 and #9 does not appear to work. It makes the issue go away, but when a new module is installed, the menu does not update and the new links don't become visible. So the hash might be too generic(?).

The patch from #13 does not appear to do anything. The toggles are still missing and the error is still shown?

Should we perhaps try hasing the raw menu tree structure or something instead?

neograph734’s picture

Issue summary: View changes
matthiasm11’s picture

Combining the patches from #9 to generate the hash and #13 to fix the caching seems to fix the issue.
Disabling a module makes the corresponding menu item disappear, enabling the module again makes it appear again.
No console errors anymore. I've not investigated this any further.

milos.kroulik’s picture

I can confirm observations made in #17. So I'm going to create a combined patch.

ericdsd’s picture

Hi milos.kroulik, did you create a combine patch for it yet ?

Note i'm still experiencing it on core 10.3.11.

sleitner made their first commit to this issue’s fork.

sleitner changed the visibility of the branch 11.x to hidden.

sleitner’s picture

ToolbarAdminMenuTest test still needs to be updated

anairamzap’s picture

I've created a patch that merges the ones in #9 and #13 based on core 10.3.x

Leaving this as "Needs work" since a test update is still missing

frontmobe’s picture

Thanks @anairamzap, I can confirm that your patch also cleanly applies to Drupal 10.4.3.

carlos romero made their first commit to this issue’s fork.

carlos romero’s picture

Status: Needs work » Needs review
carlos romero’s picture

Hi, I've forked, applied the change to the 10.4.x branch, and submitted the PR.

Best regards.

smustgrave’s picture

Status: Needs review » Needs work

Have not reviewed but changes need to be against 11.x as that’s the development branch

tinto changed the visibility of the branch 11.x to active.

tinto changed the visibility of the branch 11.x to hidden.

tinto’s picture

Status: Needs work » Needs review
Issue tags: +ddd2025

Rebased to 11.x

Greetings from the contrib room at Drupal Developer Days 2025 in Leuven, Belgium.

smustgrave’s picture

Status: Needs review » Needs work

Hello!

New parameter probably should be typehinted and parameter doc added

Also will most likely need test coverage

sleitner’s picture

The MR doesn't fix the problem when installing/uninstalling modules which only add a sub menu item e.g. "User interface translation" for locale module.

The keys of the array do not change, so the hash does not change either. Maybe the installed modules list should be in in the hash input, too?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Needs work » Postponed

The Toolbar Module was approved for removal in #3476882: [Policy] Move Toolbar module to contrib.

This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

The deprecation work is in #3484850: [meta] Tasks to deprecate Toolbar module and the removal work in #3488828: [meta] Tasks to remove Toolbar module.

Toolbar will be moved to a contributed project before Drupal 12.0.0 is released.