From a4c17935006a72cd447a6c642b0bb33959a68af3 Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Thu, 2 Nov 2023 20:55:44 +0100 Subject: [PATCH 01/25] Shortcut url followup 2 --- .../composables/actions/files/useFileActionsOpenShortcut.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts b/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts index 1a8e02c8549..f9faff51f8b 100644 --- a/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts +++ b/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts @@ -108,7 +108,6 @@ function getWrapper({ }) } - // url contains xss code to test xss protection mocks.$clientService.webdav.getFileContents.mockResolvedValue( mock({ body: getFileContentsValue From 41f450848b62e77a5b9f8a550bb4ad9359ad93c8 Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Thu, 2 Nov 2023 21:01:55 +0100 Subject: [PATCH 02/25] open in same window if is ocis uri --- .../composables/actions/files/useFileActionsOpenShortcut.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/web-pkg/src/composables/actions/files/useFileActionsOpenShortcut.ts b/packages/web-pkg/src/composables/actions/files/useFileActionsOpenShortcut.ts index 34305f06733..2f4404ab1bb 100644 --- a/packages/web-pkg/src/composables/actions/files/useFileActionsOpenShortcut.ts +++ b/packages/web-pkg/src/composables/actions/files/useFileActionsOpenShortcut.ts @@ -13,6 +13,7 @@ import { useGettext } from 'vue3-gettext' import { Store } from 'vuex' import { useClientService } from '../../clientService' import DOMPurify from 'dompurify' +import { useConfigurationManager } from '../../configuration' export const useFileActionsOpenShortcut = ({ store }: { store?: Store } = {}) => { const router = useRouter() @@ -20,6 +21,7 @@ export const useFileActionsOpenShortcut = ({ store }: { store?: Store } = { const isFilesAppActive = useIsFilesAppActive() const isSearchActive = useIsSearchActive() const clientService = useClientService() + const configurationManger = useConfigurationManager() const extractUrl = (fileContents: string) => { const regex = /URL=(.+)/ @@ -39,6 +41,10 @@ export const useFileActionsOpenShortcut = ({ store }: { store?: Store } = { // Omit possible xss code const sanitizedUrl = DOMPurify.sanitize(url, { USE_PROFILES: { html: true } }) + if (sanitizedUrl.startsWith(configurationManger.serverUrl)) { + return (window.location.href = sanitizedUrl) + } + window.open(sanitizedUrl) } catch (e) { console.error(e) From 7d9f94c8982735eed312684e5ff443e916464e10 Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Thu, 2 Nov 2023 21:12:53 +0100 Subject: [PATCH 03/25] add more tests --- .../files/useFileActionsOpenShortcut.spec.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts b/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts index f9faff51f8b..2aed42db181 100644 --- a/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts +++ b/packages/web-pkg/tests/unit/composables/actions/files/useFileActionsOpenShortcut.spec.ts @@ -7,7 +7,7 @@ import { RouteLocation, getComposableWrapper } from 'web-test-helpers' -import { useFileActionsOpenShortcut, useRoute } from '../../../../../src' +import { ConfigurationManager, useFileActionsOpenShortcut, useRoute } from '../../../../../src' import { Resource } from '@ownclouders/web-client' import { GetFileContentsResponse } from '@ownclouders/web-client/src/webdav/getFileContents' @@ -16,6 +16,13 @@ jest.mock('../../../../../src/composables/router', () => ({ useRoute: jest.fn() })) +jest.mock('../../../../../src/composables/configuration', () => ({ + useConfigurationManager: () => + mock({ + serverUrl: 'https://demo.owncloud.com' + }) +})) + window = Object.create(window) Object.defineProperty(window, 'location', { value: { @@ -68,6 +75,18 @@ describe('openShortcut', () => { } }) }) + it('opens the url in the same window if url links to OCIS instance', () => { + getWrapper({ + getFileContentsValue: '[InternetShortcut]\nURL=https://demo.owncloud.com', + setup: async ({ actions }) => { + await unref(actions)[0].handler({ + resources: [mock()], + space: null + }) + expect(window.location.href).toBe('https://demo.owncloud.com') + } + }) + }) }) }) describe('method "extractUrl"', () => { From 3a845fc90943f83da244ee61dba927cbaf2e50bc Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Fri, 3 Nov 2023 11:56:47 +0100 Subject: [PATCH 04/25] add drop --- .../src/components/CreateShortcutModal.vue | 85 +++++++++++++++++-- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/packages/web-pkg/src/components/CreateShortcutModal.vue b/packages/web-pkg/src/components/CreateShortcutModal.vue index 37e69132643..1c49219d4a0 100644 --- a/packages/web-pkg/src/components/CreateShortcutModal.vue +++ b/packages/web-pkg/src/components/CreateShortcutModal.vue @@ -9,8 +9,34 @@ @confirm="createShortcut" >