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

Đang mở Phù hợp với người mới
#251 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
86/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
security

Hướng nghiên cứu

Đọc trường hợp poll:vote trong apps/ws-server/src/utils/handleMessages.ts và các bài kiểm tra trong apps/ws-server/src/utils/handleMessages.poll.test.ts. Kiểm tra cách handler lấy ID phiên và ID người tham gia, sau đó chạy các bài kiểm tra của handler thăm dò ý kiến. Công việc hoàn tất khi phiếu bầu sử dụng ID phiên và ID người tham gia của socket, đồng thời các bài kiểm tra bao quát những ID không thuộc về socket.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
TypeScript
Star
21
Fork
7
Merge trung bình
11 giờ 14 phút
Pull request đã merge (30 ngày)
30

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TheCodeHeist-Coder/Rexial

Tất cả issue của TheCodeHeist-Coder/Rexial

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.