From 3ffdb4cce3859625b7be2e8d721d57d97dcc1740 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 20 Dec 2024 20:17:32 -0800 Subject: [PATCH 1/5] [ticket/17457] Help clients cache the manifest PHPBB-17457 --- phpBB/phpbb/manifest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php index a2701b28c38..811b063fc0a 100644 --- a/phpBB/phpbb/manifest.php +++ b/phpBB/phpbb/manifest.php @@ -93,6 +93,10 @@ public function handle(): JsonResponse $vars = array('manifest', 'board_path'); extract($this->phpbb_dispatcher->trigger_event('core.modify_manifest', compact($vars))); - return new JsonResponse($manifest); + $response = new JsonResponse($manifest); + $response->setPublic(); + $response->setMaxAge(3600); + $response->headers->addCacheControlDirective('must-revalidate', true); + return $response; } } From b6b0973e9ec1a8b1eddb4b3db77790d0063e2549 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 20 Dec 2024 20:18:31 -0800 Subject: [PATCH 2/5] =?UTF-8?q?[ticket/17457]=20Remove=20dir=20from=20mani?= =?UTF-8?q?fest,=20it=E2=80=99s=20not=20implemented?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHPBB-17457 --- phpBB/config/default/container/services.yml | 1 - phpBB/phpbb/manifest.php | 9 +-------- tests/functional/manifest_test.php | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 253a70342a9..8a4336e832d 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -161,7 +161,6 @@ services: class: phpbb\manifest arguments: - '@config' - - '@language' - '@path_helper' - '@event_dispatcher' - '@user' diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php index 811b063fc0a..1eb84eb6a72 100644 --- a/phpBB/phpbb/manifest.php +++ b/phpBB/phpbb/manifest.php @@ -16,7 +16,6 @@ use phpbb\config\config; use phpbb\event\dispatcher_interface; use phpbb\exception\http_exception; -use phpbb\language\language; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -25,9 +24,6 @@ class manifest /** @var config */ protected $config; - /** @var language */ - protected $language; - /** @var path_helper */ protected $path_helper; @@ -41,17 +37,15 @@ class manifest * Constructor for manifest controller * * @param config $config - * @param language $language * @param path_helper $path_helper * @param dispatcher_interface $phpbb_dispatcher * @param user $user */ - public function __construct(config $config, language $language, path_helper $path_helper, dispatcher_interface $phpbb_dispatcher, user $user) + public function __construct(config $config, path_helper $path_helper, dispatcher_interface $phpbb_dispatcher, user $user) { $this->config = $config; $this->path_helper = $path_helper; $this->phpbb_dispatcher = $phpbb_dispatcher; - $this->language = $language; $this->user = $user; } @@ -77,7 +71,6 @@ public function handle(): JsonResponse 'short_name' => $sitename_short ?: utf8_substr($sitename, 0, 12), 'display' => 'standalone', 'orientation' => 'portrait', - 'dir' => $this->language->lang('DIRECTION'), 'start_url' => $board_path, 'scope' => $board_path, ]; diff --git a/tests/functional/manifest_test.php b/tests/functional/manifest_test.php index 2099dd76618..0d94be0debf 100644 --- a/tests/functional/manifest_test.php +++ b/tests/functional/manifest_test.php @@ -25,7 +25,6 @@ public function test_manifest() 'short_name' => 'yourdomain', 'display' => 'standalone', 'orientation' => 'portrait', - 'dir' => 'ltr', 'start_url' => $url_path, 'scope' => $url_path, ]; From a707fe30dd66a7de85d80e0b2c23a6479f8d80bf Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 20 Dec 2024 20:19:17 -0800 Subject: [PATCH 3/5] [ticket/17457] Add more variables to manifest core event PHPBB-17457 --- phpBB/phpbb/manifest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php index 1eb84eb6a72..4418327a2c4 100644 --- a/phpBB/phpbb/manifest.php +++ b/phpBB/phpbb/manifest.php @@ -79,11 +79,13 @@ public function handle(): JsonResponse * Event to modify manifest data before it is outputted * * @event core.modify_manifest - * @var array manifest Array of manifest members - * @var string board_path Path to the board root + * @var array manifest Array of manifest members + * @var string board_url Url to the board root + * @var string sitename Full name of the board + * @var string sitename_short Shortened name of the board * @since 4.0.0-a1 */ - $vars = array('manifest', 'board_path'); + $vars = ['manifest', 'board_url', 'sitename', 'sitename_short']; extract($this->phpbb_dispatcher->trigger_event('core.modify_manifest', compact($vars))); $response = new JsonResponse($manifest); From 11b071f626c3691a82d2e0722f577ca4c3c617c2 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 20 Dec 2024 20:43:08 -0800 Subject: [PATCH 4/5] [ticket/17457] Oops fix changed variable name PHPBB-17457 --- phpBB/phpbb/manifest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php index 4418327a2c4..880db6a4442 100644 --- a/phpBB/phpbb/manifest.php +++ b/phpBB/phpbb/manifest.php @@ -80,12 +80,12 @@ public function handle(): JsonResponse * * @event core.modify_manifest * @var array manifest Array of manifest members - * @var string board_url Url to the board root + * @var string board_path Path to the board root * @var string sitename Full name of the board * @var string sitename_short Shortened name of the board * @since 4.0.0-a1 */ - $vars = ['manifest', 'board_url', 'sitename', 'sitename_short']; + $vars = ['manifest', 'board_path', 'sitename', 'sitename_short']; extract($this->phpbb_dispatcher->trigger_event('core.modify_manifest', compact($vars))); $response = new JsonResponse($manifest); From 0bf195c46ffec1cfae7813f97a77b4e9cce734c1 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 21 Dec 2024 09:40:49 -0800 Subject: [PATCH 5/5] [ticket/17457] Allow bots but let reverse proxies know PHPBB-17457 --- phpBB/phpbb/manifest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/manifest.php b/phpBB/phpbb/manifest.php index 880db6a4442..6b48138517e 100644 --- a/phpBB/phpbb/manifest.php +++ b/phpBB/phpbb/manifest.php @@ -15,9 +15,7 @@ use phpbb\config\config; use phpbb\event\dispatcher_interface; -use phpbb\exception\http_exception; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Response; class manifest { @@ -56,11 +54,6 @@ public function __construct(config $config, path_helper $path_helper, dispatcher */ public function handle(): JsonResponse { - if ($this->user->data['is_bot']) - { - throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION'); - } - $board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path(); $sitename = html_entity_decode($this->config['sitename'], ENT_QUOTES, 'UTF-8'); @@ -92,6 +85,13 @@ public function handle(): JsonResponse $response->setPublic(); $response->setMaxAge(3600); $response->headers->addCacheControlDirective('must-revalidate', true); + + if (!empty($this->user->data['is_bot'])) + { + // Let reverse proxies know we detected a bot. + $response->headers->set('X-PHPBB-IS-BOT', 'yes'); + } + return $response; } }