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

未关闭
#39 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
TypeScript
星标
2
派生
1
平均合并
6 分钟
30 天内合并 PR
27

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sumamakhan761/tryinstance 的其他 Issue

查看 sumamakhan761/tryinstance 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。