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

オープン
#39 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
27

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sumamakhan761/tryinstance のほかの issue

sumamakhan761/tryinstance の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。