Page MenuHomePhabricator

PHP Notice: Trying to access array offset on value of type bool (in MobileContext.php)
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   PHP Notice: Trying to access array offset on value of type bool
exception.trace
from /srv/mediawiki/php-1.41.0-wmf.26/extensions/MobileFrontend/includes/MobileContext.php(911)
#0 /srv/mediawiki/php-1.41.0-wmf.26/extensions/MobileFrontend/includes/MobileContext.php(911): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.41.0-wmf.26/extensions/MobileFrontend/includes/MobileFrontendHooks.php(365): MobileContext->isLocalUrl(string)
#2 /srv/mediawiki/php-1.41.0-wmf.26/includes/HookContainer/HookContainer.php(161): MobileFrontendHooks::onBeforePageRedirect(MediaWiki\Output\OutputPage, string, string)
#3 /srv/mediawiki/php-1.41.0-wmf.26/includes/HookContainer/HookRunner.php(950): MediaWiki\HookContainer\HookContainer->run(string, array)
#4 /srv/mediawiki/php-1.41.0-wmf.26/includes/Output/OutputPage.php(2830): MediaWiki\HookContainer\HookRunner->onBeforePageRedirect(MediaWiki\Output\OutputPage, string, string)
#5 /srv/mediawiki/php-1.41.0-wmf.26/includes/MediaWiki.php(962): MediaWiki\Output\OutputPage->output(boolean)
#6 /srv/mediawiki/php-1.41.0-wmf.26/includes/MediaWiki.php(592): MediaWiki->main()
#7 /srv/mediawiki/php-1.41.0-wmf.26/index.php(50): MediaWiki->run()
#8 /srv/mediawiki/php-1.41.0-wmf.26/index.php(46): wfIndexMain()
#9 /srv/mediawiki/w/index.php(3): require(string)
#10 {main}
Impact
Notes

Details

Request URL
https://pt.wikipedia.org/wiki/Especial:Entrar?centralAuthAutologinTried=*&centralAuthError=*

Event Timeline

@Ammarpad It seems the error fired only once and I haven't seen it error out since the 18th. I've tried hitting the same URL a couple of times and didn't see the error fire again on logstash. Could it perhaps be a one-off? I can keep monitoring the dashboard in the next few days also to check.

CentralAuth and MobileFrontend share a strange and poorly documented relationship (with some code in mediawiki-config if I'm remembering correctly) so given this touches a central auth request URL I've also tagged this with CentralAuth.

	/**
	 * Determine whether or not a given URL is local
	 *
	 * @param string $url URL to check against
	 * @return bool
	 */
	public function isLocalUrl( $url ) {
		$parsedTarget = wfParseUrl( $url );
		$parsedServer = wfParseUrl( $this->config->get( 'Server' ) );
L911 >>		return $parsedTarget['host'] === $parsedServer['host'];
	}

Note (Edit): I understand why the bug is happening. wfParseUrl can return false when the URL can't be parsed for some reason - so MobileFrontend should be handling this (or throwing false maybe?) - but I'm not sure why the URL would not be parseable - so would want to understand this more before making a decision here.

@Ammarpad It seems the error fired only once and I haven't seen it error out since the 18th.

There are new ones for September 22nd

'Top-level autologin succeeded' info message from CentralAuth seems to precede the notice. This was added recently in T326281 and looks relevant.

Krinkle renamed this task from PHP Notice: Trying to access array offset on value of type bool to PHP Notice: Trying to access array offset on value of type bool (in MobileContext.php).Sep 25 2023, 1:27 PM

'Top-level autologin succeeded' info message from CentralAuth seems to precede the notice.

Given the presence of that, the redirect in question is probably CheckUser's SpecialPageBeforeExecuteHookHandler::onSpecialPageBeforeExecute():

$special->getOutput()->redirect( Title::newMainPage( $special->getContext() ) );

which is somewhat broken (will try to redirect to Main Page instead of /wiki/Main Page, although in practice it will work out since browsers will interpret it as relative to the "parent directory" in the current URL).

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

[mediawiki/extensions/CentralAuth@master] Fix redirect to main page after top-level autologin

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

Note (Edit): I understand why the bug is happening. wfParseUrl can return false when the URL can't be parsed for some reason - so MobileFrontend should be handling this (or throwing false maybe?) - but I'm not sure why the URL would not be parseable - so would want to understand this more before making a decision here.

wfParseUrl() returns null for relative URLs (except protocol-relative ones). OutputPage::redirect() tries to expand the URL, but it can't expand path-relative URLs (ie. relative URLs which do not start with a slash) as it does not know the base URL, so those are left as-is. Redirecting to a path-relative URL doesn't make much sense but is technically valid, so there is no guarantee URLs passed to BeforePageRedirect are parseable.

Change 961972 merged by jenkins-bot:

[mediawiki/extensions/CentralAuth@master] Fix redirect to main page after top-level autologin

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