Skip to content

Commit

Permalink
[FIX] Validate room access (#24534)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Lehnen <[email protected]>
  • Loading branch information
albuquerquefabio and pierre-lehnen-rc authored Jul 1, 2022
1 parent 60638b9 commit 26c310c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 1 addition & 5 deletions apps/meteor/client/lib/rooms/roomTypes/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AtLeast } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';

import { hasAtLeastOnePermission, hasPermission } from '../../../../app/authorization/client';
import { hasAtLeastOnePermission } from '../../../../app/authorization/client';
import { Subscriptions, Users, ChatRoom } from '../../../../app/models/client';
import { settings } from '../../../../app/settings/client';
import { getUserPreference } from '../../../../app/utils/client';
Expand Down Expand Up @@ -134,10 +134,6 @@ roomCoordinator.add(DirectMessageRoomType, {
},

findRoom(identifier) {
if (!hasPermission('view-d-room')) {
return;
}

const query = {
t: 'd',
$or: [{ name: identifier }, { rid: identifier }],
Expand Down
10 changes: 8 additions & 2 deletions apps/meteor/server/services/authorization/canAccessRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ const roomAccessValidators: RoomAccessValidator[] = [
if (!room?._id || !user?._id) {
return false;
}
if (await Subscriptions.countByRoomIdAndUserId(room._id, user._id)) {

if (!(await Subscriptions.countByRoomIdAndUserId(room._id, user._id))) {
return false;
}

if (await Authorization.hasPermission(user._id, 'view-joined-room')) {
return true;
}
return false;

return Authorization.hasPermission(user._id, `view-${room.t}-room`);
},

async function _validateAccessToDiscussionsParentRoom(room, user): Promise<boolean> {
Expand Down

0 comments on commit 26c310c

Please sign in to comment.