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

Aperta
#39 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
6m
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sumamakhan761/tryinstance

Tutte le issue di sumamakhan761/tryinstance

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.