Page MenuHomePhabricator

$wgInternalServer doesn't properly fallback to $wgServer in REL1_39 results in page not properly applying
Closed, ResolvedPublicBUG REPORT

Description

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

  • LocalSettings.php
$wgServer = "https://test.com"
  • maintenance/update.php
	public function execute() {
		print(wfExpandUrl( '/wiki/Main_Page', PROTO_INTERNAL ) . PHP_EOL);
		exit();

Run the code to trigger update.php

php maintenance/update.php --quick

What happens?:

What should have happened instead?:
$wgInternalServer should fallback to $wgServer when not configured

Background & analysis
The investigation started with issue where we noticed view pages are not applying proper CDN cache but a 3600 hard coded s-maxage.
We then dig into the code changed and noticed that the handling of $wgInternalServer has changed, which caused matchURLForCDN to always return false, when $wgInternalServer is not defined.

Previous fallback code

// includes/GlobalFunctions.php
	} elseif ( $defaultProto === PROTO_INTERNAL && $wgInternalServer !== false ) {
		// Make $wgInternalServer fall back to $wgServer if not set
		$serverUrl = $wgInternalServer;
	} else {

REL1_39 code

// includes/WebRequest.php
	public function matchURLForCDN( array $cdnUrls ) {
		$reqUrl = wfExpandUrl( $this->getRequestURL(), PROTO_INTERNAL );
		$config = MediaWikiServices::getInstance()->getMainConfig();
		if ( $config->get( MainConfigNames::CdnMatchParameterOrder ) ) {
			// Strict matching
			return in_array( $reqUrl, $cdnUrls, true );
		}

// includes/utils/UrlUtils.php
		if ( $defaultProto === PROTO_CANONICAL ) {
			$serverUrl = $this->canonicalServer;
		} elseif ( $defaultProto === PROTO_INTERNAL ) {
			$serverUrl = $this->internalServer;
		} else {

Software version (skip for WMF-hosted wikis like Wikipedia):
REL1_39

Workaround
Simplest workaround now is to have in LocalSettings.php

$wgInternalServer = $wgServer;

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Krinkle subscribed.

Thanks @pandafox. Looks like this got lost in the refactor to URLUtils indeed and was missing a test case to ensure its continued function. Aaron will try to investigate in a few weeks. A patch is also welcome sooner than that!

The REL1_39 code had this for fallback

// includes/utils/UrlUtils.php

		if ( $this->server !== null ) {
			if ( $this->canonicalServer === null ) {
				$this->canonicalServer = $this->expand( $this->server, PROTO_HTTP );
			}
			if ( $this->internalServer === null ) {
				$this->internalServer = $this->server;
			}
		}

However, because of the strict checking of === null, these actually doesn't do anything, removing the strict check or check for false would solve the issue, but I'm not yet familiar with the full effect of that'll do without further investigation.

Additionally the wgCanonicalServer is not affected due to the following code in

includes/Setup.php

// Non-trivial expansion of: $wgCanonicalServer, $wgServerName.
// These require calling global functions.
// Also here are other settings that further depend on these two.
if ( $wgCanonicalServer === false ) {
	$wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
}
Krinkle added a subscriber: TK-999.

This seems likely a regression by change 776991 (ref T305093), whch broke $wgCanonicalServer. Credit to @TK-999 for finding that on IRC.

Change 900459 had a related patch set uploaded (by Krinkle; author: Tim Starling):

[mediawiki/core@master] Fix total breakage of wgCanonicalServer fallback

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

Change 900469 had a related patch set uploaded (by Krinkle; author: Tim Starling):

[mediawiki/core@REL1_40] Fix total breakage of wgCanonicalServer fallback

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

Change 900470 had a related patch set uploaded (by Krinkle; author: Tim Starling):

[mediawiki/core@REL1_39] Fix total breakage of wgCanonicalServer fallback

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

Change 900469 merged by jenkins-bot:

[mediawiki/core@REL1_40] Fix total breakage of wgCanonicalServer fallback

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

Change 900470 merged by jenkins-bot:

[mediawiki/core@REL1_39] Fix total breakage of wgCanonicalServer fallback

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

Change 900459 merged by jenkins-bot:

[mediawiki/core@master] Fix total breakage of wgCanonicalServer fallback

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