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): handle answers exceeding poll options (#18026)

Md Ikbal Hossain453f2f52b103
diff --git a/resources/prosody-plugins/mod_polls_component.lua b/resources/prosody-plugins/mod_polls_component.lua
index f51f643d5e..27494ddb6a 100644
--- a/resources/prosody-plugins/mod_polls_component.lua
+++ b/resources/prosody-plugins/mod_polls_component.lua
@@ -274,6 +274,12 @@ end
return;
end
+ if #data.answers ~= #poll.answers then
+ module:log("warn", "answering poll %s with mismatched answer count. Sender: %s",
+ data.pollId, stanza.attr.from);
+ return true;
+ end
+
local voter = occupant_details;
-- Capture the voter's current vote state so we can detect changes.
diff --git a/tests/prosody/mod_polls_component_spec.js b/tests/prosody/mod_polls_component_spec.js
index bd4256b6a7..e697b71c9f 100644
--- a/tests/prosody/mod_polls_component_spec.js
+++ b/tests/prosody/mod_polls_component_spec.js
@@ -364,6 +364,56 @@ describe('mod_polls_component', () => {
await assertNoPollBroadcast(creator);
});
+ it('answer-poll with a mismatched answer count is ignored', async () => {
+ const r = nextRoom();
+
+ await focusJoin(r);
+ const creator = await joinParticipant(r);
+ const other = await joinParticipant(r);
+
+ const pollId = nextPollId();
+
+ creator.createPoll(POLLS_COMPONENT, pollId, 'Pick one', [ { name: 'A' }, { name: 'B' } ]);
+ await Promise.all([
+ waitForPollCommand(creator, 'new-poll'),
+ waitForPollCommand(other, 'new-poll')
+ ]);
+
+ creator.sendPollsMessage(POLLS_COMPONENT, JSON.stringify({
+ answers: [ true, false, true ],
+ command: 'answer-poll',
+ pollId,
+ type: 'polls'
+ }));
+
+ await Promise.all([
+ assertNoPollBroadcast(creator),
+ assertNoPollBroadcast(other)
+ ]);
+
+ creator.sendPollsMessage(POLLS_COMPONENT, JSON.stringify({
+ answers: [ true ],
+ command: 'answer-poll',
+ pollId,
+ type: 'polls'
+ }));
+
+ await Promise.all([
+ assertNoPollBroadcast(creator),
+ assertNoPollBroadcast(other)
+ ]);
+
+ // The malformed votes must not mutate the stored poll state.
+ creator.answerPoll(POLLS_COMPONENT, pollId, [ true, false ]);
+ const [ answer, answerAtOther ] = await Promise.all([
+ waitForPollCommand(creator, 'answer-poll'),
+ waitForPollCommand(other, 'answer-poll')
+ ]);
+
+ assert.deepEqual(answer.answers, [ true, false ]);
+ assert.deepEqual(answerAtOther.answers, [ true, false ]);
+ });
+
it('invalid JSON is ignored cleanly', async () => {
const r = nextRoom();