Page MenuHomePhabricator

OAuth can register tokens with empty scopes (which subsequently error out)
Closed, ResolvedPublicPRODUCTION ERROR

Description

Steps to replicate the issue (include links if applicable):

Use the following code:https://gitlab.wikimedia.org/toolforge-repos/link-dispenser/-/blob/d34e3e39b37b71251e7ec7726c473aa9c1691135/auth.py to authenticate and retrieve data about the user

What happens?:
At the step where a request is made to the following URL: https://meta.wikimedia.org/w/rest.php/oauth2/resource/profile

I got back the following request text:

<!DOCTYPE html>
<html><head><title>Internal error - Meta-Wiki</title><meta name="color-scheme" content="light dark" /><style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style></head><body>
<div class="cdx-message--error cdx-message cdx-message--block"><span class="cdx-message__icon"></span><div class="cdx-message__content">[10cf4ec5-4f8e-49e3-ba8a-525febc9da25] 2026-03-20 02:17:16: Fatal exception of type &quot;TypeError&quot;</div></div><!-- Set $wgShowExceptionDetails = true; at the bottom of LocalSettings.php to show detailed debugging information. --></body></html>

Looking at the request on Logstash, I get the following traceback:

from /srv/mediawiki/php-1.46.0-wmf.20/extensions/OAuth/src/ResourceServer.php(113)
#0 /srv/mediawiki/php-1.46.0-wmf.20/extensions/OAuth/src/SessionProvider.php(151): MediaWiki\Extension\OAuth\ResourceServer->getScopes()
#1 /srv/mediawiki/php-1.46.0-wmf.20/includes/Session/SessionManager.php(568): MediaWiki\Extension\OAuth\SessionProvider->provideSessionInfo(MediaWiki\Request\WebRequest)
#2 /srv/mediawiki/php-1.46.0-wmf.20/includes/Session/SessionManager.php(137): MediaWiki\Session\SessionManager->getSessionInfoForRequest(MediaWiki\Request\WebRequest)
#3 /srv/mediawiki/php-1.46.0-wmf.20/includes/Request/WebRequest.php(861): MediaWiki\Session\SessionManager->getSessionForRequest(MediaWiki\Request\WebRequest)
#4 /srv/mediawiki/php-1.46.0-wmf.20/includes/Setup.php(504): MediaWiki\Request\WebRequest->getSession()
#5 /srv/mediawiki/php-1.46.0-wmf.20/includes/WebStart.php(73): require_once(string)
#6 /srv/mediawiki/php-1.46.0-wmf.20/rest.php(18): require(string)
#7 /srv/mediawiki/w/rest.php(3): require(string)
#8 {main}

What should have happened instead?:

Not that? Based on the text of what I selected, I should definitely be able to lookup atleast the username of the user I am authenticating. Additionally I definitely shouldn't be causing a production error.

Event Timeline

Restricted Application changed the subtype of this task from "Bug Report" to "Production Error". · View Herald Transcript
Restricted Application added a subscriber: • Aklapper. · View Herald Transcript

Copying this in from Discord, I figured out what the problem was. In my code, I was asking for "basic" rights from the server, but since I had an authonly grant, instead of granting me at least "authonly" permissions, it instead granted me a null scope, which caused a prod error when I tried to request anything with it. I've implemented a fix by asking specifically for the authonly scope in my initial request, but there is probably a fix here somewhere that needs to be made to the extension to show an error/a mismatch instead of going up in flames.

Soda renamed this task from OAuth can register consumers with null scopes (which subsequently error out) to OAuth can register tokens with empty scopes (which subsequently error out).Mar 20 2026, 6:51 AM
Soda updated the task description. (Show Details)
Soda updated the task description. (Show Details)
matmarex subscribed.

This reminds me of T409901. It looks like we missed a spot.

Change #1256493 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/OAuth@master] ResourceServer: Handle the case of no scopes

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

After this change, you will instead get an API error with "code": "readapidenied" (because, with no scopes, your client will have no rights to do anything).

This reminds me of T409901. It looks like we missed a spot.

Ack! It seems like.

Change #1256493 merged by jenkins-bot:

[mediawiki/extensions/OAuth@master] ResourceServer: Handle the case of no scopes

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