Merge commit from fork

* fix(backend): restrict chat room / chat message permissions

* spec: モデレーター以上の権限では全てを閲覧可能
This commit is contained in:
かっこかり 2026-05-20 22:03:53 +09:00 committed by GitHub
commit 04f18fe919
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -572,6 +572,27 @@ export class ChatService {
return created;
}
@bindThis
public async hasPermissionToViewRoomInfo(meId: MiUser['id'], room: MiChatRoom) {
if (room.ownerId === meId) {
return true;
}
if (await this.isRoomMember(room, meId)) {
return true;
}
if (await this.chatRoomInvitationsRepository.findOneBy({ roomId: room.id, userId: meId })) {
return true;
}
if (await this.roleService.isModerator({ id: meId })) {
return true;
}
return false;
}
@bindThis
public async hasPermissionToDeleteRoom(meId: MiUser['id'], room: MiChatRoom) {
if (room.ownerId === meId) {

View file

@ -54,6 +54,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchRoom);
}
if (!await this.chatService.hasPermissionToViewRoomInfo(me.id, room)) {
throw new ApiError(meta.errors.noSuchRoom);
}
return this.chatEntityService.packRoom(room, me);
});
}