feature: check if url is whitelisted

This commit is contained in:
Timothy Z. 2024-09-26 12:28:48 +03:00
parent c5b20800c0
commit 4173fca28c
2 changed files with 19 additions and 3 deletions

View file

@ -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,
};

View file

@ -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,
};
};