Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(polls): validate answer structure from participants

damenchodd3463654448
diff --git a/react/features/polls/components/AbstractPollResults.tsx b/react/features/polls/components/AbstractPollResults.tsx
index 0355aeb2c3..70ea8d18bb 100644
--- a/react/features/polls/components/AbstractPollResults.tsx
+++ b/react/features/polls/components/AbstractPollResults.tsx
@@ -68,14 +68,17 @@ const AbstractPollResults = (Component: ComponentType<AbstractProps>) => (props:
// Getting every voters ID that participates to the poll
for (const answer of poll.answers) {
- answer.voters?.forEach(k => allVoters.add(k.id));
+ const answerVoters = Array.isArray(answer.voters) ? answer.voters : undefined;
+
+ answerVoters?.forEach(k => allVoters.add(k.id));
}
return poll.answers.map(answer => {
- const nrOfVotersPerAnswer = answer.voters?.length || 0;
+ const answerVoters = Array.isArray(answer.voters) ? answer.voters : undefined;
+ const nrOfVotersPerAnswer = answerVoters?.length || 0;
const percentage = allVoters.size > 0 ? Math.round(nrOfVotersPerAnswer / allVoters.size * 100) : 0;
- const voters = answer.voters?.reduce((acc, v) => {
+ const voters = answerVoters?.reduce((acc, v) => {
acc.push({
id: v.id,
name: getParticipantById(reduxState, v.id)
diff --git a/react/features/polls/middleware.ts b/react/features/polls/middleware.ts
index 9063580223..e5943f28ca 100644
--- a/react/features/polls/middleware.ts
+++ b/react/features/polls/middleware.ts
@@ -12,13 +12,33 @@ import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../notifications/c
import { RECEIVE_POLL } from './actionTypes';
import { clearPolls, receiveAnswer, receivePoll } from './actions';
-import { IIncomingAnswerData } from './types';
+import { IAnswerData, IIncomingAnswerData } from './types';
/**
* The maximum number of answers a poll can have.
*/
const MAX_ANSWERS = 32;
+/**
+ * Normalizes the answers received for a poll, keeping only the expected fields
+ * and shapes. Answers arrive from remote participants and cannot be trusted to
+ * match the expected structure, so we coerce the name to a string and only keep
+ * voters when it is an array.
+ *
+ * @param {any} answers - The raw answers array carried by the polls message.
+ * @returns {Array<IAnswerData>}
+ */
+function _sanitizeAnswers(answers: any): Array<IAnswerData> {
+ if (!Array.isArray(answers)) {
+ return [];
+ }
+
+ return answers.slice(0, MAX_ANSWERS).map((answer: any) => ({
+ name: String(answer?.name ?? ''),
+ voters: Array.isArray(answer?.voters) ? answer.voters : undefined
+ }));
+}
+
/**
* Set up state change listener to perform maintenance tasks when the conference
* is left or failed, e.g. Clear messages or close the chat modal if it's left
@@ -89,7 +109,7 @@ function _handleReceivedPollsData(data: any, dispatch: IStore['dispatch'], getSt
showResults: false,
lastVote: null,
question,
- answers: answers.slice(0, MAX_ANSWERS),
+ answers: _sanitizeAnswers(answers),
saved: false,
editing: false,
pollId
diff --git a/react/features/polls/reducer.ts b/react/features/polls/reducer.ts
index 3ed3a75cd4..5a2f64e801 100644
--- a/react/features/polls/reducer.ts
+++ b/react/features/polls/reducer.ts
@@ -12,7 +12,7 @@ import {
SAVE_POLL
} from './actionTypes';
import logger from './logger';
-import { IIncomingAnswerData, IPollData } from './types';
+import { IIncomingAnswerData, IPollData, IVoterData } from './types';
const INITIAL_STATE = {
polls: {},
@@ -96,7 +96,7 @@ ReducerRegistry.register<IPollsState>(STORE_NAME, (state = INITIAL_STATE, action
// if the poll exists, we update it with the incoming answer
for (let i = 0; i < poll.answers.length; i++) {
// if the answer was chosen, we add the senderId to the array of voters of this answer
- let voters = poll.answers[i].voters || [];
+ let voters = Array.isArray(poll.answers[i].voters) ? poll.answers[i].voters as IVoterData[] : [];
if (voters.find(user => user.id === answer.senderId)) {
if (!answer.answers[i]) {
diff --git a/resources/prosody-plugins/mod_polls_component.lua b/resources/prosody-plugins/mod_polls_component.lua
index 8f757149a4..f51f643d5e 100644
--- a/resources/prosody-plugins/mod_polls_component.lua
+++ b/resources/prosody-plugins/mod_polls_component.lua
@@ -255,6 +255,9 @@ end
}
-- now send message to all participants
+ -- Only relay the sanitized answers (name only) so no unexpected
+ -- fields from the sender's payload are forwarded to participants.
+ data.answers = answers;
data.senderId = poll_creator.occupant_id;
data.type = 'polls';
local json_msg_str, error = json.encode(data);