From: Tim Düsterhus Date: Thu, 6 Aug 2020 12:38:02 +0000 (+0200) Subject: Detect misconfigured hostnames during WCFSetup X-Git-Tag: 5.3.0_Alpha_1~89^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7353493f3e6baa4ba3ebbedc07cec3b7dcfc7fd6;p=GitHub%2FWoltLab%2FWCF.git Detect misconfigured hostnames during WCFSetup Misconfigured reverse reverse proxies might rewrite the `host` header to the upstream's hostname, instead of preserving the `host` as it was sent by the web browser. Such a misconfiguration will cause WoltLab Suite to generate incorrect absolute URLs and more importantly this also causes it to specify an incorrect `domain` within cookies. The latter leads to the browser ignoring the cookie. At the end of WCFSetup this ultimately leads to the ACP session cookie being ignored, which in turn leads to failing the transition from WCFSetup into the package installation. Instead the user will be bounced to the LoginForm which fails to load, because the necessary option.xml was not yet installed. An example HAProxy configuration that reproduces the issue is as follows: listen test mode http bind *:80 http-request set-header host 172.19.0.5 server nginx 172.19.0.5:80 If the WCFSetup is accepted via any hostname that is not `172.19.0.5`, e.g. by using `localhost` then cookies will fail to stick within the web browser. This commit extends the system requirements step to: - Compare the HTTP_HOST as seen by the web server against both: 1) The `Referer` header. 2) The `window.location.host` value in JavaScript. If any of those mismatches, then the web server is not correctly configured. - Read a cookie that was set earlier. If this cookie is missing, then most likely the `domain` property was incorrectly specified. This commit most likely resolves #3024. --- diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 9aa4bf6c00..89ced00ae4 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -19,6 +19,7 @@ use wcf\system\io\File; use wcf\system\io\Tar; use wcf\system\language\LanguageFactory; use wcf\system\package\PackageArchive; +use wcf\system\request\RouteHandler; use wcf\system\session\ACPSessionFactory; use wcf\system\session\SessionHandler; use wcf\system\setup\Installer; @@ -225,6 +226,8 @@ class WCFSetup extends WCF { if (isset($_REQUEST['step'])) $step = $_REQUEST['step']; else $step = 'selectSetupLanguage'; + header('set-cookie: wcfsetup_cookietest='.TMP_FILE_PREFIX.'; domain=' . str_replace(RouteHandler::getProtocol(), '', RouteHandler::getHost()) . (RouteHandler::secureConnection() ? '; secure' : '')); + // execute current step switch ($step) { /** @noinspection PhpMissingBreakStatementInspection */ @@ -384,6 +387,16 @@ class WCFSetup extends WCF { // openssl extension $system['openssl']['result'] = @extension_loaded('openssl'); + // misconfigured reverse proxy / cookies + $system['hostname']['result'] = true; + list($system['hostname']['value']) = explode(':', $_SERVER['HTTP_HOST'], 2); + if (!empty($_SERVER['HTTP_REFERER'])) { + $refererHostname = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); + $system['hostname']['result'] = $_SERVER['HTTP_HOST'] == $refererHostname; + } + + $system['cookie']['result'] = !empty($_COOKIE['wcfsetup_cookietest']) && $_COOKIE['wcfsetup_cookietest'] == TMP_FILE_PREFIX; + WCF::getTPL()->assign([ 'system' => $system, 'nextStep' => 'configureDirectories' diff --git a/wcfsetup/setup/lang/setup_de.xml b/wcfsetup/setup/lang/setup_de.xml index a68f251db7..8e791cf315 100644 --- a/wcfsetup/setup/lang/setup_de.xml +++ b/wcfsetup/setup/lang/setup_de.xml @@ -38,6 +38,11 @@ + + + + + diff --git a/wcfsetup/setup/lang/setup_en.xml b/wcfsetup/setup/lang/setup_en.xml index 40933e817a..52bef8182a 100644 --- a/wcfsetup/setup/lang/setup_en.xml +++ b/wcfsetup/setup/lang/setup_en.xml @@ -38,6 +38,11 @@ + + + + + diff --git a/wcfsetup/setup/template/stepShowSystemRequirements.tpl b/wcfsetup/setup/template/stepShowSystemRequirements.tpl index 4f8a8a112a..34952f5db8 100644 --- a/wcfsetup/setup/template/stepShowSystemRequirements.tpl +++ b/wcfsetup/setup/template/stepShowSystemRequirements.tpl @@ -82,6 +82,62 @@ + +
+

{lang}wcf.global.systemRequirements.hostname{/lang}

+ +
+
+
{lang}wcf.global.systemRequirements.element.required{/lang}
+
{lang}wcf.global.systemRequirements.hostname.requirement{/lang}
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ {$system.hostname.value} + {lang}wcf.global.systemRequirements.hostname.description{/lang} +
+ +
+
+
+ +
+

{lang}wcf.global.systemRequirements.cookie{/lang}

+ +
+
+
{lang}wcf.global.systemRequirements.element.required{/lang}
+
{lang}wcf.global.systemRequirements.active{/lang}
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ + {if !$system.cookie.result}{lang}wcf.global.systemRequirements.notActive{/lang}{else} + {lang}wcf.global.systemRequirements.active{/lang} + {/if} + {if !$system.cookie.result}{lang}wcf.global.systemRequirements.cookie.description{/lang}{/if} +
+
+
+
@@ -130,7 +186,7 @@
- +