diff --git a/src/common/CONSTANTS.js b/src/common/CONSTANTS.js index 742c138d6..c64c84bcd 100644 --- a/src/common/CONSTANTS.js +++ b/src/common/CONSTANTS.js @@ -93,6 +93,8 @@ const EXTERNAL_PLAYERS = [ }, ]; +const WHITELISTED_HOSTS = ['www.stremio.com', 'blog.stremio.com', 'web.stremio.com', 'web.strem.io', 'stremio.zendesk.com', 'www.google.com', 'www.youtube.com', 'www.twitch.tv', 'twitter.com', 'www.netflix.com', 'www.adex.network', 'www.amazon.com', 'docs.google.com', 'blog.stremio.com', 'forms.gle']; + module.exports = { CHROMECAST_RECEIVER_APP_ID, SUBTITLES_SIZES, @@ -110,4 +112,5 @@ module.exports = { TYPE_PRIORITIES, ICON_FOR_TYPE, EXTERNAL_PLAYERS, + WHITELISTED_HOSTS, }; diff --git a/src/common/Platform/Platform.tsx b/src/common/Platform/Platform.tsx index c93064d78..0804d512b 100644 --- a/src/common/Platform/Platform.tsx +++ b/src/common/Platform/Platform.tsx @@ -1,5 +1,6 @@ import React, { createContext, useContext } from 'react'; import useShell from './useShell'; +import { WHITELISTED_HOSTS } from 'stremio/common/CONSTANTS'; interface PlatformContext { openExternal: (url: string) => void, @@ -15,10 +16,22 @@ const PlatformProvider = ({ children }: Props) => { const shell = useShell(); const openExternal = (url: string) => { + let finalUrl = url; + try { + const parsedUrl = new URL(url); + const hostname = parsedUrl.hostname; + const isWhitelisted = WHITELISTED_HOSTS.some((host: string) => hostname === host || hostname.endsWith('.' + host)); + if (!isWhitelisted) { + finalUrl = 'https://www.stremio.com/warning#' + encodeURIComponent(url); + } + } catch (e) { + finalUrl = 'https://www.stremio.com/warning#' + encodeURIComponent(url); + } + if (shell.active) { - shell.send('open-external', url); + shell.send('open-external', finalUrl); } else { - window.open(url, '_blank'); + window.open(finalUrl, '_blank'); } }; @@ -36,4 +49,4 @@ const usePlatform = () => { export { PlatformProvider, usePlatform, -}; \ No newline at end of file +};