From a8e8a89ade2e5fd1aed16905335fbb765fbdde67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Sat, 22 Oct 2022 12:49:11 +0200 Subject: [PATCH] Only check unsupported browsers on user rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- build/psalm-baseline.xml | 35 ++++++++++++-- core/Application.php | 4 ++ .../BeforeTemplateRenderedListener.php | 44 ++++++++++++++++++ core/src/main.js | 5 -- core/src/unsupported-browser-redirect.js | 26 +++++++++++ core/src/unsupported-browser.js | 2 +- core/src/utils/RedirectUnsupportedBrowsers.js | 9 ++-- core/src/views/UnsupportedBrowser.vue | 10 +++- dist/core-common.js | Bin 14586175 -> 14586215 bytes dist/core-common.js.map | Bin 28419288 -> 28419274 bytes dist/core-main.js | Bin 148492 -> 147710 bytes dist/core-main.js.map | Bin 490840 -> 483984 bytes dist/core-unsupported-browser-redirect.js | Bin 0 -> 3064 bytes ...nsupported-browser-redirect.js.LICENSE.txt | Bin 0 -> 826 bytes dist/core-unsupported-browser-redirect.js.map | Bin 0 -> 18466 bytes dist/core-unsupported-browser.js | Bin 9188 -> 9400 bytes dist/core-unsupported-browser.js.LICENSE.txt | Bin 826 -> 826 bytes dist/core-unsupported-browser.js.map | Bin 35187 -> 35711 bytes lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + webpack.common.js | 4 ++ webpack.modules.js | 1 + 22 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 core/Listener/BeforeTemplateRenderedListener.php create mode 100644 core/src/unsupported-browser-redirect.js create mode 100644 dist/core-unsupported-browser-redirect.js create mode 100644 dist/core-unsupported-browser-redirect.js.LICENSE.txt create mode 100644 dist/core-unsupported-browser-redirect.js.map diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 18eb5af458a..b1a38b6730a 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -823,12 +823,23 @@ + + $res + $res + + + openssl_pkey_new($config) + + + resource + $userSession $userSession get_class($res) === 'OpenSSLAsymmetricKey' + is_resource($res) @@ -1066,6 +1077,12 @@ addServiceListener + + + FTP_BINARY + FTP_BINARY + + put @@ -1097,10 +1114,12 @@ + + 'OCA\\Files_External::loadAdditionalBackends' + dispatch - @@ -1130,7 +1149,6 @@ $maxUploadFilesize - $maxUploadFilesize null @@ -1457,7 +1475,6 @@ $groupID - $groupID @@ -1651,7 +1668,8 @@ - + + addServiceListener addServiceListener addServiceListener addServiceListener @@ -1749,6 +1767,9 @@ $levelNum + + $identifier === false + @@ -3741,6 +3762,12 @@ \Test\Util\User\Dummy + + + $version + $version + + $this->request->server diff --git a/core/Application.php b/core/Application.php index 749f2d176d4..6b3d7d6e0c7 100644 --- a/core/Application.php +++ b/core/Application.php @@ -5,6 +5,7 @@ * * @author Christoph Wurst * @author Joas Schilling + * @author John Molakvoæ * @author Julius Härtl * @author Lukas Reschke * @author Mario Danic @@ -42,6 +43,7 @@ use OC\Authentication\Listeners\UserDeletedStoreCleanupListener; use OC\Authentication\Listeners\UserDeletedTokenCleanupListener; use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener; use OC\Authentication\Notifications\Notifier as AuthenticationNotifier; +use OC\Core\Listener\BeforeTemplateRenderedListener; use OC\Core\Notification\CoreNotifier; use OC\DB\Connection; use OC\DB\MissingColumnInformation; @@ -51,6 +53,7 @@ use OC\DB\SchemaWrapper; use OC\Metadata\FileEventListener; use OC\TagManager; use OCP\AppFramework\App; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Events\Node\NodeDeletedEvent; use OCP\Files\Events\Node\NodeWrittenEvent; @@ -310,6 +313,7 @@ class Application extends App { } ); + $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class); $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class); $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class); diff --git a/core/Listener/BeforeTemplateRenderedListener.php b/core/Listener/BeforeTemplateRenderedListener.php new file mode 100644 index 00000000000..4b658cb550a --- /dev/null +++ b/core/Listener/BeforeTemplateRenderedListener.php @@ -0,0 +1,44 @@ + + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OC\Core\Listener; + +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +class BeforeTemplateRenderedListener implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof BeforeTemplateRenderedEvent)) { + return; + } + + if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) { + // Making sure to inject just after core + \OCP\Util::addScript('core', 'unsupported-browser-redirect'); + } + } +} diff --git a/core/src/main.js b/core/src/main.js index a8abbe5ac02..ec23171b6ea 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -36,11 +36,6 @@ import './globals.js' import './jquery/index.js' import { initCore } from './init.js' import { registerAppsSlideToggle } from './OC/apps.js' -import { testSupportedBrowser } from './utils/RedirectUnsupportedBrowsers.js' - -if (!window.TESTING && !OC?.config?.no_unsupported_browser_warning) { - testSupportedBrowser() -} window.addEventListener('DOMContentLoaded', function() { initCore() diff --git a/core/src/unsupported-browser-redirect.js b/core/src/unsupported-browser-redirect.js new file mode 100644 index 00000000000..5ea64221a04 --- /dev/null +++ b/core/src/unsupported-browser-redirect.js @@ -0,0 +1,26 @@ +/** + * @copyright 2022 John Molakvoæ + * + * @author John Molakvoæ + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { testSupportedBrowser } from './utils/RedirectUnsupportedBrowsers.js' + +if (!window.TESTING && !OC?.config?.no_unsupported_browser_warning) { + testSupportedBrowser() +} diff --git a/core/src/unsupported-browser.js b/core/src/unsupported-browser.js index 59b4154ec6b..a9b44b666fc 100644 --- a/core/src/unsupported-browser.js +++ b/core/src/unsupported-browser.js @@ -1,5 +1,5 @@ /** - * @copyright 2021 John Molakvoæ + * @copyright 2022 John Molakvoæ * * @author John Molakvoæ * diff --git a/core/src/utils/RedirectUnsupportedBrowsers.js b/core/src/utils/RedirectUnsupportedBrowsers.js index dd6bb99b94d..04382722c2d 100644 --- a/core/src/utils/RedirectUnsupportedBrowsers.js +++ b/core/src/utils/RedirectUnsupportedBrowsers.js @@ -1,5 +1,5 @@ /** - * @copyright 2021 John Molakvoæ + * @copyright 2022 John Molakvoæ * * @author John Molakvoæ * @@ -19,8 +19,6 @@ * along with this program. If not, see . */ -import { generateUrl } from '@nextcloud/router' - import { supportedBrowsersRegExp } from '../services/BrowsersListService.js' import browserStorage from '../services/BrowserStorageService.js' import logger from '../logger.js' @@ -49,6 +47,9 @@ export const testSupportedBrowser = function() { // If incompatible, NOT overridden AND NOT already on the warning page, // redirect to the unsupported warning page if (window.location.pathname.indexOf(redirectPath) === -1) { - window.location = generateUrl(redirectPath) + const redirectUrl = window.location.href.replace(window.location.origin, '') + const base64Param = Buffer.from(redirectUrl).toString('base64') + history.pushState(null, null, `${redirectPath}?redirect_url=${base64Param}`) + window.location.reload() } } diff --git a/core/src/views/UnsupportedBrowser.vue b/core/src/views/UnsupportedBrowser.vue index 86e24925c32..e46c64da24c 100644 --- a/core/src/views/UnsupportedBrowser.vue +++ b/core/src/views/UnsupportedBrowser.vue @@ -1,5 +1,5 @@