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
fix(gif): Restrict gif rendering to Giphy only
Hristo Terezov200228339be8
diff --git a/react/features/base/react/components/web/Message.tsx b/react/features/base/react/components/web/Message.tsxindex 36f58f700b..170cabcbf6 100644--- a/react/features/base/react/components/web/Message.tsx+++ b/react/features/base/react/components/web/Message.tsx@@ -1,14 +1,21 @@import React, { Component, ReactNode } from 'react';import { toArray } from 'react-emoji-render';+import { connect } from 'react-redux';+import { IReduxState } from '../../../../app/types';import GifMessage from '../../../../chat/components/web/GifMessage';import { GIF_PREFIX } from '../../../../gifs/constants';-import { isGifMessage } from '../../../../gifs/functions.web';+import { isGifEnabled, isGifMessage } from '../../../../gifs/functions.web';import Linkify from './Linkify';interface IProps {+ /**+ * Whether the gifs are enabled or not.+ */+ gifEnabled: boolean;+/*** The body of the message.*/@@ -43,11 +50,11 @@ class Message extends Component<IProps> {// Tokenize the text in order to avoid emoji substitution for URLsconst tokens = text ? text.split(' ') : [];-const content = [];+ const { gifEnabled } = this.props;// check if the message is a GIF- if (isGifMessage(text)) {+ if (gifEnabled && isGifMessage(text)) {const url = text.substring(GIF_PREFIX.length, text.length - 1);content.push(<GifMessage@@ -93,4 +100,16 @@ class Message extends Component<IProps> {}}-export default Message;+/**+ * Maps part of the redux state to the props of this component.+ *+ * @param {IReduxState} state - The Redux state.+ * @returns {IProps}+ */+function _mapStateToProps(state: IReduxState) {+ return {+ gifEnabled: isGifEnabled(state)+ };+}++export default connect(_mapStateToProps)(Message);diff --git a/react/features/chat/components/native/ChatMessage.tsx b/react/features/chat/components/native/ChatMessage.tsxindex 9df888b85b..696b78b62d 100644--- a/react/features/chat/components/native/ChatMessage.tsx+++ b/react/features/chat/components/native/ChatMessage.tsx@@ -6,7 +6,7 @@ import { IReduxState } from '../../../app/types';import Avatar from '../../../base/avatar/components/Avatar';import { translate } from '../../../base/i18n/functions';import Linkify from '../../../base/react/components/native/Linkify';-import { isGifMessage } from '../../../gifs/functions.native';+import { isGifEnabled, isGifMessage } from '../../../gifs/functions.native';import { CHAR_LIMIT, MESSAGE_TYPE_ERROR, MESSAGE_TYPE_LOCAL } from '../../constants';import {getCanReplyToMessage,@@ -32,7 +32,7 @@ class ChatMessage extends Component<IChatMessageProps> {* @inheritdoc*/render() {- const { message, knocking } = this.props;+ const { gifEnabled, message, knocking } = this.props;const localMessage = message.messageType === MESSAGE_TYPE_LOCAL;const { privateMessage, lobbyChat } = message;@@ -82,7 +82,7 @@ class ChatMessage extends Component<IChatMessageProps> {<View style = { messageBubbleStyle }><View style = { styles.textWrapper as ViewStyle } >{ this._renderDisplayName() }- { isGifMessage(messageText)+ { gifEnabled && isGifMessage(messageText)? <GifMessage message = { messageText } />: this._renderMessageTextComponent(messageText) }{ this._renderPrivateNotice() }@@ -232,6 +232,7 @@ class ChatMessage extends Component<IChatMessageProps> {function _mapStateToProps(state: IReduxState, { message }: IChatMessageProps) {return {canReply: getCanReplyToMessage(state, message),+ gifEnabled: isGifEnabled(state),knocking: state['features/lobby'].knocking};}diff --git a/react/features/chat/middleware.ts b/react/features/chat/middleware.tsindex 0c50614dcc..22b55c221d 100644--- a/react/features/chat/middleware.ts+++ b/react/features/chat/middleware.ts@@ -25,7 +25,7 @@ import StateListenerRegistry from '../base/redux/StateListenerRegistry';import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';import { addGif } from '../gifs/actions';import { GIF_PREFIX } from '../gifs/constants';-import { getGifDisplayMode, isGifMessage } from '../gifs/function.any';+import { getGifDisplayMode, isGifEnabled, isGifMessage } from '../gifs/function.any';import { showMessageNotification } from '../notifications/actions';import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';import { resetNbUnreadPollsMessages } from '../polls/actions';@@ -322,7 +322,7 @@ function _onConferenceMessageReceived(store: IStore,participantId: string; privateMessage: boolean; timestamp: number; }) {- const isGif = isGifMessage(message);+ const isGif = isGifEnabled(store.getState()) && isGifMessage(message);if (isGif) {_handleGifMessageReceived(store, participantId, message);diff --git a/react/features/chat/types.ts b/react/features/chat/types.tsindex a50fb312a7..4290ff287a 100644--- a/react/features/chat/types.ts+++ b/react/features/chat/types.ts@@ -44,6 +44,11 @@ export interface IChatMessageProps extends WithTranslation {*/canReply?: boolean;+ /**+ * Whether gifs are enabled or not.+ */+ gifEnabled?: boolean;+/*** Whether current participant is currently knocking in the lobby room.*/diff --git a/react/features/gifs/function.any.ts b/react/features/gifs/function.any.tsindex 066fcaa889..b530b83c72 100644--- a/react/features/gifs/function.any.ts+++ b/react/features/gifs/function.any.ts@@ -45,6 +45,26 @@ export function getGifForParticipant(state: IReduxState, participantId: string):return isGifEnabled(state) ? state['features/gifs'].gifList.get(participantId) || {} : {};}+/**+ * Returns true if a given URL is allowed to be rendered as gif and false otherwise.+ *+ * @param {string} url - The URL to be validated.+ * @returns {boolean} - True if a given URL is allowed to be rendered as gif and false otherwise.+ */+export function isGifUrlAllowed(url: string) {+ let hostname: string | undefined;++ try {+ const urlObject = new URL(url);++ hostname = urlObject?.hostname;+ } catch (_error) {+ return false;+ }++ return hostname === 'i.giphy.com';+}+/*** Whether or not the message is a GIF message.*@@ -52,8 +72,10 @@ export function getGifForParticipant(state: IReduxState, participantId: string):* @returns {boolean}*/export function isGifMessage(message: string) {+ const url = message.substring(GIF_PREFIX.length, message.length - 1);+return message.trim().toLowerCase()- .startsWith(GIF_PREFIX);+ .startsWith(GIF_PREFIX) && isGifUrlAllowed(url);}/**