Skip to content

Commit

Permalink
feat(shared-video): run whitelisted urls through store
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinteodor committed Aug 26, 2024
1 parent 3441954 commit ab9a544
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 feature
Expand Down
1 change: 1 addition & 0 deletions react/features/base/config/configType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export interface IConfig {
notifications?: Array<string>;
openSharedDocumentOnJoin?: boolean;
opusMaxAverageBitrate?: number;
ownVideoURLDomains?: Array<string>;
p2p?: {
backToP2PDelay?: number;
codecPreferenceOrder?: Array<string>;
Expand Down
3 changes: 3 additions & 0 deletions react/features/dynamic-branding/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface IDynamicBrandingState {
muiBrandedTheme?: boolean;
premeetingBackground: string;
showGiphyIntegration?: boolean;
urlWhitelist?: Array<string>

Check failure on line 161 in react/features/dynamic-branding/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected a semicolon
useDynamicBrandingData: boolean;
virtualBackgrounds: Array<Image>;
}
Expand All @@ -182,6 +183,7 @@ ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STA
muiBrandedTheme,
premeetingBackground,
showGiphyIntegration,
urlWhitelist,
virtualBackgrounds
} = action.value;

Expand All @@ -201,6 +203,7 @@ ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STA
showGiphyIntegration,
customizationFailed: false,
customizationReady: true,
urlWhitelist,
useDynamicBrandingData: true,
virtualBackgrounds: formatImages(virtualBackgrounds || [])
};
Expand Down
9 changes: 9 additions & 0 deletions react/features/shared-video/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
18 changes: 16 additions & 2 deletions react/features/shared-video/actions.any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 6 in react/features/shared-video/actions.any.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 6 in react/features/shared-video/actions.any.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'
import { SharedVideoDialog } from './components';
import { isSharedVideoEnabled, isURLAllowedForSharedVideo } from './functions';

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -126,3 +126,17 @@ export function toggleSharedVideo() {
}
};
}

/**

Check failure on line 130 in react/features/shared-video/actions.any.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing JSDoc for parameter 'urlWhitelist'
* 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
};
}
16 changes: 11 additions & 5 deletions react/features/shared-video/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion react/features/shared-video/middleware.any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion react/features/shared-video/reducer.ts
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 3 in react/features/shared-video/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 3 in react/features/shared-video/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'
import {YOUTUBE_URL_DOMAIN} from "./constants";

Check failure on line 4 in react/features/shared-video/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required after '{'

Check failure on line 4 in react/features/shared-video/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'

Check failure on line 4 in react/features/shared-video/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

const initialState = {};

Expand All @@ -12,6 +13,7 @@ export interface ISharedVideoState {
time?: number;
videoUrl?: string;
volume?: number;
urlWhitelist?: Array<string>

Check failure on line 16 in react/features/shared-video/reducer.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected interface keys to be in ascending order. 'urlWhitelist' should be before 'volume'
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ab9a544

Please sign in to comment.