This issue affects only version 3.1.2 of the menu_item_extras module. Authenticated users on affected sites can access cached menu content that belongs to other users. Treat this as a security-sensitive regression and apply the workaround as soon as possible.
Version 3.1.2 of the menu_item_extras Drupal contributed module introduced a defective render array caching layer in MenuLinkTreeHandler::getMenuLinkItemContent(). This regression causes two distinct bugs: a PHP serialization fatal error that prevents the system from writing the menu cache, and cross-user cache reuse caused by missing theme and user.permissions cache contexts. Neither bug existed in version 3.1.1.
Sites affected by this regression typically display one or more of the following symptoms:
drush cr restores them temporarily, but the problem returns after a short time.menu_item_extras or MenuLinkTreeHandler.| Module | Affected Version | Safe Version |
|---|---|---|
| drupal/menu_item_extras | 3.1.2 | 3.1.1 (or a future 3.1.3+ release when available) |
The 3.1.2 release added a render array caching layer to MenuLinkTreeHandler::getMenuLinkItemContent(). This implementation contains the following two bugs:
PHP Fatal error: Serialization of ... is not allowed. In some cache backend configurations this failure is caught silently, causing every menu cache write to fail without a visible error in the browser.#cache definition on the render array omits the theme and user.permissions cache contexts. As a result, the system can retrieve and serve a cached menu entry that was created for one user or active theme to a different user with different permissions or to a request that uses a different theme, without triggering a cache miss or a rebuildTo confirm that this issue causes menu problems on your site, complete the following steps
Run either of the following commands and confirm the output displays version 3.1.2.
drush pm:list --filter=menu_item_extrascomposer show drupal/menu_item_extrasIf the installed version is not 3.1.2, this issue is not the cause of the problem. Proceed with other cache debugging resources listed under Related Resources.
Run the following command to check whether a menu link entry exists in the cache_menu bin. Replace 1 with the numeric ID of a known menu link content entity on your site. It is visible in the URL when editing the menu link at Structure > Menus.
drush php:eval "
\$mid = 1;
\$menu_link = \Drupal::entityTypeManager()
->getStorage('menu_link_content')
->load(\$mid);
if (!\$menu_link) {
print 'Menu link entity not found in DB. Check the ID.' . PHP_EOL;
} else {
print 'DB entity found: ' . \$menu_link->getTitle() . PHP_EOL;
\$cid = 'menu_link_content:' . \$menu_link->uuid();
\$cache = \Drupal::cache('menu')->get(\$cid);
if (\$cache) {
print 'Cache entry EXISTS for CID: ' . \$cid . PHP_EOL;
print 'Tags: ' . implode(', ', \$cache->tags) . PHP_EOL;
} else {
print 'NO cache entry found for CID: ' . \$cid . PHP_EOL;
print 'Confirmed: DB entry is intact but cache entry is missing.' . PHP_EOL;
}
}
"
If the database entity is found but no corresponding cache entry exists, this confirms the serialization fatal is preventing the cache write.
If a cache entry does exist, examine its tags output. If neither theme nor user.permissions context values appear in the entry's cache ID or tags, the missing cache contexts bug is present.
Run the following command to invalidate all cache entries tagged to the main and footer menus and force a rebuild on the next request. Adjust the menu names to match the menus on your site.
drush php:eval "
use Drupal\Core\Cache\Cache;
\$tags = [
'config:system.menu.main',
'config:system.menu.footer',
'config:system.menu.account',
];
Cache::invalidateTags(\$tags);
print 'Cache tags invalidated for: ' . implode(', ', \$tags) . PHP_EOL;
print 'Menus will rebuild on the next page request.' . PHP_EOL;
"
After you run this command, if menus display temporarily and then disappear within a few page requests, the serialization fatal error prevents stable cache writes
Search the PHP error log for fatal errors related to menu_item_extras. On Cloud Platform, PHP error logs are located at /var/log/php/php-errors.log. Run the following command from an SSH session:
grep -i "serialize\|MenuLinkTreeHandler\|menu_item_extras" /var/log/php/php-errors.log | tail -50Entries resembling the following confirm the serialization fatal:
PHP Fatal error: Uncaught Exception: Serialization of
'Drupal\menu_item_extras\MenuLinkTreeHandler' is not allowed
in .../core/lib/Drupal/Core/Cache/DatabaseBackend.php on line ...If the site uses Memcache as the cache backend, a high eviction rate on the cache_menu slab can indicate that menu cache writes are failing or producing large objects that are immediately evicted.
Access the Memcache statistics page at /admin/reports/memcache in the Drupal admin UI. Compare the ratio of evictions to total get_hits. A high eviction rate specifically on menu-related slabs is consistent with the serialization failure in this bug.
For additional Memcache diagnostics, refer to Memcache monitoring and flush using the nc command and Tuning your Memcached settings.
This workaround pins the module to version 3.1.1. Confirm that version 3.1.1 is compatible with the site's installed version of Drupal core before proceeding. You can verify compatibility at drupal.org/project/menu_item_extras.
composer.json file at the root of the Drupal project.Locate the require section and update the version constraint for drupal/menu_item_extras to pin it to version 3.1.1:
"drupal/menu_item_extras": "3.1.1"For guidance on pinning Composer packages, refer to Migrating a Drupal website into a Composer-managed build.
Save the file and run the following command to downgrade the module and update its dependencies:
composer update drupal/menu_item_extras --with-dependenciesRebuild the Drupal cache to remove any corrupted entries written by version 3.1.2:
drush crConfirm the downgrade was successful:
drush pm:list --filter=menu_item_extrasThe output must display version 3.1.1.
Currently, no fix is available in the menu_item_extras module at this time. A corrected release (3.1.3 or later) has not yet been published. The upstream bug report is tracked at drupal.org/project/menu_item_extras/issues/3615084. Monitor that issue for patch availability and a corrected release.
Once a fixed version is released, remove the version pin from composer.json and run the following commands to upgrade and clear the cache:
composer update drupal/menu_item_extras --with-dependencies
drush cr