diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-05-20 15:14:53 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-05-20 18:16:11 +0300 |
commit | 9e3447f850c2a56f6a66ea483723d72ff8150c4a (patch) | |
tree | c9d29d1bd320e282dbd7941d0e99a82451865488 | |
parent | 994b4063bc949a610e289f50c68d3ffb077b73a9 (diff) |
Remove unreliable csp detection and reload handling
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | appinfo/routes.php | 1 | ||||
-rw-r--r-- | lib/Controller/DocumentController.php | 48 | ||||
-rw-r--r-- | src/files.js | 56 | ||||
-rw-r--r-- | src/services/preload.js | 43 | ||||
-rw-r--r-- | src/view/FilesAppIntegration.js | 40 |
5 files changed, 0 insertions, 188 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index 5e358e0d..760e0a83 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -30,7 +30,6 @@ return [ //documents ['name' => 'document#index', 'url' => 'index', 'verb' => 'GET'], ['name' => 'document#remote', 'url' => 'remote', 'verb' => 'GET'], - ['name' => 'document#openRemoteFile', 'url' => 'open', 'verb' => 'GET'], ['name' => 'document#createFromTemplate', 'url' => 'indexTemplate', 'verb' => 'GET'], ['name' => 'document#publicPage', 'url' => '/public', 'verb' => 'GET'], diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index c12df105..e70bcae5 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -11,7 +11,6 @@ namespace OCA\Richdocuments\Controller; -use OCA\Richdocuments\Events\BeforeFederationRedirectEvent; use OCA\Richdocuments\Service\FederationService; use OCA\Richdocuments\Service\InitialStateService; use OCA\Richdocuments\TemplateManager; @@ -361,53 +360,6 @@ class DocumentController extends Controller { } /** - * Redirect to the files app with proper CSP headers set for federated editing - * This is a workaround since we cannot set a nonce for allowing dynamic URLs in the richdocument iframe - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function openRemoteFile($fileId) { - try { - $folder = $this->rootFolder->getUserFolder($this->uid); - $item = $folder->getById($fileId)[0]; - if (!($item instanceof File)) { - throw new \Exception('Node is not a file'); - } - - if ($item->getStorage()->instanceOfStorage(\OCA\Files_Sharing\External\Storage::class)) { - $remote = $item->getStorage()->getRemote(); - $remoteCollabora = $this->federationService->getRemoteCollaboraURL($remote); - if ($remoteCollabora !== '') { - $absolute = $item->getParent()->getPath(); - $relativeFolderPath = $folder->getRelativePath($absolute); - $relativeFilePath = $folder->getRelativePath($item->getPath()); - $url = '/index.php/apps/files/?dir=' . $relativeFolderPath . - '&richdocuments_open=' . $relativeFilePath . - '&richdocuments_fileId=' . $fileId . - '&richdocuments_remote_access=' . $remote; - - $event = new BeforeFederationRedirectEvent( - $item, $relativeFolderPath, $remote - ); - $eventDispatcher = \OC::$server->getEventDispatcher(); - $eventDispatcher->dispatch(BeforeFederationRedirectEvent::class, $event); - if ($event->getRedirectUrl()) { - $url = $event->getRedirectUrl(); - } - return new RedirectResponse($url); - } - $this->logger->warning('Failed to connect to remote collabora instance for ' . $fileId); - } - } catch (\Exception $e) { - $this->logger->logException($e, ['app' => 'richdocuments']); - return $this->renderErrorPage('Failed to open the requested file.'); - } - - return new TemplateResponse('core', '403', [], 'guest'); - } - - /** * Open file on Source instance with token from Initiator instance * * @PublicPage diff --git a/src/files.js b/src/files.js index 932381f7..e9d7e359 100644 --- a/src/files.js +++ b/src/files.js @@ -7,7 +7,6 @@ import { showError } from '@nextcloud/dialogs' import { getDocumentUrlFromTemplate, getDocumentUrlForPublicFile, getDocumentUrlForFile } from './helpers/url' import PostMessageService from './services/postMessage.tsx' import Config from './services/config.tsx' -import Preload from './services/preload' import Types from './helpers/types' import FilesAppIntegration from './view/FilesAppIntegration' import { splitPath } from './helpers' @@ -151,52 +150,6 @@ const odfViewer = { documentUrl = getDocumentUrlFromTemplate(templateId, fileName, fileDir) } - /** - * We need to reload the page to set a proper CSP if the file is federated - * and the reload didn't happen for the exact same file - * - * @param {string} url the url - * @param {Function} callback to be run after reload is complete - */ - const canAccessCSP = (url, callback) => { - let canEmbed = false - const frame = document.createElement('iframe') - frame.style.display = 'none' - frame.onload = () => { - canEmbed = true - } - document.body.appendChild(frame) - frame.setAttribute('src', url) - setTimeout(() => { - if (!canEmbed) { - callback() - } - document.body.removeChild(frame) - }, 1000) - - } - - // FIXME: Once Nextcloud 16 is minimum requirement we can just pass the allowed domains to initial state - // to check then if they are set properly - const reloadForFederationCSP = (fileName, shareOwnerId) => { - const preloadId = Preload.open ? parseInt(Preload.open.id) : -1 - if (typeof shareOwnerId !== 'undefined') { - const lastIndex = shareOwnerId.lastIndexOf('@') - // only redirect if remote file, not opened though reload and csp blocks the request - if (shareOwnerId.slice(lastIndex).indexOf('/') !== -1 && fileId !== preloadId) { - canAccessCSP('https://' + shareOwnerId.slice(lastIndex) + '/ocs/v2.php/apps/richdocuments/api/v1/federation', () => { - console.debug('Cannot load federated instance though CSP, navigating to ', generateUrl('/apps/richdocuments/open?fileId=' + fileId)) - window.location = generateUrl('/apps/richdocuments/open?fileId=' + fileId) - }) - } - } - return false - } - - if (context) { - reloadForFederationCSP(fileName, context?.shareOwnerId) - } - $('head').append($('<link rel="stylesheet" type="text/css" href="' + generateFilePath('richdocuments', 'css', 'mobile.css') + '"/>')) const $iframe = $('<iframe id="richdocumentsframe" nonce="' + btoa(OC.requestToken) + '" scrolling="no" allowfullscreen src="' + documentUrl + '" />') @@ -361,15 +314,6 @@ $(document).ready(function() { OC.MimeType._mimeTypeIcons['application/vnd.oasis.opendocument.graphics'] = imagePath('richdocuments', 'x-office-draw') - // Open the template picker if there was a create parameter detected on load - if (Preload.create && Preload.create.type && Preload.create.filename) { - FilesAppIntegration.preloadCreate() - } - - if (Preload.open) { - FilesAppIntegration.preloadOpen() - } - // Open documents if a public page is opened for a supported mimetype const isSupportedMime = isPublic && odfViewer.supportedMimes.indexOf($('#mimetype').val()) !== -1 && odfViewer.excludeMimeFromDefaultOpen.indexOf($('#mimetype').val()) === -1 const showSecureView = isPublic && isDownloadHidden && odfViewer.hideDownloadMimes.indexOf($('#mimetype').val()) !== -1 diff --git a/src/services/preload.js b/src/services/preload.js deleted file mode 100644 index c0cf1e1c..00000000 --- a/src/services/preload.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net> - * - * @author Julius Härtl <jus@bitgrid.net> - * - * @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 <http://www.gnu.org/licenses/>. - * - */ - -import { getSearchParam } from '../helpers/url' - -const preloadCreate = getSearchParam('richdocuments_create') -const preloadOpen = getSearchParam('richdocuments_open') -const Preload = {} - -if (preloadCreate) { - Preload.create = { - type: getSearchParam('richdocuments_create'), - filename: getSearchParam('richdocuments_filename'), - } -} - -if (preloadOpen) { - Preload.open = { - filename: preloadOpen, - id: getSearchParam('richdocuments_fileId'), - } -} - -export default Preload diff --git a/src/view/FilesAppIntegration.js b/src/view/FilesAppIntegration.js index 66b7c384..a634ac83 100644 --- a/src/view/FilesAppIntegration.js +++ b/src/view/FilesAppIntegration.js @@ -23,11 +23,6 @@ import { generateUrl, generateRemoteUrl, getRootUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' import moment from '@nextcloud/moment' -import Preload from '../services/preload' -import { splitPath } from '../helpers' -import Types from '../helpers/types' -import Config from '../services/config.tsx' -import NewFileMenu from './NewFileMenu' const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1' @@ -570,41 +565,6 @@ export default { }) }, - /** - * Automaically open a document on page load - */ - preloadOpen() { - if (this.handlers.preloadOpen && this.handlers.preloadOpen(this)) { - return - } - - const fileId = Preload.open.id - const path = Preload.open.filename - setTimeout(function() { - window.FileList.$fileList.one('updated', function() { - const [, file] = splitPath(path) - const fileModel = FileList.getModelForFile(file) - OCA.RichDocuments.open({ path, fileId, fileModel, fileList: window.FileList }) - }) - }, 250) - }, - - /** - * Automaically open a template picker on page load - */ - preloadCreate() { - if (this.handlers.preloadCreate && this.handlers.preloadCreate(this)) { - return - } - - setTimeout(function() { - window.FileList.$fileList.one('updated', function() { - const fileType = Types.getFileType(Preload.create.type, Config.get('ooxml')) - NewFileMenu._openTemplatePicker(Preload.create.type, fileType.mime, Preload.create.filename + '.' + fileType.extension) - }) - }, 250) - }, - loggingContext() { return { currentUser: getCurrentUser()?.uid, |