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

Open
#39 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

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.

Written by the indexing model from the issue text.

Description

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.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.