Skip to content

Commit

Permalink
Merge pull request ajnart#1210 from ajnart/feat/allow-non-standard-pr…
Browse files Browse the repository at this point in the history
…otocols
  • Loading branch information
ajnart authored Jul 27, 2023
2 parents 18e0e2a + b557f04 commit ef0ac58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/layout/modals/add-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions src/components/Dashboard/Modals/EditAppModal/EditAppModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,6 +22,7 @@ export const GeneralTab = ({ form, openTab }: GeneralTabProps) => {
placeholder="My example app"
variant="default"
withAsterisk
mb="md"
{...form.getInputProps('name')}
/>
<TextInput
Expand All @@ -31,10 +32,8 @@ export const GeneralTab = ({ form, openTab }: GeneralTabProps) => {
placeholder="https://google.com"
variant="default"
withAsterisk
mb="md"
{...form.getInputProps('url')}
onChange={(e) => {
form.setFieldValue('url', e.target.value);
}}
/>
<TextInput
icon={<IconClick size={16} />}
Expand All @@ -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://') && (
<Text color="red" mt="sm" size="sm">
{t('behaviour.customProtocolWarning')}
</Text>
)}
</Tabs.Panel>
);
};

0 comments on commit ef0ac58

Please sign in to comment.