Page MenuHomePhabricator

CentralAuth edge login and autologin for some Wikimedia domains broken on mobile
Closed, ResolvedPublic

Description

After logging in on mobile web (on hu.m.wikipedia.org, with Chrome 83 on Android 10 on a Pixel 4) I get the error shown on the first screenshot below (the message key is centralauth-error-badtoken). The login works otherwise, I'm logged in even on the screen with the error.

When visiting en.m.wiktionary.org, I see that edge login has failed; I'm not immediately logged in, but get logged in in a second or so.

When visiting m.mediawiki.org, both edge login and autologin fail; I'm not logged in at all.

login erroredge login failureautologin failure
centralauth-login-error.png (3×1 px, 164 KB)
centralauth-edge-login-failure.png (3×1 px, 312 KB)
centralauth-login-failure.png (3×1 px, 215 KB)

Logging in on m.mediawiki.org works without an error message, and logs me in to some projects (commons.wikimedia.org, at least) but on most projects including Wikipedias I remain logged out (no autologin, either).

I have seen the error in the past, so this is not (or at a minimum, not fully) related to SameSite changes or to T257853: CentralAuth edge login broken on desktop (coinciding with SameSite rollout).

Related Objects

Mentioned In
T328397: API:Clientlogin send wrong cookie headers on mobile domains
T296349: Session not created on VoteWiki when using desktop site with a mobile user agent
T74186: Varnish: Mobile site redirect interferes with OAuth authorization process
T312042: After log in on mobile Beta Commons, user gets redirected to non-mobile page (and is not logged in there)
T351026: VisualEditor adding nonsense code to file pages
T351113: Figure out how Parsoid will work with MCR slots to support both reading and editing clients
T350544: OOUI widgets now have huge fonts and misaligned buttons in some places
T344757: Remove the BetaFeatures integration in VisualEditor
T344759: Remove VisualEditorTransitionDefault config and AutodisableVisualEditorPref maint script
T253620: Logged out after switching between mobile and desktop site on the log-in page and later back again
T345249: Mitigate phase-out of third-party cookies in CentralAuth
T335750: OAuth auto logging doesn't work on mobile Chrome
T335125: Account creation attempt on mobile Wikipedia domain leads user to desktop Special:CentralLogin/complete, often in logged-out state
T318138: Cannot manually log in on mobile Wikidata (real or test)
T262846: Uncaught SyntaxError: Unexpected identifier < (checkLoggedIn script)
T256525: Stay logged in doesn’t work, global login doesn’t work on different projects
Mentioned Here
rECAU7c566b79c70d: Don't autologin to self
rOMWCb5417c0a43d5: CentralAuth: Clarify why we don't use second-level domain for some wikis
rEMFRee049b8e45e0: Handle mobile URLs for other wikis
rOMWCbeb76abd7344: Generalize Meta/Commons exceptions for CentralAuth cookie handling
T351026: VisualEditor adding nonsense code to file pages
T351113: Figure out how Parsoid will work with MCR slots to support both reading and editing clients
T350544: OOUI widgets now have huge fonts and misaligned buttons in some places
T344757: Remove the BetaFeatures integration in VisualEditor
T344759: Remove VisualEditorTransitionDefault config and AutodisableVisualEditorPref maint script
T49647: meta.m.wikimedia.org user login doesn't work
T112730: Failure to OAuth after login on mobile
T198515: "No active login attempt is in progress for your session" (LG K10 (2017))
T200719: CentralAuth AutoLogin not working for MediaWiki mobile site
T225814: m.wikidata: login status not detected
T253620: Logged out after switching between mobile and desktop site on the log-in page and later back again
T318138: Cannot manually log in on mobile Wikidata (real or test)
T335125: Account creation attempt on mobile Wikipedia domain leads user to desktop Special:CentralLogin/complete, often in logged-out state
T312042: After log in on mobile Beta Commons, user gets redirected to non-mobile page (and is not logged in there)
T262846: Uncaught SyntaxError: Unexpected identifier < (checkLoggedIn script)
T257853: CentralAuth edge login broken on desktop (coinciding with SameSite rollout)

Event Timeline

Jdlrobson subscribed.

I have experienced this too and I believe it's been a problem for why (I believe there may even be another bug open) but have no idea what causes it. Am happy to advise/make appropriate changes in MobileFrontend if somebody that can understand CentralAuth can tell me what's going wrong.

This comment was removed by Jdlrobson.

I don't see how this task is related to those errors. All the script in question does is update the personal toolbar so it looks like you are logged in. (You are, in fact, logged in at that point, but the page was rendered earlier; so this is a hack to avoid reloading the page after an AJAX-based login.) Script errors are inconsequential; at worst the user toolbar will look weird, or will not look logged-in until you reload the page.

Sorry for confusion @Tgr I meant to post this on: T262846 Correcting..

Jdlrobson raised the priority of this task from High to Needs Triage.Dec 8 2020, 4:09 PM

(I don't disagree about this being a high-priority issue, FWIW, I'm just pretty sure the cause lies elsewhere.)

This happened in Wikidata in my phone. while I successfully logged-in at Wikipedia and Commons, I stay logged out at Wikidata only in the mobile domain, while in the desktop version stays logged in.

This is more than annoying, and I agree this task should be high priority since more than a year passed since this issue was opened.

I sort of doubt T312042 is a dupe of this. A megadott hitelesítési token lejárt vagy érvénytelen. is centralauth-error-badtoken from the CentralAuth extension. In English that's The provided authentication token is either expired or invalid.

In T312042 I got No active login attempt is in progress for your session. which is centralauth-error-nologinattempt. Also, I was directed to the desktop domain which I don't see happening here.

Similar tasks / possible duplicates:

T318138#8919988 points out that we have some special-casing for a few wikimedia.org domains (see explanation at T49647#525483; the beta version is a bit more flexible) so either that's unnecessary or the rest of wikimedia.org domains likely don't work. That might be a distinct issue happening on top of the one described in this task (which does affect non-wikimedia.org wikis).

There's another suspicious special-casing when unsetting the current domain in $wgCentralAuthAutoLoginWikis. (That should probably be fixed in CentralAuth so the config hack isn't needed. Maybe hard because of mobile domains?) Affects wikimedia.org edge login wikis that aren't Commons or Meta (that is, Wikispecies, Incubator, Wikimania and api.wikimedia.org).

T225814#5402942 points out that the cookie domain for Wikidata is www.wikidata.org (instead of wikidata.org), which seems wrong. (Maybe to avoid conflict with test.wikidata.org? In theory that shouldn't be a problem...) Same for Wikifunctions.

T225814#5992589 / T225814#5992609 points out that MobileContext::getMobileUrl() gives bogus results for URLs from a different wiki (because the mobile domain template is set per-wiki: prod, labs), which is sometimes needed by CentralAuth.

So that's at least four error clusters (which might or might not have the same cause): mobile login fails with centralauth-error-badtoken, mobile login fails with centralauth-error-nologinattempt, mobile and desktop site doesn't share login state, different mobile sites do not share login state.

And at least four broken things in code which might cause some of this (or not): mobile domain not correctly applied to some wikimedia.org wikis in WebResponseSetCookie, mobile domain not correctly taken into account for some wikimedia.org wikis when unsetting the current domain in $wgCentralAuthAutoLoginWikis, shared cookie domain not being the parent domain for Wikidata / Wikifunctions, and cross-wiki mobile domain URL generation broken in between wikis which have a different domain structure.

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

[operations/mediawiki-config@master] Generalize Meta/Commons exceptions for CentralAuth cookie handling

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

Logging in on hu.m.wiktionary.org (in mobile simulation mode on desktop Chrome) worked fine. Some of the edge login links are bogus:

GET https://www.m.mediawiki.org/wiki/Special:CentralAutoLogin/start?type=1x1&from=huwiki&mobile=1 net::ERR_NAME_NOT_RESOLVED
GET https://www.m.wikidata.org/wiki/Special:CentralAutoLogin/start?type=1x1&from=huwiki&mobile=1 net::ERR_NAME_NOT_RESOLVED
GET https://www.m.wikifunctions.org/wiki/Special:CentralAutoLogin/start?type=1x1&from=huwiki&mobile=1 net::ERR_NAME_NOT_RESOLVED

and unsurprisingly, edge login and autologin on those wikis fails. (For autologin it's the same issue, m.mediawiki.org redirects to login.wikimedia.org, but then login.wikimedia.org wants to redirect to www.m.mediawiki.org.) But the other wikis seem to mostly work fine, even unusual ones like Wikisource or Outreach. (Wikimania only worked on the second try, for some reason.) Somewhat suprisingly, central login on mediawiki.org also works, even though that involves a similar redirect chain; and generating edge login links from mediawiki.org to other wikis works too, except the links to Wikidata / Wikifunctions. The code snippet in T225814#5992589, when executed on mediawikiwiki, works correctly for wikidatawiki (which has the same mobile domain structure) and fails for loginwiki (which has a different mobile domain structure) so not sure what's going on.

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

[operations/mediawiki-config@master] CentralAuth: Use second-level domain for cookies for www.* wikis

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

Change 967394 merged by jenkins-bot:

[operations/mediawiki-config@master] CentralAuth: Clarify why we don't use second-level domain for some wikis

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

Mentioned in SAL (#wikimedia-operations) [2023-10-24T20:16:35Z] <jdrewniak@deploy2002> Started scap: Backport for [[gerrit:967208|Update comment about EditAttemptStep instruments]], [[gerrit:967394|CentralAuth: Clarify why we don't use second-level domain for some wikis (T257852)]], [[gerrit:967973|Remove unused VisualEditor config settings (T344757 T344759)]], [[gerrit:967995|[noop] Explain more thoroughly how the '-' prefix works]]

Mentioned in SAL (#wikimedia-operations) [2023-10-24T20:17:58Z] <jdrewniak@deploy2002> tgr and matmarex and jdrewniak: Backport for [[gerrit:967208|Update comment about EditAttemptStep instruments]], [[gerrit:967394|CentralAuth: Clarify why we don't use second-level domain for some wikis (T257852)]], [[gerrit:967973|Remove unused VisualEditor config settings (T344757 T344759)]], [[gerrit:967995|[noop] Explain more thoroughly how the '-' prefix works]] synced to the testservers (htt

Mentioned in SAL (#wikimedia-operations) [2023-10-24T20:23:56Z] <jdrewniak@deploy2002> Finished scap: Backport for [[gerrit:967208|Update comment about EditAttemptStep instruments]], [[gerrit:967394|CentralAuth: Clarify why we don't use second-level domain for some wikis (T257852)]], [[gerrit:967973|Remove unused VisualEditor config settings (T344757 T344759)]], [[gerrit:967995|[noop] Explain more thoroughly how the '-' prefix works]] (duration: 07m 21s)

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

[mediawiki/extensions/MobileFrontend@master] Handle mobile URLs for other wikis

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

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

[operations/mediawiki-config@master] mobile: Add MobileUrlCallback

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

Change 968386 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Handle mobile URLs for other wikis

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

Change 966798 merged by jenkins-bot:

[operations/mediawiki-config@master] Generalize Meta/Commons exceptions for CentralAuth cookie handling

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

Mentioned in SAL (#wikimedia-operations) [2023-11-06T14:35:25Z] <urbanecm@deploy2002> Started scap: Backport for [[gerrit:966798|Generalize Meta/Commons exceptions for CentralAuth cookie handling (T257852)]], [[gerrit:971539|Restore OOUI dialog styles for compatibility (T350544)]]

Mentioned in SAL (#wikimedia-operations) [2023-11-06T14:36:41Z] <urbanecm@deploy2002> urbanecm and tgr and matmarex: Backport for [[gerrit:966798|Generalize Meta/Commons exceptions for CentralAuth cookie handling (T257852)]], [[gerrit:971539|Restore OOUI dialog styles for compatibility (T350544)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2023-11-06T14:48:39Z] <urbanecm@deploy2002> Finished scap: Backport for [[gerrit:966798|Generalize Meta/Commons exceptions for CentralAuth cookie handling (T257852)]], [[gerrit:971539|Restore OOUI dialog styles for compatibility (T350544)]] (duration: 13m 13s)

Change 969401 merged by jenkins-bot:

[operations/mediawiki-config@master] mobile: Add MobileUrlCallback

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

Mentioned in SAL (#wikimedia-operations) [2023-11-13T21:35:59Z] <urbanecm@deploy2002> Started scap: Backport for [[gerrit:969401|mobile: Add MobileUrlCallback (T257852)]], [[gerrit:973797|Parsoid-VE-MCR hack: Always return main slot output if useParsoid is set (T351026 T351113)]]

Mentioned in SAL (#wikimedia-operations) [2023-11-13T21:37:17Z] <urbanecm@deploy2002> urbanecm and ssastry and tgr: Backport for [[gerrit:969401|mobile: Add MobileUrlCallback (T257852)]], [[gerrit:973797|Parsoid-VE-MCR hack: Always return main slot output if useParsoid is set (T351026 T351113)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2023-11-13T21:54:33Z] <urbanecm@deploy2002> Finished scap: Backport for [[gerrit:969401|mobile: Add MobileUrlCallback (T257852)]], [[gerrit:973797|Parsoid-VE-MCR hack: Always return main slot output if useParsoid is set (T351026 T351113)]] (duration: 18m 34s)

I tried a few of the bugs linked in T257852#9252513 that had clear reproduction steps, and closed 3 that were definitely fixed by this work (T335125 T312042 T318138).

Tgr updated Other Assignee, added: matmarex.

T318138#8919988 points out that we have some special-casing for a few wikimedia.org domains (see explanation at T49647#525483; the beta version is a bit more flexible) so either that's unnecessary or the rest of wikimedia.org domains likely don't work. That might be a distinct issue happening on top of the one described in this task (which does affect non-wikimedia.org wikis).

We replaced this with simpler and more correct static code in rOMWCbeb76abd7344: Generalize Meta/Commons exceptions for CentralAuth cookie handling and predecessor patches.

There's another suspicious special-casing when unsetting the current domain in $wgCentralAuthAutoLoginWikis. (That should probably be fixed in CentralAuth so the config hack isn't needed. Maybe hard because of mobile domains?) Affects wikimedia.org edge login wikis that aren't Commons or Meta (that is, Wikispecies, Incubator, Wikimania and api.wikimedia.org).

Fixed in CentralAuth: rECAU7c566b79c70d: Don't autologin to self

T225814#5402942 points out that the cookie domain for Wikidata is www.wikidata.org (instead of wikidata.org), which seems wrong. (Maybe to avoid conflict with test.wikidata.org? In theory that shouldn't be a problem...) Same for Wikifunctions.

This was intentional after all, we documented it more clearly in rOMWCb5417c0a43d5: CentralAuth: Clarify why we don't use second-level domain for some wikis.

T225814#5992589 / T225814#5992609 points out that MobileContext::getMobileUrl() gives bogus results for URLs from a different wiki (because the mobile domain template is set per-wiki: prod, labs), which is sometimes needed by CentralAuth.

Fixed in rEMFRee049b8e45e0: Handle mobile URLs for other wikis.

So that's at least four error clusters (which might or might not have the same cause): mobile login fails with centralauth-error-badtoken, mobile login fails with centralauth-error-nologinattempt, mobile and desktop site doesn't share login state, different mobile sites do not share login state.

We fixed login state sharing, to the extent possible. (*.wikimedia.org wikis can't share state because wikimedia.org is considered an unsafe domain for session cookies. Wikidata and Wikifunctions can't share state for similar reasons. I considered setting cookies on m.wikimedia.org so at least mobile versions of *.wikimedia.org wikis can share login state with each other, but it didn't seem worth the compexity.)

None of the bugs we found explain the centralauth-error-badtoken and centralauth-error-nologinattempt errors, or the fact that the user would start login on the mobile domain but end up on the desktop one, as far as I can see. Maybe those had to do with domain rewrite rules in Varnish. But per T257852#9347008 they don't seem to happen anymore, so something probably changed since those bugs were filed.

Similar tasks / possible duplicates:

Reviewed the three remaining ones (T225814, T112730, T200719), tested where appropriate, all seems good. I think we are done here.

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

[mediawiki/extensions/MobileFrontend@master] Hard-deprecate mobile URL templates

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