Security: a suggestion note is admin-XSS-filtered rather than escaped, so markup from a suggestion source renders in the editing form

Summary

AiDisclosureDefaultWidget renders a pending suggestion's free-text note through html_tag #value, which core hands to Xss::filterAdmin() and then marks safe. The note is never escaped, so markup a suggestion source puts in it renders live inside the node form, though the code's own comment calls the value plain text. Confirmed on Drupal 11.4.6.

Technical detail

The widget builds the note as the tag's content:

// src/Plugin/Field/FieldWidget/AiDisclosureDefaultWidget.php:523
if ((string) $top['note'] !== '') {
  $build['note'] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#attributes' => ['class' => ['ai-disclosure-widget__suggestion-note']],
    // Plain text, no markup: a machine-written service note.
    '#value' => (string) $top['note'],
  ];
}

A #value that is not already a MarkupInterface takes the filtering branch:

// core/lib/Drupal/Core/Render/Element/HtmlTag.php:109
$element['#markup'] = Markup::create(Xss::filterAdmin($element['#value']));

Xss::filterAdmin() removes <script>, event handlers and javascript: URLs, so this is not a script execution path, but it leaves anchors, images and emphasis intact. The note reaches the widget from SuggestionStorage::upsert() (src/SuggestionStorage.php:92), which stores whatever a producer passes and filters nothing.

Reproduction steps

  1. Install ai_disclosure, add the disclosure field to Article, and create a published article.
  2. Call ai_disclosure.suggestion_storage's upsert() for that node with the note Confirm with <a href="https://attacker.example/confirm">the compliance desk</a> before publishing.
  3. Open the node's edit form and read the served HTML for ai-disclosure-widget__suggestion-note.
  4. The anchor is a live element, not visible text.

Impact

An editor opening the form sees an instruction that appears to come from the site, carrying a link to somewhere the site does not control. Reaching it needs a suggestion producer that forwards untrusted text, and ai_disclosure ships none, so the exposure rests on modules built against the documented API.

It is submitted privately because it concerns how untrusted text is handled on an authenticated form, and it may not warrant an advisory. That is the security team's call. If it reads as hardening, moving it to the public issue queue would be reasonable.

Possible fixes

Pass a MarkupInterface holding the escaped note, which makes HtmlTag skip filtering: '#value' => new FormattableMarkup('@note', ['@note' => (string) $top['note']]).

Or escape first, leaving the filter nothing to act on: '#value' => Html::escape((string) $top['note']). Both were checked against the running site.

If notes are meant to carry formatting, document that and filter at upsert() instead.

Disclosure

AI was used to find this issue, verify it against a running site, and write this report.