Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(shared-video): run whitelisted urls through store
Calin-Teodore9ca4b009af7
diff --git a/config.js b/config.jsindex 741f047bb1..43560bccb7 100644--- a/config.js+++ b/config.js@@ -1443,6 +1443,9 @@ var config = {*/// dynamicBrandingUrl: '',+ // Own url domains list added to the white listed domains for shared video+ // ownVideoURLDomains: [ '' ],+// Options related to the participants pane.// participantsPane: {// // Enables featurediff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex 6a183e8ca9..a1bf904f7f 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -456,6 +456,7 @@ export interface IConfig {notifications?: Array<string>;openSharedDocumentOnJoin?: boolean;opusMaxAverageBitrate?: number;+ ownVideoURLDomains?: Array<string>;p2p?: {backToP2PDelay?: number;codecPreferenceOrder?: Array<string>;diff --git a/react/features/dynamic-branding/reducer.ts b/react/features/dynamic-branding/reducer.tsindex ab668f3e1c..7935ffa280 100644--- a/react/features/dynamic-branding/reducer.ts+++ b/react/features/dynamic-branding/reducer.ts@@ -158,6 +158,7 @@ export interface IDynamicBrandingState {muiBrandedTheme?: boolean;premeetingBackground: string;showGiphyIntegration?: boolean;+ urlWhitelist?: Array<string>useDynamicBrandingData: boolean;virtualBackgrounds: Array<Image>;}@@ -182,6 +183,7 @@ ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STAmuiBrandedTheme,premeetingBackground,showGiphyIntegration,+ urlWhitelist,virtualBackgrounds} = action.value;@@ -201,6 +203,7 @@ ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STAshowGiphyIntegration,customizationFailed: false,customizationReady: true,+ urlWhitelist,useDynamicBrandingData: true,virtualBackgrounds: formatImages(virtualBackgrounds || [])};diff --git a/react/features/shared-video/actionTypes.ts b/react/features/shared-video/actionTypes.tsindex fcbab71fae..ec8ac7351c 100644--- a/react/features/shared-video/actionTypes.ts+++ b/react/features/shared-video/actionTypes.ts@@ -28,3 +28,12 @@ export const RESET_SHARED_VIDEO_STATUS = 'RESET_SHARED_VIDEO_STATUS';* }*/export const SET_DISABLE_BUTTON = 'SET_DISABLE_BUTTON';++/**+ * The type of the action which sets an array of whitelisted urls.+ *+ * {+ * type: SET_URL_WHITELIST+ * }+ */+export const SET_URL_WHITELIST = 'SET_URL_WHITELIST';diff --git a/react/features/shared-video/actions.any.ts b/react/features/shared-video/actions.any.tsindex 26ed62ff2e..6b6002b4bd 100644--- a/react/features/shared-video/actions.any.ts+++ b/react/features/shared-video/actions.any.ts@@ -3,7 +3,7 @@ import { getCurrentConference } from '../base/conference/functions';import { openDialog } from '../base/dialog/actions';import { getLocalParticipant } from '../base/participants/functions';-import { RESET_SHARED_VIDEO_STATUS, SET_SHARED_VIDEO_STATUS } from './actionTypes';+import {RESET_SHARED_VIDEO_STATUS, SET_SHARED_VIDEO_STATUS, SET_URL_WHITELIST} from './actionTypes';import { SharedVideoDialog } from './components';import { isSharedVideoEnabled, isURLAllowedForSharedVideo } from './functions';@@ -90,7 +90,7 @@ export function stopSharedVideo() {*/export function playSharedVideo(videoUrl: string) {return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {- if (!isSharedVideoEnabled(getState()) || !isURLAllowedForSharedVideo(videoUrl)) {+ if (!isSharedVideoEnabled(getState()) || !isURLAllowedForSharedVideo(getState(), videoUrl)) {return;}const conference = getCurrentConference(getState());@@ -126,3 +126,17 @@ export function toggleSharedVideo() {}};}++/**+ * Resets the status of the shared video.+ *+ * @returns {{+ * type: SET_SHARED_VIDEO_STATUS,+ * }}+ */+export function setUrlWhitelist(urlWhitelist: Array<string>) {+ return {+ type: SET_URL_WHITELIST,+ urlWhitelist+ };+}diff --git a/react/features/shared-video/functions.ts b/react/features/shared-video/functions.tsindex eeeada86db..9e052aca55 100644--- a/react/features/shared-video/functions.ts+++ b/react/features/shared-video/functions.ts@@ -107,9 +107,11 @@ export function extractYoutubeIdOrURL(input: string) {*/export function isSharedVideoEnabled(stateful: IStateful) {const state = toState(stateful);++ const { urlWhitelist } = toState(stateful)['features/shared-video'];const { disableThirdPartyRequests = false } = state['features/base/config'];- return !disableThirdPartyRequests && URL_WHITELIST.length > 0;+ return !disableThirdPartyRequests && urlWhitelist.length > 0;}/**@@ -124,10 +126,14 @@ export function areYoutubeURLsAllowedForSharedVideo() {/*** Returns true if the passed url is allowed to be used for shared video or not.*+ * @param {IStateful} stateful - The redux store, state, or+ * {@code getState} function.* @param {string} url - The URL.* @returns {boolean}*/-export function isURLAllowedForSharedVideo(url: string) {+export function isURLAllowedForSharedVideo(stateful: IStateful, url: string) {+ const { urlWhitelist } = toState(stateful)['features/shared-video'];+if (!url) {return false;}@@ -136,10 +142,10 @@ export function isURLAllowedForSharedVideo(url: string) {const urlObject = new URL(url);if ([ 'http:', 'https:' ].includes(urlObject?.protocol?.toLowerCase())) {- return URL_WHITELIST.includes(urlObject?.hostname);+ return urlWhitelist?.includes(urlObject?.hostname);}- } catch (_e) { // it should be youtube id.- return areYoutubeURLsAllowedForSharedVideo();+ } catch (_e) { // it should be YouTube id.+ return urlWhitelist?.includes(YOUTUBE_URL_DOMAIN);}return false;diff --git a/react/features/shared-video/middleware.any.ts b/react/features/shared-video/middleware.any.tsindex 6c31ff4a31..909d53ec60 100644--- a/react/features/shared-video/middleware.any.ts+++ b/react/features/shared-video/middleware.any.ts@@ -45,7 +45,7 @@ MiddlewareRegistry.register(store => next => action => {({ value, attributes }: { attributes: {from: string; muted: string; state: string; time: string; }; value: string; }) => {- if (!isURLAllowedForSharedVideo(value)) {+ if (!isURLAllowedForSharedVideo(state, value)) {logger.debug(`Shared Video: Received a not allowed URL ${value}`);return;diff --git a/react/features/shared-video/reducer.ts b/react/features/shared-video/reducer.tsindex eb1ff1240a..8fe0b507a8 100644--- a/react/features/shared-video/reducer.ts+++ b/react/features/shared-video/reducer.ts@@ -1,6 +1,7 @@import ReducerRegistry from '../base/redux/ReducerRegistry';-import { RESET_SHARED_VIDEO_STATUS, SET_DISABLE_BUTTON, SET_SHARED_VIDEO_STATUS } from './actionTypes';+import {RESET_SHARED_VIDEO_STATUS, SET_DISABLE_BUTTON, SET_SHARED_VIDEO_STATUS, SET_URL_WHITELIST} from './actionTypes';+import {YOUTUBE_URL_DOMAIN} from "./constants";const initialState = {};@@ -12,6 +13,7 @@ export interface ISharedVideoState {time?: number;videoUrl?: string;volume?: number;+ urlWhitelist?: Array<string>}/**@@ -41,6 +43,13 @@ ReducerRegistry.register<ISharedVideoState>('features/shared-video',disabled};+ case SET_URL_WHITELIST: {+ return {+ ...state,+ urlWhitelist: [ YOUTUBE_URL_DOMAIN, ...action.urlWhitelist ]+ }+ }+default:return state;}