Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Team, Room } from '@rocket.chat/core-services';
import type { IRoom, ISubscription, IUser, RoomType } from '@rocket.chat/core-typings';
import { TEAM_TYPE, type IRoom, type ISubscription, type IUser, type RoomType } from '@rocket.chat/core-typings';
import { Integrations, Messages, Rooms, Subscriptions, Uploads, Users } from '@rocket.chat/models';
import {
isChannelsAddAllProps,
Expand Down Expand Up @@ -302,6 +302,10 @@ API.v1.addRoute(
...(pinned && pinned.toLowerCase() === 'true' ? { pinned: true } : {}),
};

if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
return API.v1.forbidden();
}

// Special check for the permissions
if (
(await hasPermissionAsync(this.userId, 'view-joined-room')) &&
Expand Down Expand Up @@ -453,6 +457,10 @@ API.v1.addRoute(

const findResult = await findChannelByIdOrName({ params });

if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
return API.v1.forbidden();
}

const moderators = (
await Subscriptions.findByRoomIdAndRoles(findResult._id, ['moderator'], {
projection: { u: 1 },
Expand Down Expand Up @@ -859,6 +867,10 @@ API.v1.addRoute(
checkedArchived: false,
});

if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
return API.v1.forbidden();
}

let includeAllPublicChannels = true;
if (typeof this.queryParams.includeAllPublicChannels !== 'undefined') {
includeAllPublicChannels = this.queryParams.includeAllPublicChannels === 'true';
Expand Down Expand Up @@ -904,12 +916,18 @@ API.v1.addRoute(
{ authRequired: true },
{
async get() {
const findResult = await findChannelByIdOrName({
params: this.queryParams,
checkedArchived: false,
userId: this.userId,
});

if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
return API.v1.forbidden();
}

return API.v1.success({
channel: await findChannelByIdOrName({
params: this.queryParams,
checkedArchived: false,
userId: this.userId,
}),
channel: findResult,
});
},
},
Expand Down Expand Up @@ -1058,6 +1076,10 @@ API.v1.addRoute(
checkedArchived: false,
});

if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
return API.v1.forbidden();
}

if (findResult.broadcast && !(await hasPermissionAsync(this.userId, 'view-broadcast-member-list', findResult._id))) {
return API.v1.forbidden();
}
Expand Down Expand Up @@ -1416,7 +1438,7 @@ API.v1.addRoute(

API.v1.addRoute(
'channels.anonymousread',
{ authRequired: false },
{ authOrAnonRequired: true },
{
async get() {
const findResult = await findChannelByIdOrName({
Expand All @@ -1434,6 +1456,16 @@ API.v1.addRoute(
});
}

// Public rooms of private teams should be accessible only by team members
if (findResult.teamId) {
const team = await Team.getOneById(findResult.teamId);
if (team?.type === TEAM_TYPE.PRIVATE) {
if (!this.userId || !(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
return API.v1.notFound('Room not found');
}
}
}

const { cursor, totalCount } = await Messages.findPaginated(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
Expand Down
Loading
Loading