Skip to content

Commit

Permalink
Actually fixed message spoofing exploit
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-eason committed Jan 14, 2024
1 parent 1146246 commit d353cc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions client/src/views/game/Game.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export default {
let player = GameHelper.getUserPlayer(this.$store.state.game)
let socketData = {
gameId: this.$store.state.game._id,
userId: this.$store.state.userId
gameId: this.$store.state.game._id
}
if (player) {
Expand Down
9 changes: 8 additions & 1 deletion server/services/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ export default class BroadcastService {
}

gameMessageSent(game: Game, message: ConversationMessageSentResult) {
message.toPlayerIds.forEach(p => this.io.to(p).emit('gameMessageSent', message));
// Note: We need to ensure we send to the users' socket, not the players as the player one
// can be spoofed.
const toUserIds = game.galaxy.players
.filter(p => message.toPlayerIds.find(m => m.toString() === p._id.toString()) != null)
.filter(p => p.userId != null)
.map(p => p.userId!);

toUserIds.forEach(p => this.io.to(p.toString()).emit('gameMessageSent', message));
}

gameConversationRead(game: Game, conversation: Conversation, readByPlayerId: DBObjectId) {
Expand Down

0 comments on commit d353cc7

Please sign in to comment.