fix(sales-chat): derive companyId from session user and enforce role guard on markAsRead
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
- Domain
- authentication, backend, security
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
Problem Description
In apps/api/src/sales-chat/sales-chat.controller.ts (markAsRead, lines 129-140):
-
Cross-Tenant IDOR via
x-company-idheader:
markAsReadaccepts@Headers('x-company-id') companyId?: stringand resolvesfinalCompanyId = companyId || (user ? this.getCompanyId(user) : undefined). Any authenticated user can pass another workspace's ID in thex-company-idheader along with aconversationIdto mark another tenant's inbound messages as read. -
Missing
@Roles(...)guard:
markAsReaddoes not enforce@Roles('OWNER', 'ADMIN', 'MAINTAINER'), allowingVIEWERusers to mutate conversation read state.
Expected Behavior
markAsReadmust ignore any client-suppliedx-company-idheader and always derivecompanyIdstrictly from the authenticated user (this.getCompanyId(user)).- Only
OWNER,ADMIN, andMAINTAINERroles (subject toassertConversationAccesswhenrestrictMaintainerToAssignedis enabled) should be allowed to mark conversations as read;VIEWERs should receive403 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
- In
apps/api/src/sales-chat/sales-chat.controller.ts:- Add
@Roles('OWNER', 'ADMIN', 'MAINTAINER')tomarkAsRead. - Remove
@Headers('x-company-id') companyId?: stringand derivecompanyIdsolely fromthis.getCompanyId(user). - Pass
usertothis.salesChatService.markAsRead(companyId, conversationId, user).
- Add
- In
apps/api/src/sales-chat/sales-chat.service.ts:- Call
await this.assertConversationAccess(companyId, conversationId, user)before updating unread message state so restrictedMAINTAINERs cannot mark unassigned conversations as read.
- Call
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day