fix: Drop abac attributes when room changes to public#40537
Conversation
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: 35cc236 The changes in this PR will be included in the next version bump. This PR includes changesets to release 42 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 |
WalkthroughWhen a room is converted to a direct channel type (roomType 'c'), any existing ABAC attributes are now cleared before the type update proceeds. The fix prevents attributes from persisting when ABAC is disabled, with corresponding tests and release documentation. ChangesABAC Attribute Cleanup on Room Type Conversion
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 #40537 +/- ##
===========================================
+ Coverage 69.62% 69.63% +0.01%
===========================================
Files 3326 3326
Lines 122681 122681
Branches 21886 21849 -37
===========================================
+ Hits 85414 85427 +13
+ Misses 33914 33912 -2
+ Partials 3353 3342 -11
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/app/channel-settings/server/functions/saveRoomType.ts (1)
45-53:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winRace condition: ABAC attributes stripped after room type change.
The current implementation changes the room type to public at line 45, then strips ABAC attributes at line 52. This creates a timing window where the room is public but still has
abacAttributesin the database, potentially allowing unauthorized access or violating security invariants.Additionally, there's no check that ABAC is disabled. According to the PR description, attributes should only be dropped "when ABAC is disabled," but this function doesn't validate that condition and appears to rely on upstream validation.
🔒 Proposed fix: Strip attributes before type change
const result = await Promise.all([Rooms.setTypeById(rid, roomType), Subscriptions.updateTypeByRoomId(rid, roomType)]); if (!result) { return result; } -if (roomType === 'c' && room.abacAttributes?.length) { - await Rooms.unsetAbacAttributesById(rid); -} - if (result[1]?.modifiedCount) { void notifyOnSubscriptionChangedByRoomId(rid); }Move the attribute cleanup before the type change:
+if (roomType === 'c' && room.abacAttributes?.length) { + await Rooms.unsetAbacAttributesById(rid); +} + const result = await Promise.all([Rooms.setTypeById(rid, roomType), Subscriptions.updateTypeByRoomId(rid, roomType)]); if (!result) { return result; } if (result[1]?.modifiedCount) { void notifyOnSubscriptionChangedByRoomId(rid); }🤖 Prompt for 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. In `@apps/meteor/app/channel-settings/server/functions/saveRoomType.ts` around lines 45 - 53, The code currently calls Rooms.setTypeById and Subscriptions.updateTypeByRoomId (result) before potentially removing ABAC attributes with Rooms.unsetAbacAttributesById, creating a race where the room is public while attributes still exist and also lacks a check that ABAC is disabled; fix by moving the ABAC cleanup ahead of the type change and only when ABAC is disabled: if roomType === 'c' and room.abacAttributes?.length and ABAC is disabled (check your feature flag or helper such as isAbacEnabled/feature flag), call Rooms.unsetAbacAttributesById(rid) first, then perform Promise.all([Rooms.setTypeById(rid, roomType), Subscriptions.updateTypeByRoomId(rid, roomType)]); ensure you reference the existing room.abacAttributes check and the same rid/roomType variables.
🤖 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.
Outside diff comments:
In `@apps/meteor/app/channel-settings/server/functions/saveRoomType.ts`:
- Around line 45-53: The code currently calls Rooms.setTypeById and
Subscriptions.updateTypeByRoomId (result) before potentially removing ABAC
attributes with Rooms.unsetAbacAttributesById, creating a race where the room is
public while attributes still exist and also lacks a check that ABAC is
disabled; fix by moving the ABAC cleanup ahead of the type change and only when
ABAC is disabled: if roomType === 'c' and room.abacAttributes?.length and ABAC
is disabled (check your feature flag or helper such as isAbacEnabled/feature
flag), call Rooms.unsetAbacAttributesById(rid) first, then perform
Promise.all([Rooms.setTypeById(rid, roomType),
Subscriptions.updateTypeByRoomId(rid, roomType)]); ensure you reference the
existing room.abacAttributes check and the same rid/roomType variables.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fcb41ea9-1aeb-464b-b703-590560cf18d3
📒 Files selected for processing (3)
.changeset/calm-seas-run.mdapps/meteor/app/channel-settings/server/functions/saveRoomType.tsapps/meteor/tests/end-to-end/api/abac.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (4/5)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{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/app/channel-settings/server/functions/saveRoomType.tsapps/meteor/tests/end-to-end/api/abac.ts
🧠 Learnings (4)
📚 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/calm-seas-run.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/app/channel-settings/server/functions/saveRoomType.tsapps/meteor/tests/end-to-end/api/abac.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/app/channel-settings/server/functions/saveRoomType.tsapps/meteor/tests/end-to-end/api/abac.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/app/channel-settings/server/functions/saveRoomType.tsapps/meteor/tests/end-to-end/api/abac.ts
🔇 Additional comments (4)
apps/meteor/tests/end-to-end/api/abac.ts (3)
1564-1580: LGTM!
1582-1599: LGTM!
1695-1698: LGTM!.changeset/calm-seas-run.md (1)
1-5: LGTM!
Proposed changes (including videos or screenshots)
Issue(s)
https://rocketchat.atlassian.net/browse/ABAC3-10
Steps to test or reproduce
Further comments
This is only possible while abac is disabled and the rooms was previously abac managed. Other changes to rooms while keeping the same privacy level are permitted without changing attributes.
Summary by CodeRabbit