Skip to content

fix: canAccessRoom throwing when the user's _id is undefined - #41744

Merged
dionisio-bot[bot] merged 5 commits into
developfrom
fix/canAccessRoom-isPartialUser
Aug 11, 2026
Merged

fix: canAccessRoom throwing when the user's _id is undefined#41744
dionisio-bot[bot] merged 5 commits into
developfrom
fix/canAccessRoom-isPartialUser

Conversation

@nazabucciarelli

@nazabucciarelli nazabucciarelli commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Proposed changes (including videos or screenshots)

In #38622 we added a method name isPartialUser, which checks for the existence of the _id property in the user object rather than checking it's truthy. That implementation returned true every time the user _id came as undefined, getting into the conditional that hydrates the object querying to the user's collection by _id, and hence, throwing 'User not found' error.

Issue(s)

SUP-1093 Regression in 8.3.0: loadMissedMessages throws User not found for unauthenticated callers, reachable from an unauthenticated public endpoint

Steps to test or reproduce

Precondition: You need to have a room with the GENERAL _id, or tweak the body based on your needs.

This can be tested via API, use the POST method against http://localhost:3000/api/v1/method.callAnon/loadMissedMessages, no headers.

Body template:

{"message":"{\"msg\":\"method\",\"id\":\"42\",\"method\":\"loadMissedMessages\",\"params\":[\"GENERAL\",{\"$date\":1700000000000}]}"

Expected result: You shouldn't get an 'User not found' error in console. The response should contain success: true.

Further comments

Review in cubic

Summary by CodeRabbit

Bug Fixes

  • Fixed an authorization error that could occur when a user ID was undefined.
  • Improved handling of incomplete user information during room access checks.
  • Preserved correct anonymous-access decisions when user IDs are empty.

Tests

  • Added coverage for user hydration, missing users, incomplete users, and anonymous access scenarios.

@dionisio-bot

dionisio-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b77e120

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4aa7cdeb-7859-4241-9fa7-13a5c36c5798

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae7d1e and b77e120.

📒 Files selected for processing (1)
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
⚠️ CI failures not shown inline (2)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

Walkthrough

canAccessRoom now rejects partial users with undefined or falsy IDs. Unit tests cover hydration, missing users, complete users, and anonymous access. A patch changeset documents the fix.

Changes

canAccessRoom authorization fix

Layer / File(s) Summary
Reject falsy partial-user IDs
apps/meteor/server/services/authorization/canAccessRoom.ts, .changeset/lazy-ends-drive.md
isPartialUser now requires a truthy _id. The changeset documents the patch fix.
Cover user handling and access decisions
apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
Unit tests mock dependencies and verify hydration, missing-user errors, complete or undefined users, and anonymous access decisions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix for canAccessRoom when the user's _id is undefined.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • SUP-1093: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nazabucciarelli nazabucciarelli added this to the 8.8.0 milestone Aug 11, 2026
@nazabucciarelli nazabucciarelli changed the title fix: isPartialUser checking for user's _id existence instead of checking if it is truthy fix: canAccessRoom throwing when the user's _id is undefined Aug 11, 2026
@nazabucciarelli
nazabucciarelli marked this pull request as ready for review August 11, 2026 01:13
@nazabucciarelli
nazabucciarelli requested a review from a team as a code owner August 11, 2026 01:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts`:
- Around line 100-108: Add a regression test alongside the existing empty-string
case for canAccessRoom that passes a user object with _id explicitly set to
undefined. Verify Users.findOneById is not called and the call completes without
throwing, preserving anonymous-read behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e2a841d4-9901-42c3-a10a-b216eb93c1ec

📥 Commits

Reviewing files that changed from the base of the PR and between 93aa04b and 55ba7e7.

📒 Files selected for processing (3)
  • .changeset/lazy-ends-drive.md
  • apps/meteor/server/services/authorization/canAccessRoom.ts
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: 🔎 Code Check / TypeScript
  • GitHub Check: 🔨 Test Storybook / Test Storybook
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 📦 Meteor Build (coverage)
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/services/authorization/canAccessRoom.ts
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
apps/meteor/**

📄 CodeRabbit inference engine (CLAUDE.md)

The main Rocket.Chat Meteor application resides in apps/meteor/; place its application code there rather than in other monorepo areas.

Files:

  • apps/meteor/server/services/authorization/canAccessRoom.ts
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use .spec.ts extension for test files (e.g., login.spec.ts)

Files:

  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
🧠 Learnings (7)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/lazy-ends-drive.md
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/services/authorization/canAccessRoom.ts
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/services/authorization/canAccessRoom.ts
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/server/services/authorization/canAccessRoom.ts
  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
📚 Learning: 2026-08-05T22:02:59.828Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 41707
File: apps/meteor/server/hooks/messages/processThreads.ts:66-68
Timestamp: 2026-08-05T22:02:59.828Z
Learning: In Rocket.Chat Meteor server code, `callbacks.runAsync` returns its input item rather than the asynchronous callback promise. Callers of `afterReadMessages` must invoke `callbacks.runAsync` without awaiting it, keeping read-receipt I/O off the message-send path; this includes `apps/meteor/server/hooks/messages/processThreads.ts`.

Applied to files:

  • apps/meteor/server/services/authorization/canAccessRoom.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.

Applied to files:

  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts
🔇 Additional comments (4)
.changeset/lazy-ends-drive.md (1)

1-6: LGTM!

apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts (2)

1-80: LGTM!

Also applies to: 88-98, 110-117


82-85: 🎯 Functional Correctness

No change required to the rejection assertion. Mocha loads tests/setup/chaiPlugins.ts, which registers chai-as-promised.

			> Likely an incorrect or invalid review comment.
apps/meteor/server/services/authorization/canAccessRoom.ts (1)

109-109: 🔒 Security & Privacy

No issue in the production path.

Anonymous sessions pass undefined, and authenticated sessions provide users with valid _id values.

			> Likely an incorrect or invalid review comment.

Comment thread apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts Outdated
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.69%. Comparing base (93aa04b) to head (b77e120).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #41744   +/-   ##
========================================
  Coverage    68.68%   68.69%           
========================================
  Files         4166     4167    +1     
  Lines       159382   159436   +54     
  Branches     28253    28312   +59     
========================================
+ Hits        109479   109521   +42     
- Misses       44747    44754    +7     
- Partials      5156     5161    +5     
Flag Coverage Δ
e2e 58.85% <ø> (-0.05%) ⬇️
e2e-api 45.72% <ø> (+<0.01%) ⬆️
unit 70.60% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/tests/unit/server/services/authorization/canAccessRoom.spec.ts Outdated
@ricardogarim ricardogarim added the stat: QA assured Means it has been tested and approved by a company insider label Aug 11, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 11, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Aug 11, 2026
Merged via the queue into develop with commit 15a251c Aug 11, 2026
56 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/canAccessRoom-isPartialUser branch August 11, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants