From 65a2b5e2193434169444ef929314e94e24aa9f37 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 1 May 2020 05:12:01 -0700 Subject: [PATCH] Route hard-coded "/favicon.ico" requests to a favicon resource Summary: See PHI1719. User agents making hard-coded requests to "/favicon.ico" currently 404. This is a mild source of log noise, and we can reasonably route this request. Limitations: - This only routes the "PlatformSite". Other sites (custom Phame blogs, third-party sites, Phurl redirectors) won't route here for now. - This returns a "Location:" redirect to the correct resource rather than icon data directly. This produces the right icon with the right caching behavior, and returning icon data directly is difficult in the general case. However, it won't perform/cache as well as a direct response would. Test Plan: - Visted `/favicon.ico`. - Before: 404. - After: redirect to favicon. Differential Revision: https://secure.phabricator.com/D21195 --- src/__phutil_library_map__.php | 2 ++ .../PhabricatorSystemApplication.php | 1 + .../PhabricatorFaviconController.php | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/applications/system/controller/PhabricatorFaviconController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1618f2078c..765481ba45 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3371,6 +3371,7 @@ phutil_register_library_map(array( 'PhabricatorFactRaw' => 'applications/fact/storage/PhabricatorFactRaw.php', 'PhabricatorFactUpdateIterator' => 'applications/fact/extract/PhabricatorFactUpdateIterator.php', 'PhabricatorFailHisecUserLogType' => 'applications/people/userlog/PhabricatorFailHisecUserLogType.php', + 'PhabricatorFaviconController' => 'applications/system/controller/PhabricatorFaviconController.php', 'PhabricatorFaviconRef' => 'applications/files/favicon/PhabricatorFaviconRef.php', 'PhabricatorFaviconRefQuery' => 'applications/files/favicon/PhabricatorFaviconRefQuery.php', 'PhabricatorFavoritesApplication' => 'applications/favorites/application/PhabricatorFavoritesApplication.php', @@ -9852,6 +9853,7 @@ phutil_register_library_map(array( 'PhabricatorFactRaw' => 'PhabricatorFactDAO', 'PhabricatorFactUpdateIterator' => 'PhutilBufferedIterator', 'PhabricatorFailHisecUserLogType' => 'PhabricatorUserLogType', + 'PhabricatorFaviconController' => 'PhabricatorController', 'PhabricatorFaviconRef' => 'Phobject', 'PhabricatorFaviconRefQuery' => 'Phobject', 'PhabricatorFavoritesApplication' => 'PhabricatorApplication', diff --git a/src/applications/system/application/PhabricatorSystemApplication.php b/src/applications/system/application/PhabricatorSystemApplication.php index 88f07ae17c..45cc0bab77 100644 --- a/src/applications/system/application/PhabricatorSystemApplication.php +++ b/src/applications/system/application/PhabricatorSystemApplication.php @@ -24,6 +24,7 @@ final class PhabricatorSystemApplication extends PhabricatorApplication { return array( '/status/' => 'PhabricatorStatusController', '/debug/' => 'PhabricatorDebugController', + '/favicon.ico' => 'PhabricatorFaviconController', '/robots.txt' => 'PhabricatorRobotsController', '/services/' => array( 'encoding/' => 'PhabricatorSystemSelectEncodingController', diff --git a/src/applications/system/controller/PhabricatorFaviconController.php b/src/applications/system/controller/PhabricatorFaviconController.php new file mode 100644 index 0000000000..721a40be8c --- /dev/null +++ b/src/applications/system/controller/PhabricatorFaviconController.php @@ -0,0 +1,36 @@ + tags in the document body + // to direct user agents to icons, like this: + // + // + // + // However, some software requests the hard-coded path "/favicon.ico" + // directly. To tidy the logs, serve some reasonable response rather than + // a 404. + + // NOTE: Right now, this only works for the "PhabricatorPlatformSite". + // Other sites (like custom Phame blogs) won't currently route this + // path. + + $ref = id(new PhabricatorFaviconRef()) + ->setWidth(64) + ->setHeight(64); + + id(new PhabricatorFaviconRefQuery()) + ->withRefs(array($ref)) + ->execute(); + + return id(new AphrontRedirectResponse()) + ->setIsExternal(true) + ->setURI($ref->getURI()); + } +}