Skip to content

Commit

Permalink
fix(ui): validate application url and service external urls
Browse files Browse the repository at this point in the history
  • Loading branch information
sct committed Feb 4, 2021
1 parent ee0a7bd commit 026795d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
4 changes: 0 additions & 4 deletions server/api/externalapi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import NodeCache from 'node-cache';
import logger from '../logger';

// 5 minute default TTL (in seconds)
const DEFAULT_TTL = 300;
Expand Down Expand Up @@ -66,9 +65,6 @@ class ExternalAPI {

if (cachedItem) {
const keyTtl = this.cache?.getTtl(cacheKey) ?? 0;
logger.debug(`Loaded item from cache: ${cacheKey}`, {
keyTtl,
});

// If the item has passed our rolling check, fetch again in background
if (
Expand Down
14 changes: 14 additions & 0 deletions src/components/Settings/RadarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const messages = defineMessages({
loadingrootfolders: 'Loading root folders…',
testFirstRootFolders: 'Test connection to load root folders',
preventSearch: 'Disable Auto-Search',
validationApplicationUrl: 'You must provide a valid URL',
validationApplicationUrlTrailingSlash: 'URL must not end in a trailing slash',
});

interface TestResponse {
Expand Down Expand Up @@ -105,6 +107,18 @@ const RadarrModal: React.FC<RadarrModalProps> = ({
minimumAvailability: Yup.string().required(
intl.formatMessage(messages.validationMinimumAvailabilityRequired)
),
externalUrl: Yup.string()
.url(intl.formatMessage(messages.validationApplicationUrl))
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
(value) => {
if (value?.substr(value.length - 1) === '/') {
return false;
}
return true;
}
),
});

const testConnection = useCallback(
Expand Down
17 changes: 17 additions & 0 deletions src/components/Settings/SettingsMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const messages = defineMessages({
'Allows Overseerr to correctly register client IP addresses behind a proxy (Overseerr must be reloaded for changes to take effect)',
localLogin: 'Enable Local User Sign-In',
validationApplicationTitle: 'You must provide an application title',
validationApplicationUrl: 'You must provide a valid URL',
validationApplicationUrlTrailingSlash: 'URL must not end in a trailing slash',
});

const SettingsMain: React.FC = () => {
Expand All @@ -52,6 +54,18 @@ const SettingsMain: React.FC = () => {
applicationTitle: Yup.string().required(
intl.formatMessage(messages.validationApplicationTitle)
),
applicationUrl: Yup.string()
.url(intl.formatMessage(messages.validationApplicationUrl))
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
(value) => {
if (value?.substr(value.length - 1) === '/') {
return false;
}
return true;
}
),
});

const regenerate = async () => {
Expand Down Expand Up @@ -200,6 +214,9 @@ const SettingsMain: React.FC = () => {
placeholder="https://os.example.com"
/>
</div>
{errors.applicationUrl && touched.applicationUrl && (
<div className="error">{errors.applicationUrl}</div>
)}
</div>
</div>
<div className="form-row">
Expand Down
14 changes: 14 additions & 0 deletions src/components/Settings/SonarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const messages = defineMessages({
externalUrl: 'External URL',
externalUrlPlaceholder: 'External URL pointing to your Sonarr server',
preventSearch: 'Disable Auto-Search',
validationApplicationUrl: 'You must provide a valid URL',
validationApplicationUrlTrailingSlash: 'URL must not end in a trailing slash',
});

interface TestResponse {
Expand Down Expand Up @@ -102,6 +104,18 @@ const SonarrModal: React.FC<SonarrModalProps> = ({
activeProfileId: Yup.string().required(
intl.formatMessage(messages.validationProfileRequired)
),
externalUrl: Yup.string()
.url(intl.formatMessage(messages.validationApplicationUrl))
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
(value) => {
if (value?.substr(value.length - 1) === '/') {
return false;
}
return true;
}
),
});

const testConnection = useCallback(
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@
"components.Settings.RadarrModal.toastRadarrTestFailure": "Failed to connect to Radarr.",
"components.Settings.RadarrModal.toastRadarrTestSuccess": "Radarr connection established!",
"components.Settings.RadarrModal.validationApiKeyRequired": "You must provide an API key",
"components.Settings.RadarrModal.validationApplicationUrl": "You must provide a valid URL",
"components.Settings.RadarrModal.validationApplicationUrlTrailingSlash": "URL must not end in a trailing slash",
"components.Settings.RadarrModal.validationHostnameRequired": "You must provide a hostname/IP",
"components.Settings.RadarrModal.validationMinimumAvailabilityRequired": "You must select a minimum availability",
"components.Settings.RadarrModal.validationNameRequired": "You must provide a server name",
Expand Down Expand Up @@ -409,6 +411,8 @@
"components.Settings.SonarrModal.toastSonarrTestFailure": "Failed to connect to Sonarr.",
"components.Settings.SonarrModal.toastSonarrTestSuccess": "Sonarr connection established!",
"components.Settings.SonarrModal.validationApiKeyRequired": "You must provide an API key",
"components.Settings.SonarrModal.validationApplicationUrl": "You must provide a valid URL",
"components.Settings.SonarrModal.validationApplicationUrlTrailingSlash": "URL must not end in a trailing slash",
"components.Settings.SonarrModal.validationHostnameRequired": "You must provide a hostname/IP",
"components.Settings.SonarrModal.validationNameRequired": "You must provide a server name",
"components.Settings.SonarrModal.validationPortRequired": "You must provide a port",
Expand Down Expand Up @@ -502,6 +506,8 @@
"components.Settings.trustProxy": "Enable Proxy Support",
"components.Settings.trustProxyTip": "Allows Overseerr to correctly register client IP addresses behind a proxy (Overseerr must be reloaded for changes to take effect)",
"components.Settings.validationApplicationTitle": "You must provide an application title",
"components.Settings.validationApplicationUrl": "You must provide a valid URL",
"components.Settings.validationApplicationUrlTrailingSlash": "URL must not end in a trailing slash",
"components.Settings.validationHostnameRequired": "You must provide a hostname/IP",
"components.Settings.validationPortRequired": "You must provide a port",
"components.Setup.configureplex": "Configure Plex",
Expand Down

0 comments on commit 026795d

Please sign in to comment.