Skip to content

fix: add server-side role check on sync-elements and sync-state socket events - #131

Open
HunarBhatia wants to merge 1 commit into
KENZY004:mainfrom
HunarBhatia:fix/sync-events-role-authorization
Open

fix: add server-side role check on sync-elements and sync-state socket events#131
HunarBhatia wants to merge 1 commit into
KENZY004:mainfrom
HunarBhatia:fix/sync-events-role-authorization

Conversation

@HunarBhatia

Copy link
Copy Markdown
Contributor

Fixes #81

Problem

The sync-elements and sync-state socket events had no server-side authorization check. Any authenticated student could emit these events directly from the browser console and completely overwrite the entire board state — both in the live session and the database — bypassing the existing allowedStudents and allowStudentEditing permission system entirely.

Fix

Added a board ownership check to both events using socket.userId compared against board.createdBy:

const board = await Board.findOne({ roomId });
if (!board || board.createdBy.toString() !== socket.userId) {
  return socket.emit('error', { message: 'Unauthorized: only the board teacher can sync elements' });
}

Events Fixed

  • sync-elements — only board owner can sync full element array
  • sync-state — only board owner can sync full board state

File Changed

  • server/index.js

…t events

Fixes KENZY004#81

- sync-elements: verify socket.userId matches board.createdBy before syncing
- sync-state: verify socket.userId matches board.createdBy before syncing
- Both events now return unauthorized error to client if check fails
- Prevents students from overwriting entire board state via browser console
@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the MINHA's projects Team on Vercel.

A member of the Team first needs to authorize it.

@HunarBhatia

Copy link
Copy Markdown
Contributor Author

@KENZY004 PR submitted! Would it be possible to add relevant labels like security or bug to this issue? Also wanted to confirm — will this be counted under GSSoC '26 points once merged?

@KENZY004

KENZY004 commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Looks great overall! Just one small issue: sync-elements and sync-state are currently restricted to board.createdBy. Students with editing access (allowedStudents or allowStudentEditing) should also be allowed to sync, otherwise Undo/Redo won't work for them.

Could you update the condition to include those cases? Once that's done, I'll merge it right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Students can overwrite entire board state via unprotected sync-elements and sync-state socket events

2 participants