-
Notifications
You must be signed in to change notification settings - Fork 20
fix: handling non-public room join #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis PR modifies the invite service to improve room privacy detection and add input validation. It changes from scanning all state events for a public join rule to locating the first m.room.join_rules event specifically, and adds validation to ensure strippedStateEvents is not empty before processing invites. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 @@
## main #290 +/- ##
=======================================
Coverage 60.49% 60.49%
=======================================
Files 67 67
Lines 6675 6675
=======================================
Hits 4038 4038
Misses 2637 2637 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/federation-sdk/src/services/invite.service.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/federation-sdk/src/services/invite.service.ts (1)
packages/federation-sdk/src/index.ts (1)
NotAllowedError(93-93)
🔇 Additional comments (1)
packages/federation-sdk/src/services/invite.service.ts (1)
203-209: No changes needed; validation is spec-compliant.The Matrix specification distinguishes between the
invite_room_statefield being optional (can be omitted entirely) and the array being empty when present. Per the v1.16 specification, if stripped state events are provided, they must include valid events—notably,m.room.createis required in invite contexts. Throwing an error when the array is empty is correct behavior and prevents malformed invites. The comment accurately references the spec, and the validation appropriately guards against empty state.
| const joinRuleEvent = strippedStateEvents.find( | ||
| (stateEvent) => stateEvent.type === 'm.room.join_rules', | ||
| ); | ||
| const isRoomNonPrivate = joinRuleEvent | ||
| ? joinRuleEvent.content.join_rule === 'public' | ||
| : true /* default, if no event */; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reconsider the default value for isRoomNonPrivate.
When no m.room.join_rules event is found, the code defaults isRoomNonPrivate to true, treating the room as public/non-private. This appears inconsistent with the Matrix specification, which typically defaults join_rules to "invite" (private) when not explicitly set. Defaulting to true here could bypass privacy restrictions configured via allowedNonPrivateRooms, potentially allowing invites to private rooms that should be rejected.
Consider this safer default:
const joinRuleEvent = strippedStateEvents.find(
(stateEvent) => stateEvent.type === 'm.room.join_rules',
);
const isRoomNonPrivate = joinRuleEvent
? joinRuleEvent.content.join_rule === 'public'
- : true /* default, if no event */;
+ : false /* default to private/invite per Matrix spec */;🤖 Prompt for AI Agents
In packages/federation-sdk/src/services/invite.service.ts around lines 163 to
168, the code currently treats a missing m.room.join_rules event as public
(isRoomNonPrivate = true); change this to treat a missing join_rules as private
(default to invite) by setting the default to false so that absence of the event
is handled as "invite"/private; update the ternary (or conditional) and any
accompanying comment to reflect the safer default and ensure downstream checks
(e.g., allowedNonPrivateRooms) continue to behave correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@debdutdeb what do you think about this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) { | ||
| // SPEC: An optional list of stripped state events to help the receiver of the invite identify the room. | ||
| // https://spec.matrix.org/v1.12/server-server-api/#put_matrixfederationv1inviteroomideventid | ||
| if (strippedStateEvents.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we validate this only if we have configured restrictions? like if we don't restrict anything we won't use the stripped state anyways
|
not required for now |
|
existing check covers the case sionce no join_rule === non public. this pr shouldn't be needed anymore. |
Summary by CodeRabbit