Poll votes accept any sessionId from the client, so one session can vote in another

未关闭 适合新手
#251 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
security

调研方向

阅读 apps/ws-server/src/utils/handleMessages.ts 中的 poll:vote 分支,以及 apps/ws-server/src/utils/handleMessages.poll.test.ts 中的相关测试。检查处理程序如何获取会话 ID 和参与者 ID,然后运行投票处理程序测试。完成标准是投票使用套接字的会话 ID 和参与者 ID,并且测试覆盖外部 ID。

由索引模型根据 Issue 内容生成。

描述

bug level3 nsoc26

What happens

poll:vote is the only poll handler that does not check the socket's own session. Every other one calls authorizeOrganizerAction, which binds the action to client.sessionId. The vote handler reads sessionId straight out of the message payload:

// apps/ws-server/src/utils/handleMessages.ts
case 'poll:vote': {
    const { sessionId, pollId, optionId, participantId } = payload;
    const voterId = client.participantId || participantId;
    if (!voterId || !sessionId || !pollId || !optionId) break;

    const result = votePoll(sessionId, pollId, optionId, voterId);

Compare with the helper every other poll handler uses:

// apps/ws-server/src/utils/organizerAuth.ts
if (payload?.sessionId && payload.sessionId !== client.sessionId) {
    sendError(client, "SESSION_MISMATCH", "This message is for a different session.");
    return null;
}

Why it matters

A participant joined to session A can send poll:vote with session B's id. If they can guess or observe a poll id in another session, their vote lands there. votePoll looks the poll up purely by the payload's sessionId and never asks whether the socket belongs to it.

The vote also broadcasts to the other session, so participants in B see a vote count move for someone who was never in the room.

Reproducing

  1. Join session A as a participant
  2. Have a host start a poll in session B, note its pollId and sessionId (both are in the poll:started broadcast to B's participants)
  3. From A's socket send { type: 'poll:vote', payload: { sessionId: B, pollId: B's poll, optionId: ..., participantId: <A's id> } }
  4. The vote is counted in B

The fix

Use the socket's own session, the same as every other handler:

case 'poll:vote': {
    if (!client.sessionId || !client.participantId) break;
    const { pollId, optionId } = payload;
    if (!pollId || !optionId) break;

    const result = votePoll(client.sessionId, pollId, optionId, client.participantId);

Note the second half: client.participantId || participantId also lets a client supply someone else's participant id when the socket has none, which both ballot-stuffs and overwrites another player's vote. The id should come only from the socket, which is set at join time.

A test in apps/ws-server/src/utils/handleMessages.poll.test.ts should cover both: a vote with a foreign sessionId is refused, and a vote with a foreign participantId is attributed to the socket's own participant.

Files

  • apps/ws-server/src/utils/handleMessages.ts — the poll:vote case
  • apps/ws-server/src/utils/handleMessages.poll.test.ts — tests
主要语言
TypeScript
星标
21
派生
7
平均合并
11 小时 14 分钟
30 天内合并 PR
30

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TheCodeHeist-Coder/Rexial 的其他 Issue

查看 TheCodeHeist-Coder/Rexial 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。