fix(sales-chat): derive companyId from session user and enforce role guard on markAsRead

Đang mở
#39 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript

Hướng nghiên cứu

Start with markAsRead in apps/api/src/sales-chat/sales-chat.controller.ts, then trace the corresponding method in apps/api/src/sales-chat/sales-chat.service.ts and how assertConversationAccess checks roles and assignments. Update the controller and service to derive the company from the authenticated user, enforce the specified role and conversation access checks, and verify viewers receive 403 while authorized users can mark permitted conversations as read.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

backend bug
Problem Description

In apps/api/src/sales-chat/sales-chat.controller.ts (markAsRead, lines 129-140):

  1. Cross-Tenant IDOR via x-company-id header:
    markAsRead accepts @Headers('x-company-id') companyId?: string and resolves finalCompanyId = companyId || (user ? this.getCompanyId(user) : undefined). Any authenticated user can pass another workspace's ID in the x-company-id header along with a conversationId to mark another tenant's inbound messages as read.

  2. Missing @Roles(...) guard:
    markAsRead does not enforce @Roles('OWNER', 'ADMIN', 'MAINTAINER'), allowing VIEWER users to mutate conversation read state.


Expected Behavior
  1. markAsRead must ignore any client-supplied x-company-id header and always derive companyId strictly from the authenticated user (this.getCompanyId(user)).
  2. Only OWNER, ADMIN, and MAINTAINER roles (subject to assertConversationAccess when restrictMaintainerToAssigned is enabled) should be allowed to mark conversations as read; VIEWERs should receive 403 Forbidden.

Where to Look
  • apps/api/src/sales-chat/sales-chat.controller.ts (markAsRead)
  • apps/api/src/sales-chat/sales-chat.service.ts (markAsRead)

Solution / Implementation Guide
  1. In apps/api/src/sales-chat/sales-chat.controller.ts:
    • Add @Roles('OWNER', 'ADMIN', 'MAINTAINER') to markAsRead.
    • Remove @Headers('x-company-id') companyId?: string and derive companyId solely from this.getCompanyId(user).
    • Pass user to this.salesChatService.markAsRead(companyId, conversationId, user).
  2. In apps/api/src/sales-chat/sales-chat.service.ts:
    • Call await this.assertConversationAccess(companyId, conversationId, user) before updating unread message state so restricted MAINTAINERs cannot mark unassigned conversations as read.
Ngôn ngữ chính
TypeScript
Star
2
Fork
1
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sumamakhan761/tryinstance

Tất cả issue của sumamakhan761/tryinstance

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.