Last modified: 2012-03-22 19:46:21 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 T37317, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 35317 - CSRF in Special:Upload
CSRF in Special:Upload
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Special pages (Other open bugs)
unspecified
All All
: High normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks: 35387
  Show dependency treegraph
 
Reported: 2012-03-19 08:48 UTC by Tim Starling
Modified: 2012-03-22 19:46 UTC (History)
6 users (show)

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


Attachments
Demo for successful CSRF image upload on test.wikipedia.org (2.06 KB, text/html)
2012-03-20 09:46 UTC, Jan Schejbal
Details
Re-enable CSRF check on upload, disabled in r56793 (865 bytes, patch)
2012-03-20 23:08 UTC, Tim Starling
Details
Re-enable CSRF check on upload, disabled in r56793 (v2) (892 bytes, patch)
2012-03-20 23:58 UTC, Tim Starling
Details
Patch against 1.18 (874 bytes, patch)
2012-03-21 00:02 UTC, Tim Starling
Details

Description Tim Starling 2012-03-19 08:48:17 UTC
-------- Original Message --------
Subject: 	CSRF in image upload
Date: 	Sun, 18 Mar 2012 15:05:50 +0100
From: 	Jan Schejbal
To: 	security@wikimedia.org


Dear MediaWiki development team,
I have discovered a Cross-site request forgery security issue in
MediaWiki. The edit token is not checked for file uploads. This was done
intentionally under the assumption that it is not possible to forge a
file upload using JavaScript. (See includes/specials/SpecialUpload.php,
a comment saying "Skip token check for file uploads as that can't be
faked via JS")

That assumption is wrong. With HTML5 and modern browsers, this is
possible with a few lines of code using FormData and BlobBuilder, and I
think that it probably has been possible for a while with
XMLHttpRequests and custom encoding of the POST body.

Please keep me updated about the steps you take to fix this issue. If
you provide acknowledgements for security bug reports e.g. in the
release notes, please attribute this to "Jan Schejbal / Hatforce.com".

Kind regards,
Jan Schejbal
Comment 1 Tim Starling 2012-03-20 09:07:09 UTC
I haven't been able to reproduce this. The documentation on MDN indicates that FormData is only used as a parameter to XMLHttpRequest.send(), but XHR doesn't allow cross-origin requests. XMLHttpRequest.open() fails so it's not possible to send the request. 

Can you provide some sample JavaScript code demonstrating this issue?
Comment 2 Jan Schejbal 2012-03-20 09:46:06 UTC
Created attachment 10288 [details]
Demo for successful CSRF image upload on test.wikipedia.org

I have attached a proof of concept. Please make sure you are logged in on test.wikipedia.org with an account that can upload images, then open the attached file. You should be redirected to the uploaded image. Note that this requires a current version Firefox or Chrome.

XHR does not allow to read the response to cross-origin requests, but it does allow to make them.
Comment 3 Tim Starling 2012-03-20 22:10:21 UTC
Right, my mistake. If I disable the extension I installed in Firefox specifically to block CSRF attacks (RequestPolicy), then it works.
Comment 4 Tim Starling 2012-03-20 23:08:22 UTC
Created attachment 10291 [details]
Re-enable CSRF check on upload, disabled in r56793

Suggested commit message:

Revert r56793, which removed the CSRF check for Special:Upload for normal file uploads. Cross-site posting of file uploads without user interaction has been possible since at least as early as Chrome 8 (late 2010) and Firefox 6 (mid 2011). 

Commonist has used api.php since version 0.4.0 (April 2010), and the API already requires an edit token, so Commonist 0.4.0+ is not affected by this change.


Suggested announcement mail text:

Jan Schejbal of Hatforce.com discovered a cross-site request forgery (CSRF) vulnerability in Special:Upload. Modern browsers (since at least as early as December 2010) are able to post file uploads without user interaction, violating previous security assumptions within MediaWiki. 

Depending on the wiki's configuration, this vulnerability could lead to further compromise, especially on private wikis where the set of allowed file types is broader than on public wikis. Note that CSRF allows compromise of a wiki from an external website even if the wiki is behind a firewall.
Comment 5 Tim Starling 2012-03-20 23:58:09 UTC
Created attachment 10293 [details]
Re-enable CSRF check on upload, disabled in r56793 (v2)

Patch against /trunk/phase3 instead of /trunk/phase3/includes
Comment 6 Tim Starling 2012-03-21 00:02:13 UTC
Created attachment 10294 [details]
Patch against 1.18

Patch against 1.18, also applies against 1.17. The difference seems to be just  $this->getUser() versus $wgUser.
Comment 7 MZMcBride 2012-03-22 19:46:21 UTC
Related revision: r114429.

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


Navigation
Links