From ef797494ca898180bed0b1f1b2f90c0688e36d69 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Sun, 26 May 2013 10:57:29 -0700 Subject: [PATCH] Add Allowed uris config Summary: Kind of a quick look at an idea for T2184 Ref T2184 Test Plan: Make sure the site still loads Reviewers: epriestley CC: aran, Korvin, mbishopim3 Maniphest Tasks: T2184 Differential Revision: https://secure.phabricator.com/D6045 --- .../AphrontApplicationConfiguration.php | 4 +++- .../option/PhabricatorCoreConfigOptions.php | 13 +++++++++++++ .../DifferentialRevisionIDFieldSpecification.php | 8 ++++++++ src/infrastructure/env/PhabricatorEnv.php | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/aphront/configuration/AphrontApplicationConfiguration.php b/src/aphront/configuration/AphrontApplicationConfiguration.php index 4e71a29c7b..8f353282ae 100644 --- a/src/aphront/configuration/AphrontApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontApplicationConfiguration.php @@ -120,6 +120,7 @@ abstract class AphrontApplicationConfiguration { $file_uri = PhabricatorEnv::getEnvConfig( 'security.alternate-file-domain'); $conduit_uris = PhabricatorEnv::getEnvConfig('conduit.servers'); + $allowed_uris = PhabricatorEnv::getEnvConfig('phabricator.allowed-uris'); $uris = array_merge( array( @@ -127,7 +128,8 @@ abstract class AphrontApplicationConfiguration { $prod_uri, $file_uri, ), - $conduit_uris); + $conduit_uris, + $allowed_uris); $host_match = false; foreach ($uris as $uri) { diff --git a/src/applications/config/option/PhabricatorCoreConfigOptions.php b/src/applications/config/option/PhabricatorCoreConfigOptions.php index 053c5d1390..1d2e34167d 100644 --- a/src/applications/config/option/PhabricatorCoreConfigOptions.php +++ b/src/applications/config/option/PhabricatorCoreConfigOptions.php @@ -37,6 +37,19 @@ final class PhabricatorCoreConfigOptions "{{phabricator.base-uri}}. Most installs do not need to set ". "this option.")) ->addExample('http://phabricator.example.com/', pht('Valid Setting')), + $this->newOption('phabricator.allowed-uris', 'list', array()) + ->setLocked(true) + ->setSummary(pht("Alternative URIs that can access Phabricator.")) + ->setDescription( + pht( + "These alternative URIs will be able to access 'normal' pages ". + "on your Phabricator install. Other features such as OAuth ". + "won't work. The major use case for this is moving installs ". + "across domains.")) + ->addExample( + '["http://phabricator2.example.com/", '. + '"http://phabricator3.example.com/]"', + pht('Valid Setting')), $this->newOption('phabricator.timezone', 'string', null) ->setSummary( pht("The timezone Phabricator should use.")) diff --git a/src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php b/src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php index 3e341c25e9..2703386953 100644 --- a/src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php @@ -71,6 +71,14 @@ final class DifferentialRevisionIDFieldSpecification if ($uri == PhabricatorEnv::getProductionURI('/D'.$id)) { return $id; } + + $allowed_uris = PhabricatorEnv::getAllowedURIs('/D'.$id); + + foreach ($allowed_uris as $allowed_uri) { + if ($uri == $allowed_uri) { + return $id; + } + } } return null; diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 1cad3d4f12..a9ed3571b0 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -278,6 +278,21 @@ final class PhabricatorEnv { return rtrim($production_domain, '/').$path; } + public static function getAllowedURIs($path) { + $uri = new PhutilURI($path); + if ($uri->getDomain()) { + return $path; + } + + $allowed_uris = self::getEnvConfig('phabricator.allowed-uris'); + $return = array(); + foreach ($allowed_uris as $allowed_uri) { + $return[] = rtrim($allowed_uri, '/').$path; + } + + return $return; + } + /** * Get the fully-qualified production URI for a static resource path.