From af37b637f544e2c094b0f84c73b08069b1e17eeb Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 10 Jan 2012 16:42:00 -0800 Subject: [PATCH] Detect un-cookieable domain confiugration and explode Summary: Chrome/Chromium won't set cookies on these domains, at least under Ubuntu. See T754. Detect brokenness and explode. Test Plan: Logged into phabricator as "http://derps/" (failed) and "http://derps.com/" (worked) in Chromium. Set config to "http://derps/" (config exploded) and "http://local.aphront.com/" (config OK). Reviewers: btrahan, jungejason Reviewed By: btrahan CC: aran, btrahan Maniphest Tasks: T754 Differential Revision: https://secure.phabricator.com/D1355 --- src/infrastructure/setup/PhabricatorSetup.php | 20 +++++++++++--- webroot/index.php | 26 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/infrastructure/setup/PhabricatorSetup.php b/src/infrastructure/setup/PhabricatorSetup.php index 38c7c94f4d..0524a191b2 100644 --- a/src/infrastructure/setup/PhabricatorSetup.php +++ b/src/infrastructure/setup/PhabricatorSetup.php @@ -1,7 +1,7 @@ getProtocol(); + $host_uri = new PhutilURI($host); + $protocol = $host_uri->getProtocol(); $allowed_protocols = array( 'http' => true, 'https' => true, @@ -264,7 +265,7 @@ class PhabricatorSetup { return; } if (preg_match('/.*\/$/', $host)) { - self::write(" okay phabricator.base-uri\n"); + self::write(" okay phabricator.base-uri protocol\n"); } else { self::writeFailure(); self::write( @@ -275,6 +276,19 @@ class PhabricatorSetup { "options.\n"); return; } + + $host_domain = $host_uri->getDomain(); + if (strpos($host_domain, '.') !== false) { + self::write(" okay phabricator.base-uri domain\n"); + } else { + self::writeFailure(); + self::write( + "You must host Phabricator on a domain that contains a dot ('.'). ". + "The current domain, '{$host_domain}', does not have a dot, so some ". + "browsers will not set cookies on it. For instance, ". + "'http://example.com/ is OK, but 'http://example/' won't work."); + return; + } } $timezone = nonempty( diff --git a/webroot/index.php b/webroot/index.php index 99d772f0a6..0bbdb7c84e 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -1,7 +1,7 @@ getProtocol()) { + case 'http': + case 'https': + break; + default: + phabricator_fatal_config_error( + "'phabricator.base-uri' is set to '{$conf}', which is invalid. ". + "The URI must start with 'http://' or 'https://'."); + } + + if (strpos($uri->getDomain(), '.') === false) { + phabricator_fatal_config_error( + "'phabricator.base-uri' is set to '{$conf}', which is invalid. The URI ". + "must contain a dot ('.'), like 'http://example.com/', not just ". + "'http://example/'. Some web browsers will not set cookies on domains ". + "with no TLD, and Phabricator requires cookies for login."); + } } function phabricator_detect_insane_memory_limit() {