From b557f04c1032d422598fd8e5b2df6848d75e7f9f Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 24 Jul 2023 21:25:41 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20non=20standard=20protocols?= =?UTF-8?q?=20for=20ext=20app=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/locales/en/layout/modals/add-app.json | 3 ++- .../Dashboard/Modals/EditAppModal/EditAppModal.tsx | 7 +++++-- .../EditAppModal/Tabs/GeneralTab/GeneralTab.tsx | 14 ++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/public/locales/en/layout/modals/add-app.json b/public/locales/en/layout/modals/add-app.json index 551f84dad95..bed0d06301a 100644 --- a/public/locales/en/layout/modals/add-app.json +++ b/public/locales/en/layout/modals/add-app.json @@ -24,7 +24,8 @@ "isOpeningNewTab": { "label": "Open in new tab", "description": "Open the app in a new tab instead of the current one." - } + }, + "customProtocolWarning": "Using a non-standard protocol. This may require pre-installed applications and can introduce security risks. Ensure that your address is secure and trusted." }, "network": { "statusChecker": { diff --git a/src/components/Dashboard/Modals/EditAppModal/EditAppModal.tsx b/src/components/Dashboard/Modals/EditAppModal/EditAppModal.tsx index c2dfa21f5f7..a618f6d2edd 100644 --- a/src/components/Dashboard/Modals/EditAppModal/EditAppModal.tsx +++ b/src/components/Dashboard/Modals/EditAppModal/EditAppModal.tsx @@ -28,6 +28,9 @@ import { EditAppModalTab } from './Tabs/type'; const appUrlRegex = '(https?://(?:www.|(?!www))\\[?[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\]?.[^\\s]{2,}|www.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9].[^\\s]{2,}|https?://(?:www.|(?!www))\\[?[a-zA-Z0-9]+\\]?.[^\\s]{2,}|www.[a-zA-Z0-9]+.[^\\s]{2,})'; +const appUrlWithAnyProtocolRegex = + '([A-z]+://(?:www.|(?!www))\\[?[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\]?.[^\\s]{2,}|www.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9].[^\\s]{2,}|[A-z]+://(?:www.|(?!www))\\[?[a-zA-Z0-9]+\\]?.[^\\s]{2,}|www.[a-zA-Z0-9]+.[^\\s]{2,})'; + export const EditAppModal = ({ context, id, @@ -71,8 +74,8 @@ export const EditAppModal = ({ return null; } - if (!url.match(appUrlRegex)) { - return 'Uri override is not a valid uri'; + if (!url.match(appUrlWithAnyProtocolRegex)) { + return 'External URI is not a valid uri'; } return null; diff --git a/src/components/Dashboard/Modals/EditAppModal/Tabs/GeneralTab/GeneralTab.tsx b/src/components/Dashboard/Modals/EditAppModal/Tabs/GeneralTab/GeneralTab.tsx index fd5c2ea05a0..6bbc40a7b59 100644 --- a/src/components/Dashboard/Modals/EditAppModal/Tabs/GeneralTab/GeneralTab.tsx +++ b/src/components/Dashboard/Modals/EditAppModal/Tabs/GeneralTab/GeneralTab.tsx @@ -1,4 +1,4 @@ -import { Tabs, TextInput } from '@mantine/core'; +import { Tabs, Text, TextInput } from '@mantine/core'; import { UseFormReturnType } from '@mantine/form'; import { IconClick, IconCursorText, IconLink } from '@tabler/icons-react'; import { useTranslation } from 'next-i18next'; @@ -22,6 +22,7 @@ export const GeneralTab = ({ form, openTab }: GeneralTabProps) => { placeholder="My example app" variant="default" withAsterisk + mb="md" {...form.getInputProps('name')} /> { placeholder="https://google.com" variant="default" withAsterisk + mb="md" {...form.getInputProps('url')} - onChange={(e) => { - form.setFieldValue('url', e.target.value); - }} /> } @@ -44,6 +43,13 @@ export const GeneralTab = ({ form, openTab }: GeneralTabProps) => { variant="default" {...form.getInputProps('behaviour.externalUrl')} /> + + {!form.values.behaviour.externalUrl.startsWith('https://') && + !form.values.behaviour.externalUrl.startsWith('http://') && ( + + {t('behaviour.customProtocolWarning')} + + )} ); };