Skip to content

Commit b9e7e38

Browse files
fix: imported fixes 2025-02-17 (#35231)
Co-authored-by: Abhinav Kumar <15830206+abhinavkrin@users.noreply.github.com>
1 parent aadbcbc commit b9e7e38

File tree

2 files changed

+1706
-27
lines changed

2 files changed

+1706
-27
lines changed

apps/meteor/app/api/server/v1/channels.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Team, Room } from '@rocket.chat/core-services';
2-
import type { IRoom, ISubscription, IUser, RoomType } from '@rocket.chat/core-typings';
2+
import { TEAM_TYPE, type IRoom, type ISubscription, type IUser, type RoomType } from '@rocket.chat/core-typings';
33
import { Integrations, Messages, Rooms, Subscriptions, Uploads, Users } from '@rocket.chat/models';
44
import {
55
isChannelsAddAllProps,
@@ -302,6 +302,10 @@ API.v1.addRoute(
302302
...(pinned && pinned.toLowerCase() === 'true' ? { pinned: true } : {}),
303303
};
304304

305+
if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
306+
return API.v1.forbidden();
307+
}
308+
305309
// Special check for the permissions
306310
if (
307311
(await hasPermissionAsync(this.userId, 'view-joined-room')) &&
@@ -453,6 +457,10 @@ API.v1.addRoute(
453457

454458
const findResult = await findChannelByIdOrName({ params });
455459

460+
if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
461+
return API.v1.forbidden();
462+
}
463+
456464
const moderators = (
457465
await Subscriptions.findByRoomIdAndRoles(findResult._id, ['moderator'], {
458466
projection: { u: 1 },
@@ -859,6 +867,10 @@ API.v1.addRoute(
859867
checkedArchived: false,
860868
});
861869

870+
if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
871+
return API.v1.forbidden();
872+
}
873+
862874
let includeAllPublicChannels = true;
863875
if (typeof this.queryParams.includeAllPublicChannels !== 'undefined') {
864876
includeAllPublicChannels = this.queryParams.includeAllPublicChannels === 'true';
@@ -904,12 +916,18 @@ API.v1.addRoute(
904916
{ authRequired: true },
905917
{
906918
async get() {
919+
const findResult = await findChannelByIdOrName({
920+
params: this.queryParams,
921+
checkedArchived: false,
922+
userId: this.userId,
923+
});
924+
925+
if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
926+
return API.v1.forbidden();
927+
}
928+
907929
return API.v1.success({
908-
channel: await findChannelByIdOrName({
909-
params: this.queryParams,
910-
checkedArchived: false,
911-
userId: this.userId,
912-
}),
930+
channel: findResult,
913931
});
914932
},
915933
},
@@ -1058,6 +1076,10 @@ API.v1.addRoute(
10581076
checkedArchived: false,
10591077
});
10601078

1079+
if (!(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
1080+
return API.v1.forbidden();
1081+
}
1082+
10611083
if (findResult.broadcast && !(await hasPermissionAsync(this.userId, 'view-broadcast-member-list', findResult._id))) {
10621084
return API.v1.forbidden();
10631085
}
@@ -1416,7 +1438,7 @@ API.v1.addRoute(
14161438

14171439
API.v1.addRoute(
14181440
'channels.anonymousread',
1419-
{ authRequired: false },
1441+
{ authOrAnonRequired: true },
14201442
{
14211443
async get() {
14221444
const findResult = await findChannelByIdOrName({
@@ -1434,6 +1456,16 @@ API.v1.addRoute(
14341456
});
14351457
}
14361458

1459+
// Public rooms of private teams should be accessible only by team members
1460+
if (findResult.teamId) {
1461+
const team = await Team.getOneById(findResult.teamId);
1462+
if (team?.type === TEAM_TYPE.PRIVATE) {
1463+
if (!this.userId || !(await canAccessRoomAsync(findResult, { _id: this.userId }))) {
1464+
return API.v1.notFound('Room not found');
1465+
}
1466+
}
1467+
}
1468+
14371469
const { cursor, totalCount } = await Messages.findPaginated(ourQuery, {
14381470
sort: sort || { ts: -1 },
14391471
skip: offset,

0 commit comments

Comments
 (0)