Last modified: 2012-06-17 20:32:27 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 T38938, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 36938 - Correctly escape uselang attribute to prevent xss
Correctly escape uselang attribute to prevent xss
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Normal major (vote)
: 1.20.0 release
Assigned To: Chris Steipp
:
: 37275 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-05-17 16:57 UTC by Chris Steipp
Modified: 2012-06-17 20:32 UTC (History)
10 users (show)

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


Attachments

Description Chris Steipp 2012-05-17 16:57:59 UTC
It looks like the "uselang" parameter is vulnerable to simple reflective xss attacks. 

Fortunately, all modern browsers refuse to run javascript they see in the url, but there is a constant stream of ways around that protection.

http://en.wikipedia.org/wiki/Main_Page?uselang=a%27%20onmouseover=eval(alert(1))%20e=%27

It looks like we use the uselang parameter in several single-quoted strings, but don't escape single quotes in it.
Comment 1 Roan Kattouw 2012-05-18 19:07:17 UTC
Draft submitted in Gerrit: https://gerrit.wikimedia.org/r/#/c/7979/

This draft is private so you won't be able to view it by default, even if you are a Gerrit administrator. I shared it with Chris, Tim and Sam; if someone else would like to review it too, ask me to share it with you.
Comment 2 Sam Reed (reedy) 2012-06-01 16:08:20 UTC
*** Bug 37275 has been marked as a duplicate of this bug. ***
Comment 3 Laurence 'GreenReaper' Parry 2012-06-14 04:02:22 UTC
The fix for this appears to cause a couple of PHP Notices (at least on 1.17.5):

Notice: Undefined variable: userlang in [..]/includes/SkinTemplate.php on line 327
Notice: Undefined variable: userdir in [..]/includes/SkinTemplate.php on line 328

This is on a Russian-language wiki with my user language set to English.

The lines concerned are intended to set the lang and dir attributes . . .

$lang = $wgLang->getCode();
$dir  = $wgLang->getDir();
if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
  $escUserlang = htmlspecialchars( $userlang );   << HERE
  $escUserdir = htmlspecialchars( $userdir );     << HERE
  // Attributes must be in double quotes because htmlspecialchars() doesn't
  // escape single quotes
  $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
  $tpl->set( 'userlangattributes', $attrs );

It looks like $lang and $dir were renamed to $userlang and $userdir in 1.18; the patch for 1.17 should be corrected to refer to $lang and $dir.
Comment 4 Sam Reed (reedy) 2012-06-14 13:54:04 UTC
(In reply to comment #3)
> The fix for this appears to cause a couple of PHP Notices (at least on 1.17.5):
> 
> Notice: Undefined variable: userlang in [..]/includes/SkinTemplate.php on line
> 327
> Notice: Undefined variable: userdir in [..]/includes/SkinTemplate.php on line
> 328
> 
> This is on a Russian-language wiki with my user language set to English.
> 
> The lines concerned are intended to set the lang and dir attributes . . .
> 
> $lang = $wgLang->getCode();
> $dir  = $wgLang->getDir();
> if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
>   $escUserlang = htmlspecialchars( $userlang );   << HERE
>   $escUserdir = htmlspecialchars( $userdir );     << HERE
>   // Attributes must be in double quotes because htmlspecialchars() doesn't
>   // escape single quotes
>   $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
>   $tpl->set( 'userlangattributes', $attrs );
> 
> It looks like $lang and $dir were renamed to $userlang and $userdir in 1.18;
> the patch for 1.17 should be corrected to refer to $lang and $dir.

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

Also note, 1.17 is due to go EOL this month.
Comment 5 db [inactive,noenotif] 2012-06-17 06:48:52 UTC
(In reply to comment #2)
> *** Bug 37275 has been marked as a duplicate of this bug. ***

Please make dup also visible. Thanks.
Comment 6 Krinkle 2012-06-17 20:32:27 UTC
(In reply to comment #5)
> (In reply to comment #2)
> > *** Bug 37275 has been marked as a duplicate of this bug. ***
> 
> Please make dup also visible. Thanks.

Done. Moved to Product:MediaWiki

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


Navigation
Links