Toolbar username lazy builder only XSS filters but doesn't escape user display name - stored remote request

Created on 11 August 2023, over 1 year ago
Updated 12 September 2023, about 1 year ago

Hello

On a vanilla latest Drupal 9.5.9 with the default claro administration theme, having a module with this hook:

function my_module_user_format_name_alter(&$name) {
  $name = "qwerty <img src=xyz onerror=alert('StoredXSS')>";
}

visiting the admin panel renders this:

...aria-pressed="false">qwerty <img src="xyz"></a>

which in turn issues a request to /xyz via the user's browser.

This is due to '#title' => $user->getDisplayName(), at https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/fu... which is somehow filtered (onerror attribute is removed) but rendered on the HTML as is without HTML escaping.

We believe that it should be rendered using HTML escaping so it renders like qwerty &lt;img src... and not like qwerty <img src....

We discovered this from a specific project of ours where we had the hook above concatenating and returning the user's first name and last name. Thus when testing various payloads on the user's name, this issue came up. Yes, it's hard to imagine how this could be exploited (you'd need functionality that would allow users changing other user's names) but fixing it should be best. Also, simply relying on filtering (which currently removes the onerror attribute) may not be future proof, because new filter bypass methods may be discovered. Thus, fully HTML escaping this on rendering should be the best option of all.

thanks

reporters:
- https://www.drupal.org/u/ioannischerouvim
- https://www.drupal.org/u/mariaioann

p.s this issue is a followup of https://security.drupal.org/node/178915 which has been cleared to be posted publicly.

🐛 Bug report
Status

Fixed

Version

10.1

Component
User module 

Last updated 12 minutes ago

Created by

🇬🇷Greece ioannis.cherouvim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024