Last modified: 2014-06-30 20:16:39 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 T66183, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 64183 - JS injection vulnerability in Html::element()?
JS injection vulnerability in Html::element()?
Status: RESOLVED INVALID
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Unprioritized normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-04-21 12:58 UTC by Yaron Koren
Modified: 2014-06-30 20:16 UTC (History)
3 users (show)

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


Attachments

Description Yaron Koren 2014-04-21 12:58:12 UTC
I'm running MediaWiki 1.23alpha. Having the following test code in one of my extensions:

Html::element( 'a', array( 'href' => "javascript:window.alert('danger!')" ), 'Click here' );

...displays a link that, when clicked on, pops up an alert. I'm told that this is not correct behavior, so I'm submitting a bug for it.
Comment 1 Bartosz Dziewoński 2014-04-21 13:08:08 UTC
(In reply to Yaron Koren from comment #0)
I'm told that
> this is not correct behavior, so I'm submitting a bug for it.

By whom?

While it might not be the most fortunate behavior, Html::element only
HTML-escapes the attributes and does not mangle their contents.

You could validate user input by checking it against the list of protocols returned by wfUrlProtocols(), or using Sanitizer::validateTagAttributes() to do more thorough cleanup of other attributes as well.
Comment 2 Yaron Koren 2014-04-21 13:12:25 UTC
We discussed it in the comments here:

https://gerrit.wikimedia.org/r/#/c/124995/

But based on what you're saying, it sounds like there was just a misunderstanding about escaping vs. mangling of Javascript content.
Comment 3 Yaron Koren 2014-04-21 13:15:30 UTC
Changing to product "Security" - should have done that at the beginning; sorry.
Comment 4 Bartosz Dziewoński 2014-04-21 13:23:36 UTC
(In reply to Yaron Koren from comment #2)
> We discussed it in the comments here:
> 
> https://gerrit.wikimedia.org/r/#/c/124995/
> 
> But based on what you're saying, it sounds like there was just a
> misunderstanding about escaping vs. mangling of Javascript content.

That patches doesn't do anything to resolve any HTML injection issue, it just incorrectly double-escapes user input (which does make it more difficult to do XSS by preventing you from using quotes, angle brackets and ampersands, but by no means impossible). This code looks like it should be using Sanitizer::validateTagAttributes() instead.
Comment 5 Yaron Koren 2014-04-21 13:36:44 UTC
Bartosz - alright, I'll try that out.

Back to the main issue: I should note that, as far as I can remember, calling Html::element() by itself was enough to disable the Javascript, in some earlier version of MediaWiki. The relevant call is in my "HTML Tags" extension, and I was surprised recently to see that it wasn't mangling the Javascript, where I believe the same code was doing that before, with an earlier version (MW 1.19, maybe). It could be just faulty memory, though.
Comment 6 Brion Vibber 2014-04-21 15:54:36 UTC
Html::element outputs whatever you tell it to.

If you are sanitizing user input, that's your job to do it -- that's why we have a big ol' Sanitizer class etc for stuff that comes in from wikitext.
Comment 7 Chris Steipp 2014-04-21 16:31:28 UTC
Html::element will sanitize attributes against attacks that add new attributes to the Html element, or attacks that try to add new html elements inside that element's body. But if a user is able to influence the entire attribute for hrefs (or iframes, or styles, or onmouseover...), or influence what attributes are added in the first place, then that's a whole separate set of concerns.

For hrefs specifically, you would want to either build the link with the Linker class, or use one of the other Sanitizer functions to limit what kinds of urls you allow to be added.

As Bartosz suggested, you probably want to use validateTagAttributes on anything that users have supplied. It has code specifically to handle hrefs for cases like this.
Comment 8 Bartosz Dziewoński 2014-06-30 17:54:18 UTC
Is there a reason why this report is still private?

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


Navigation
Links