From 7353493f3e6baa4ba3ebbedc07cec3b7dcfc7fd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 6 Aug 2020 14:38:02 +0200 Subject: [PATCH] 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. --- .../files/lib/system/WCFSetup.class.php | 13 +++++ wcfsetup/setup/lang/setup_de.xml | 5 ++ wcfsetup/setup/lang/setup_en.xml | 5 ++ .../template/stepShowSystemRequirements.tpl | 58 ++++++++++++++++++- 4 files changed, 80 insertions(+), 1 deletion(-) 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 @@
- + -- 2.20.1