Page MenuHomePhabricator

Stored XSS in various SystemGifts-related special pages (e.g. Special:SystemGiftManager, Special:ViewSystemGifts) (CVE-2021-36130)
Closed, ResolvedPublicSecurity

Description

  1. As a privileged user (one with the awardmanage user right) go to Special:SystemGiftManager and create a gift that has a title like "><script>alert('XSS')</script>
  2. Hit the button on the page to have the award created
  3. Note that the XSS gets executed right away (if at least one user matches the threshold you chose)...
  4. ..and as a bonus, it gets spread everywhere, or at least to the profile pages of users who got the award (though not directly - it isn't executed on User:/User_profile: page views, but upon clicking on the View all link in the user profile of a user who has more than 4 awards; e.g. not on User:Foo but definitely on Special:ViewSystemGifts? user=Foo)

Tangentially related bonus: the use of $this->msg( 'some message key' )->plain() in SocialProfile in general is more than likely 100% incorrect. (I accept the full responsibility for that, my fault.)

Though they are quite similar code-wise, UserGifts' Special:GiftManager and thus the user-to-user gifting functionality does not seem to be affected. Likewise, the Special:ViewGifts and Special:ViewGift special pages are fine and do not execute the XSS.

Event Timeline


Proposed patch which fixes the issues in SystemGifts spotted with the malicious award name used as an example here, adjusts ->plain() to ->escaped(), ensures that LinkRenderer is passed raw text (->text()) instead of escaped to avoid double-escaping and removes parsing format from Message objects passed to OutputPage#setPageTitle because that method can be passed either a string or a Message object, and finally casts some things we definitely want to be ints as such (in SpecialSystemGiftManager.php).

I only reviewed the patch diff, not the rest of the code, I assume you used phan-taint-check to make sure there's no issues left?

			<input type="hidden" name="id" value="' . ( $gift['gift_id'] ?? '' ) . '" />

From SystemGiftManager, I'd prefer if there was an (int) cast (or intval()) just to make it obvious that gift_id is safe to not have explicit escaping.

					<div class=\"ga-timestamp\">({$gift['timestamp']})</div>

From ViewSystemGift, I think this needs escaping.

I only reviewed the patch diff, not the rest of the code, I assume you used phan-taint-check to make sure there's no issues left?

Alas, SocialProfile does not yet to my knowledge run phan. (Just like how it doesn't support extension registration yet, or...)

From SystemGiftManager, I'd prefer if there was an (int) cast (or intval()) just to make it obvious that gift_id is safe to not have explicit escaping.

Agreed. Implemented locally.

					<div class=\"ga-timestamp\">({$gift['timestamp']})</div>

From ViewSystemGift, I think this needs escaping.

As we discussed on IRC, the current (git master) implementation is indeed just a raw timestamp from the database which is barely "prettified", i.e. "2020-07-18 23:25:37"; but "23:25, 18 July 2020" is more human-friendly, so let's run that timestamp through Language#userTimeAndDate and thus also through htmlspecialchars. 👍

Again, thanks for the review & suggestions, very helpful! 😄 Not only are we fixing obvious security issues (after ~14 years (!)) but also improving usability while it at. Yay!

I only reviewed the patch diff, not the rest of the code, I assume you used phan-taint-check to make sure there's no issues left?

Alas, SocialProfile does not yet to my knowledge run phan. (Just like how it doesn't support extension registration yet, or...)

It looks like it's at least set up to use phan, as it has a phan config. Having the phan-taint-check plugin available only takes a couple more steps, as noted within the documentation. I've created a change set to add it here, feel free to merge if you'd like:

https://gerrit.wikimedia.org/r/683037

A few notes:

  1. You need php-ast installed to run phan (and the plugin) locally, which should be as simple as pecl install ast in most cases.
  2. composer seccheck-fast might emit a couple of warnings, but appears to work fine and generates a few issues, which may or may not be false positives.
  3. I noticed that composer.lock was in SocialProfile's .gitignore - I think the best practice is to include this in the repo, if possible.
Legoktm changed the visibility from "Custom Policy" to "Public (No Login Required)".
Legoktm changed the edit policy from "Custom Policy" to "All Users".

Change 692066 had a related patch set uploaded (by Southparkfan; author: Jack Phoenix):

[mediawiki/extensions/SocialProfile@REL1_35] [SECURITY] Fix XSS in various SystemGifts/UserGifts-related special pages

https://gerrit.wikimedia.org/r/692066

Change 692067 had a related patch set uploaded (by Southparkfan; author: Jack Phoenix):

[mediawiki/extensions/SocialProfile@REL1_36] [SECURITY] Fix XSS in various SystemGifts/UserGifts-related special pages

https://gerrit.wikimedia.org/r/692067

Change 692068 had a related patch set uploaded (by Southparkfan; author: Jack Phoenix):

[mediawiki/extensions/SocialProfile@REL1_31] [SECURITY] Fix XSS in various SystemGifts/UserGifts-related special pages

https://gerrit.wikimedia.org/r/692068

Change 692068 abandoned by Jack Phoenix:

[mediawiki/extensions/SocialProfile@REL1_31] [SECURITY] Fix XSS in various SystemGifts/UserGifts-related special pages

Reason:

Per [[mw:Social tools/MediaWiki compatibility]], the non-master release branches were never supported for social tools, especially not something as old as 1.31. We may (read: probably have to) soon transition to supporting the latest Long-Term Support (LTS) release instead of latest stable, but in any case, let's not give people the false impression that these non-master branches would be usable or recommended to be used.

https://gerrit.wikimedia.org/r/692068

sbassett renamed this task from Stored XSS in various SystemGifts-related special pages (e.g. Special:SystemGiftManager, Special:ViewSystemGifts) to Stored XSS in various SystemGifts-related special pages (e.g. Special:SystemGiftManager, Special:ViewSystemGifts) (CVE-2021-36130).Jul 2 2021, 7:49 PM

Change 692066 merged by jenkins-bot:

[mediawiki/extensions/SocialProfile@REL1_35] [SECURITY] Fix XSS in various SystemGifts/UserGifts-related special pages

https://gerrit.wikimedia.org/r/692066

Change 692067 merged by jenkins-bot:

[mediawiki/extensions/SocialProfile@REL1_36] [SECURITY] Fix XSS in various SystemGifts/UserGifts-related special pages

https://gerrit.wikimedia.org/r/692067