Problem/Motivation
For menu links created after upgrading to specific versions of Drupal core, any custom menu link attributes are no longer included in the link data produced by loading a menu link tree. The attributes get sanitized when saving the menu tree.
This causes the plugin definition in the menu_tree table to get out of sync with the data saved in the menu_link_content_data table.
This issue is present since Drupal core versions introduced a patch for SA-CORE-2025-004 which sanitizes the attributes to fix a XSS vulnerability in the core Link class.
The issue is caused by \Drupal\menu_link_content\Entity\MenuLinkContent::postSave calling $this->getPluginDefinition(); which calls $this->getUrlObject() which calls AttributeXss::sanitizeAttributes().
Affected Drupal core versions (all versions with the aforementioned patch):
>= 10.3.14
>= 10.4.5
>= 11.0.13
>= 11.1.5
>= 11.2.0-alpha1
Steps to reproduce
See issue in menu_link_attributes.
The issue seems likely to be reproducible with other modules which manipulate link attributes.
Comments
Comment #2
marttir commentedComment #3
larowlanAny chance these attributes contain underscores ?
Comment #4
tostinni commentedYes indeed, here is an example that we have where classes are lost:
What is the recommended fix here ? Convert underscores to dashes ?
Comment #5
larowlanYeah that's what I did and it fixed my issue. Core's XSS filtering strips out attributes with an underscore already. We could probably repurpose this issue to review if that is still valid in a world of HTML5 - it was added to core when everything was XHTML. Underscores weren't appropriate in XHTML but are in HTML5.
Comment #6
larowlanI think we should probably close this as duplicate of #3514968: [PP-1] Refactor \Drupal\link\AttributeXss from SA-CORE-2025-004
Comment #7
xjm@larowlan I'm not sure about marking it duplicate; the issue summary describes a data integrity problem. We would ideally want to backport a fix for that to the production and even security-supported branches, potentially, rather than waiting on the minor-only refactoring of the API to properly parse HTML5.
Comment #8
xjm@larowlan pointed out that
menu_treeis just an index table, which I knew but second-guessed. So the data integrity issue is a recoverable one; we just need to trigger a router rebuild to clean it up once the underlying underscores-versus-hyphens corrections are added for implentations.