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(polls) more resilient parsing of payloads, take 2
Saúl Ibarra Corretgéc639acebcf25
diff --git a/react/features/polls/logger.ts b/react/features/polls/logger.tsnew file mode 100644index 0000000000..7d418c1e97--- /dev/null+++ b/react/features/polls/logger.ts@@ -0,0 +1,3 @@+import { getLogger } from '../base/logging/functions';++export default getLogger('features/polls');diff --git a/react/features/polls/middleware.ts b/react/features/polls/middleware.tsindex 6fa77d00b1..f6d253d6b4 100644--- a/react/features/polls/middleware.ts+++ b/react/features/polls/middleware.ts@@ -16,6 +16,7 @@ import {COMMAND_NEW_POLL,COMMAND_OLD_POLLS} from './constants';+import logger from './logger';import { IAnswer, IPoll, IPollData } from './types';/**@@ -43,7 +44,16 @@ const parsePollData = (pollData: Partial<IPollData>): IPoll | null => {const { id, senderId, question, answers } = pollData;if (typeof id !== 'string' || typeof senderId !== 'string'- || typeof question !== 'string' || !(answers instanceof Array)) {+ || typeof question !== 'string' || !(answers instanceof Array)) {+ logger.error('Malformed poll data received:', pollData);++ return null;+ }++ // Validate answers.+ if (answers.some(answer => typeof answer !== 'string')) {+ logger.error('Malformed answers data received:', answers);+return null;}@@ -173,7 +183,7 @@ function _handleReceivePollsMessage(data: any, dispatch: IStore['dispatch'], getconst receivedAnswer: IAnswer = {voterId,pollId,- answers: answers.slice(0, MAX_ANSWERS)+ answers: answers.slice(0, MAX_ANSWERS).map(Boolean)};dispatch(receiveAnswer(pollId, receivedAnswer));@@ -188,7 +198,7 @@ function _handleReceivePollsMessage(data: any, dispatch: IStore['dispatch'], getconst poll = parsePollData(pollData);if (poll === null) {- console.warn('[features/polls] Invalid old poll data');+ logger.warn('Malformed old poll data', pollData);} else {dispatch(receivePoll(pollData.id, poll, false));}