fix: anonymous spotlight search crashing when anonymous read is enabled - #41843
fix: anonymous spotlight search crashing when anonymous read is enabled#41843KevLehman wants to merge 3 commits into
Conversation
hasPermission wrappers dereferenced the user before forwarding it to the authorization service, so callers passing an undefined user (anonymous spotlight room search) threw instead of getting false.
🦋 Changeset detectedLatest commit: 62056af The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #41843 +/- ##
===========================================
- Coverage 69.25% 69.24% -0.01%
===========================================
Files 4234 4234
Lines 167278 167288 +10
Branches 29806 29795 -11
===========================================
- Hits 115841 115840 -1
- Misses 46279 46295 +16
+ Partials 5158 5153 -5
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Proposed changes (including videos or screenshots)
Since 8.7.0, an unauthenticated room search (
GET /api/v1/spotlightand the DDPspotlightmethod) fails withCannot read properties of undefined (reading '_id')wheneverAccounts_AllowAnonymousReadis enabled — anonymous visitors can't find public channels via the navbar search.Root cause: ae72939 / #41413 (
refactor(authorization): forward only { _id, roles } from hasPermission wrappers). It introducedtoSubjectinserver/lib/authorization/hasPermission.ts, which doesuser._idon any non-string argument. Before that the wrappers passed the user straight through andAuthorization.hasPermissionreturnedfalsefor a falsy user. Only untyped.jscallers (server/lib/spotlight.jsfetchRooms/searchRooms) passundefined, so TypeScript never flagged it.Fix:
toSubjectforwards falsy users untouched; the authorization service already answersfalsefor them. One-line guard, covers all wrapper callers.Tests
hasPermission.spec.ts— id passthrough,{ _id, roles }projection, undefined user forwarded without throwing (fails ondevelop, passes here)[/spotlight]: anonymous request returns no rooms/users with the setting off, and finds public rooms (no users) with it on — this is the case that surfaced the crash[@loadHistory]: anonymous caller gets public channel messages with the setting on,falsefor a private group,error-invalid-userwith the setting off[@getRoomByTypeAndName]: the existing "anonymous read enabled" case was sending admin credentials — now goes throughmethod.callAnonIssue(s)
Steps to test or reproduce
Accounts_AllowAnonymousRead.GET /api/v1/spotlight?query=%23generalwith no auth headers.develop: 400 with the TypeError above. This branch: 200 with the public room inrooms, emptyusers.Further comments
Affects 8.7.0+, candidate for backport. Patch changeset included.