Skip to content

Commit 8027679

Browse files
MarcosSpessattosampaiodiego
authored andcommitted
[FIX] Do not allow users change another users status (#42)
* Do not allow users change another users status * Check user _id properly * Fix setDefaultStatus
1 parent fc47297 commit 8027679

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

server/server.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ var logYellow = function() {
3131
log(Array.prototype.slice.call(arguments).join(' '), 'yellow');
3232
};
3333

34+
var checkUser = function(id, userId) {
35+
if (!id || !userId || id === userId) {
36+
return true;
37+
}
38+
var user = Meteor.users.findOne(id, { fields: { _id: 1 } });
39+
if (user) {
40+
throw new Meteor.Error('cannot-change-other-users-status');
41+
}
42+
43+
return true;
44+
}
45+
3446
UserPresence = {
3547
activeLogs: function() {
3648
logEnable = true;
@@ -255,18 +267,21 @@ UserPresence = {
255267
check(id, Match.Maybe(String));
256268
check(metadata, Match.Maybe(Object));
257269
this.unblock();
270+
checkUser(id, this.userId);
258271
UserPresence.createConnection(id || this.userId, this.connection, 'online', metadata);
259272
},
260273

261274
'UserPresence:away': function(id) {
262275
check(id, Match.Maybe(String));
263276
this.unblock();
277+
checkUser(id, this.userId);
264278
UserPresence.setConnection(id || this.userId, this.connection, 'away');
265279
},
266280

267281
'UserPresence:online': function(id) {
268282
check(id, Match.Maybe(String));
269283
this.unblock();
284+
checkUser(id, this.userId);
270285
UserPresence.setConnection(id || this.userId, this.connection, 'online');
271286
},
272287

@@ -275,11 +290,12 @@ UserPresence = {
275290
check(status, Match.Maybe(String));
276291
this.unblock();
277292

278-
// backward compatible
293+
// backward compatible (receives status as first argument)
279294
if (arguments.length === 1) {
280-
status = id;
281-
id = this.userId;
295+
UserPresence.setDefaultStatus(this.userId, id);
296+
return;
282297
}
298+
checkUser(id, this.userId);
283299
UserPresence.setDefaultStatus(id || this.userId, status);
284300
}
285301
});

0 commit comments

Comments
 (0)