Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Don't walk inaccessible rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
S7evinK committed Mar 26, 2024
1 parent 2e88c72 commit 3d18878
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion roomserver/internal/query/query_room_hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker r
}
} else if !authorised {
inaccessible = append(inaccessible, queuedRoom.RoomID.String())
continue
} else {
// room exists but user is not authorised
continue
Expand All @@ -158,6 +159,7 @@ func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker r
// We need to invert the order here because the child events are lo->hi on the timestamp,
// so we need to ensure we pop in the same lo->hi order, which won't be the case if we
// insert the highest timestamp last in a stack.
extendQueueLoop:
for i := len(discoveredChildEvents) - 1; i >= 0; i-- {
spaceContent := struct {
Via []string `json:"via"`
Expand All @@ -170,6 +172,12 @@ func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker r
if err != nil {
util.GetLogger(ctx).WithError(err).WithField("invalid_room_id", ev.StateKey).WithField("parent_room_id", queuedRoom.RoomID).Warn("Invalid room ID in m.space.child state event")
} else {
// Make sure not to queue inaccessible rooms
for _, inaccessibleRoomID := range inaccessible {
if inaccessibleRoomID == childRoomID.String() {
continue extendQueueLoop
}
}
unvisited = append(unvisited, roomserver.RoomHierarchyWalkerQueuedRoom{
RoomID: *childRoomID,
ParentRoomID: &queuedRoom.RoomID,
Expand Down Expand Up @@ -257,7 +265,7 @@ func authorisedServer(ctx context.Context, querier *Queryer, roomID spec.RoomID,
return true, []string{}
}

if rule == spec.Restricted {
if rule == spec.Restricted || rule == spec.KnockRestricted {
allowJoinedToRoomIDs = append(allowJoinedToRoomIDs, restrictedJoinRuleAllowedRooms(ctx, joinRuleEv)...)
}
}
Expand Down

0 comments on commit 3d18878

Please sign in to comment.