From c4e45c6c8c2e5e1423d0f288214cfb70537df9c3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 30 May 2017 09:27:48 -0700 Subject: [PATCH] Detect and prevent invalid configuation of "ui.footer-items" Summary: Fixes T12775. Currently, we do not validate this option and it's possible to configure it in an invalid way. Test Plan: Tried to misconfigure things, was helpfully pointed toward errors. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12775 Differential Revision: https://secure.phabricator.com/D18041 --- src/__phutil_library_map__.php | 2 + .../PhabricatorCustomUIFooterConfigType.php | 41 +++++++++++++++++++ .../option/PhabricatorUIConfigOptions.php | 3 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/applications/config/custom/PhabricatorCustomUIFooterConfigType.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ce3cc27784..74ebbfe742 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2522,6 +2522,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldStorageQuery' => 'infrastructure/customfield/query/PhabricatorCustomFieldStorageQuery.php', 'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php', 'PhabricatorCustomLogoConfigType' => 'applications/config/custom/PhabricatorCustomLogoConfigType.php', + 'PhabricatorCustomUIFooterConfigType' => 'applications/config/custom/PhabricatorCustomUIFooterConfigType.php', 'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php', 'PhabricatorDaemonBulkJobController' => 'applications/daemon/controller/PhabricatorDaemonBulkJobController.php', 'PhabricatorDaemonBulkJobListController' => 'applications/daemon/controller/PhabricatorDaemonBulkJobListController.php', @@ -7779,6 +7780,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldStorageQuery' => 'Phobject', 'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage', 'PhabricatorCustomLogoConfigType' => 'PhabricatorConfigOptionType', + 'PhabricatorCustomUIFooterConfigType' => 'PhabricatorConfigJSONOptionType', 'PhabricatorDaemon' => 'PhutilDaemon', 'PhabricatorDaemonBulkJobController' => 'PhabricatorDaemonController', 'PhabricatorDaemonBulkJobListController' => 'PhabricatorDaemonBulkJobController', diff --git a/src/applications/config/custom/PhabricatorCustomUIFooterConfigType.php b/src/applications/config/custom/PhabricatorCustomUIFooterConfigType.php new file mode 100644 index 0000000000..d9961e7454 --- /dev/null +++ b/src/applications/config/custom/PhabricatorCustomUIFooterConfigType.php @@ -0,0 +1,41 @@ + $item) { + if (!is_array($item)) { + throw new Exception( + pht( + 'Footer item with index "%s" is invalid: each item must be a '. + 'dictionary describing a footer item.', + $idx)); + } + + try { + PhutilTypeSpec::checkMap( + $item, + array( + 'name' => 'string', + 'href' => 'optional string', + )); + } catch (Exception $ex) { + throw new Exception( + pht( + 'Footer item with index "%s" is invalid: %s', + $idx, + $ex->getMessage())); + } + } + } + + +} diff --git a/src/applications/config/option/PhabricatorUIConfigOptions.php b/src/applications/config/option/PhabricatorUIConfigOptions.php index 4f93946ce2..cef3fbd342 100644 --- a/src/applications/config/option/PhabricatorUIConfigOptions.php +++ b/src/applications/config/option/PhabricatorUIConfigOptions.php @@ -46,6 +46,7 @@ final class PhabricatorUIConfigOptions EOJSON; $logo_type = 'custom:PhabricatorCustomLogoConfigType'; + $footer_type = 'custom:PhabricatorCustomUIFooterConfigType'; return array( $this->newOption('ui.header-color', 'enum', 'blindigo') @@ -63,7 +64,7 @@ EOJSON; "Phabricator logo in the site header.\n\n". " - **Wordmark**: Choose new text to display next to the logo. ". "By default, the header displays //Phabricator//.\n\n")), - $this->newOption('ui.footer-items', 'list', array()) + $this->newOption('ui.footer-items', $footer_type, array()) ->setSummary( pht( 'Allows you to add footer links on most pages.'))