Page MenuHomePhabricator

CVE-2022-41346: Special:OAuth/rest_redirect does unrestricted redirects
Closed, ResolvedPublicSecurity

Description

Special:OAuth/rest_redirect (apparently created to make the returnto / returntoquery mechanism used by login/signup able to target MediaWiki REST API endpoints) does unrestricted redirects.

Example: https://www.mediawiki.org/wiki/Special:OAuth/rest_redirect?rest_url=https:/evil.com/
Another example (which is fairly easy to exploit, just send the user to the login page and then have the redirect page replicate the login page with an apparent login error): https://mediawiki.org/wiki/Special:UserLogin?returnto=Special:OAuth/rest_redirect&returntoquery=rest_url%3Dhttps%3A%2F%2Fevil.com%2F

Instead of just calling wfExpandUrl() the code should validate that it received an URL with only a path component.

Event Timeline

Good catch. I'd guess it would be fairly trivial to build allow lists to validate returnto and returntoquery. The question is which one should we use, since we have several ways of doing this that I'm aware of (1, 2, 3, 4, etc.)

Good catch. I'd guess it would be fairly trivial to build allow lists to validate returnto and returntoquery. The question is which one should we use, since we have several ways of doing this that I'm aware of (1, 2, 3, 4, etc.)

I don't think Special:OAuth/rest_redirect needs cross-domain redirects at all, so it just needs to verify that the redirect URL is relative to the current domain (which it is for the redirects generated by OAuth itself). And maybe verify that the path component has the correct prefix for the OAuth REST API, although I don't think there's any harm in redirecting elsewhere - an attacker can already send the user's browser to an arbitrary Wikipedia page.

mmartorana changed the task status from Open to In Progress.Jul 21 2022, 5:51 PM
mmartorana triaged this task as Medium priority.
mmartorana changed Risk Rating from N/A to Medium.

Hi @Tgr - are you willing to write a patch for this issue?

To test that the vulnerability is patched, visit <wiki>/wiki/Special:OAuth/rest_redirect?rest_url=https:/evil.com/
To test that the functionality still works, visit <wiki>/w/rest.php/oauth2/authorize?response_type=code&client_id=1 (which should redirect you back there after a login)

Hi @Tgr - thank you for your patch.

I confirm the vulnerability is fixed.

I am uploading this new patch file because I had some issue applying your one (probably spaces).

Deployed @mmartorana's above patch to 1.40.0-wmf.1. Tested on mwdebug1002 under meta and it appears to work as intended. No issues in logstash. Now tracking at T276237 and T311785.

Mstyles renamed this task from Special:OAuth/rest_redirect does unrestricted redirects to CVE-2022-41346: Special:OAuth/rest_redirect does unrestricted redirects.Oct 5 2022, 11:34 PM
Mstyles moved this task from Watching to Our Part Is Done on the Security-Team board.
Mstyles added a subscriber: gerritbot.

Change 838938 had a related patch set uploaded (by Mstyles; author: Gergő Tisza):

[mediawiki/extensions/OAuth@master] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

Change 838821 had a related patch set uploaded (by Mstyles; author: Gergő Tisza):

[mediawiki/extensions/OAuth@REL1_37] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

Change 838822 had a related patch set uploaded (by Mstyles; author: Gergő Tisza):

[mediawiki/extensions/OAuth@REL1_38] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

Change 838823 had a related patch set uploaded (by Mstyles; author: Gergő Tisza):

[mediawiki/extensions/OAuth@REL1_39] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

Change 838938 merged by jenkins-bot:

[mediawiki/extensions/OAuth@master] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

sbassett changed the visibility from "Custom Policy" to "Public (No Login Required)".Oct 6 2022, 4:32 PM
sbassett changed the edit policy from "Custom Policy" to "All Users".

Change 838822 merged by SBassett:

[mediawiki/extensions/OAuth@REL1_38] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

Change 838821 merged by SBassett:

[mediawiki/extensions/OAuth@REL1_37] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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

Change 838823 merged by SBassett:

[mediawiki/extensions/OAuth@REL1_39] SECURITY: Prevent open redirect in Special:OAuth/rest_redirect

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