Last modified: 2014-04-29 15:26:42 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T65251, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 63251 - XSS in action=info
XSS in action=info
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Unprioritized normal (vote)
: ---
Assigned To: Chris Steipp
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-03-29 05:31 UTC by Chris Steipp
Modified: 2014-04-29 15:26 UTC (History)
12 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Escape sortKey (902 bytes, patch)
2014-03-29 05:48 UTC, Chris Steipp
Details
Escape sortKey (894 bytes, patch)
2014-03-31 23:53 UTC, Chris Steipp
Details

Description Chris Steipp 2014-03-29 05:31:03 UTC
Reported to security@, confirmed in master. The fix in the report fixes this particular issue, although I'm suspicious that we'll find another way to inject javascript in the array returned from pageInfo().


>>>>


I have found an XSS vulnerability in the MediaWiki info action. If the default sort key is set to a string containing a script, the script will be executed when the page is viewed using the info action. For example, if the wikitext
 
{{DEFAULTSORT:<script>alert("hi");</script>}}
 
is included on a page and then the page is views with action=info (accessible using the “Page information” link in the Tools sidebar), the code will be executed displaying an alert box. This can be reproduced by creating a page named Test containing only the above text and then viewing the page with the URL http://url.to.wiki/index.php?title=Test&action=info. The vulnerability can be remediated by adding one line of code:
 
$sortKey = htmlentities($sortKey, ENT_QUOTES);
 
to the file mediawiki/includes/actions/InfoAction.php before line 265 (line number according to http://git.wikimedia.org/blob/mediawiki%2Fcore.git/dd3de3dbb71f09fca8a97642626e3c84d562d8f2/includes%2Factions%2FInfoAction.php) yielding
 
…
// Default sort key
$sortKey = $title->getCategorySortkey();
if ( !empty( $pageProperties['defaultsort'] ) ) {
        $sortKey = $pageProperties['defaultsort'];
}                      
                                        
$sortKey = htmlentities($sortKey, ENT_QUOTES);
$pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-default-sort' ), $sortKey );
…
 
__________________________
Dr. Cindy Cicalese
Lead Software Systems Engineer
The MITRE Corporation
Comment 1 Chris Steipp 2014-03-29 05:48:51 UTC
Created attachment 14969 [details]
Escape sortKey

This is patch suggested by Cindy in the report, and fixes this particular issue. Should be safe to deploy it as is.
Comment 2 Chris Steipp 2014-03-29 06:03:15 UTC
Since the patch was simple enough and low risk, I've gone ahead and deployed it to both wmf19 and wmf20. I'll take another look through that info action code on Monday and see if there are any other injections we need to fix.
Comment 3 Chris Steipp 2014-03-31 20:53:48 UTC
It looks like sortKey was the only unescaped value from pageInfo(), so the current patch should fix the whole problem. Markus, can we add this into the next tarball release?

It seems like onView or addRow should be aware if the values are properly escaped, and escape them if not instead of relying on pageInfo to return everything correctly escaped, but that type of refactor is probably better done in a public change after this is public.
Comment 4 Krinkle 2014-03-31 21:18:04 UTC
htmlentities() seems like overkill (encodes way more than necessary, bloating the html, we output UTF-8 and stuff, most of it can and should go straight through), plus it has the downside of needing a bitflag to encode both quotes (easy to mess up or confuse).

We generally use the more performant and lighweight htmlspecialchars() which in turn does encode both quotes by default.

The original submitter presumably suggested htmlentities because they are not familiar with our coding conventions.
Comment 5 Chris Steipp 2014-03-31 23:49:12 UTC
Yeah, I forgot I was going to update that. htmlspecialchars() without ENT_QUOTES is fine for mediawiki, since this is being written into the html body. It doesn't encode single quotes, but we don't need to in this context.
Comment 6 Chris Steipp 2014-03-31 23:53:17 UTC
Created attachment 14987 [details]
Escape sortKey
Comment 7 Chris Steipp 2014-04-04 18:18:09 UTC
Liangent just reported a bug with the current patch.

I'll get this updated to use the htmlspecialchars version today.
Comment 8 Liangent 2014-04-04 18:44:46 UTC
(In reply to Chris Steipp from comment #3)
> It seems like onView or addRow should be aware if the values are properly
> escaped, and escape them if not instead of relying on pageInfo to return
> everything correctly escaped, but that type of refactor is probably better
> done in a public change after this is public.

The problem should be ... displaytitle is stored partly escaped (ie. <script>-escaped but <b>-preserved) and we want it outputted as-is, so we can't simply escape everything again ... Anyway is storing an escaped version a good idea?
Comment 9 Chris Steipp 2014-04-04 19:11:18 UTC
Yeah, having display title partly escaped (I'm pretty sure it's parsed wikitext) makes it difficult to deal with-- it's safe to output into the html body, but not into an html attribute. So no, I'm not a fan of storing things "escaped".

If we follow "Escape as close to the output as possible", then we really should wait to escape the output of pageInfo() in addRow(), or probably the caller of addRow() which is onView(). But again, we can do that patch publicly in gerrit after this is released.

Oh, and the htmlspecialchars patch was deployed today:
18:43 csteipp: redeployed updated patch for bug63251 to fix a reported bug
Comment 10 Liangent 2014-04-11 14:27:33 UTC
wikitech wiki is still vulnerable.

We should really maintain a list of wikis to fix in case of security issues.
Comment 11 Chris Steipp 2014-04-11 23:25:21 UTC
Ops patched wikitech today. Thanks for pointing that out
Comment 12 Cindy Cicalese 2014-04-14 18:04:17 UTC
A CVE number for this bug has been reserved: CVE-2014-2853.
Comment 13 Chris Steipp 2014-04-22 04:22:34 UTC
Adding debian and wikia-- we're planning to include this fix in a tarball release this Thursday, April 24th.
Comment 14 Markus Glaser 2014-04-22 12:22:39 UTC
The patch applies nicely to REL1_21 and REL1_22. I can confirm the described XSS is fixed by the patch on those releases. 

On REL1_19, afaik there's no action=info, so I assume, the vulnerability is also not present there. Can someone confirm this?

One further notice: we must not forget to patch the yet unreleased REL1_23 on Thursday as well.
Comment 15 Grunny 2014-04-22 12:35:03 UTC
Yeah, this shouldn't affect MW 1.19. MW 1.19 does have action=info:
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/REL1_19/includes%2Factions%2FInfoAction.php

But, it's disabled by default with [[mw:Manual:$wgAllowPageInfo]] for performance reasons, and it doesn't have the sortkey part that is vulnerable anyway, only info on page views, watchers, etc. The rest was added later as part of bug 38450.
Comment 17 Andre Klapper 2014-04-29 14:36:42 UTC
Anything left to do here, or all branches covered so this can be closed as RESOLVED FIXED?

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links