aboutsummaryrefslogtreecommitdiff
path: root/roomserver/internal
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-08-19 11:04:26 +0200
committerGitHub <noreply@github.com>2022-08-19 11:04:26 +0200
commit365da70a23cec9595a2854ed47f970f03cfde0a9 (patch)
tree1d195baf279bf0707ea8ac079ce1f8df519ed3f3 /roomserver/internal
parent5cacca92d2b888d022f9fa346b8068ce13087b00 (diff)
Set historyVisibility for backfilled events over federation (#2656)
This should hopefully deflake Backfill works correctly with history visibility set to joined as we were using the default shared visibility, even if the events are set to joined (or something else)
Diffstat (limited to 'roomserver/internal')
-rw-r--r--roomserver/internal/perform/perform_backfill.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/roomserver/internal/perform/perform_backfill.go b/roomserver/internal/perform/perform_backfill.go
index aecff8b8..de76b641 100644
--- a/roomserver/internal/perform/perform_backfill.go
+++ b/roomserver/internal/perform/perform_backfill.go
@@ -164,6 +164,7 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
// TODO: update backwards extremities, as that should be moved from syncapi to roomserver at some point.
res.Events = events
+ res.HistoryVisibility = requester.historyVisiblity
return nil
}
@@ -248,6 +249,7 @@ type backfillRequester struct {
servers []gomatrixserverlib.ServerName
eventIDToBeforeStateIDs map[string][]string
eventIDMap map[string]*gomatrixserverlib.Event
+ historyVisiblity gomatrixserverlib.HistoryVisibility
}
func newBackfillRequester(
@@ -266,6 +268,7 @@ func newBackfillRequester(
eventIDMap: make(map[string]*gomatrixserverlib.Event),
bwExtrems: bwExtrems,
preferServer: preferServer,
+ historyVisiblity: gomatrixserverlib.HistoryVisibilityShared,
}
}
@@ -447,7 +450,8 @@ FindSuccessor:
}
// possibly return all joined servers depending on history visiblity
- memberEventsFromVis, err := joinEventsFromHistoryVisibility(ctx, b.db, roomID, stateEntries, b.thisServer)
+ memberEventsFromVis, visibility, err := joinEventsFromHistoryVisibility(ctx, b.db, roomID, stateEntries, b.thisServer)
+ b.historyVisiblity = visibility
if err != nil {
logrus.WithError(err).Error("ServersAtEvent: failed calculate servers from history visibility rules")
return nil
@@ -528,7 +532,7 @@ func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion,
// pull all events and then filter by that table.
func joinEventsFromHistoryVisibility(
ctx context.Context, db storage.Database, roomID string, stateEntries []types.StateEntry,
- thisServer gomatrixserverlib.ServerName) ([]types.Event, error) {
+ thisServer gomatrixserverlib.ServerName) ([]types.Event, gomatrixserverlib.HistoryVisibility, error) {
var eventNIDs []types.EventNID
for _, entry := range stateEntries {
@@ -542,7 +546,9 @@ func joinEventsFromHistoryVisibility(
// Get all of the events in this state
stateEvents, err := db.Events(ctx, eventNIDs)
if err != nil {
- return nil, err
+ // even though the default should be shared, restricting the visibility to joined
+ // feels more secure here.
+ return nil, gomatrixserverlib.HistoryVisibilityJoined, err
}
events := make([]*gomatrixserverlib.Event, len(stateEvents))
for i := range stateEvents {
@@ -551,20 +557,22 @@ func joinEventsFromHistoryVisibility(
// Can we see events in the room?
canSeeEvents := auth.IsServerAllowed(thisServer, true, events)
+ visibility := gomatrixserverlib.HistoryVisibility(auth.HistoryVisibilityForRoom(events))
if !canSeeEvents {
- logrus.Infof("ServersAtEvent history not visible to us: %s", auth.HistoryVisibilityForRoom(events))
- return nil, nil
+ logrus.Infof("ServersAtEvent history not visible to us: %s", visibility)
+ return nil, visibility, nil
}
// get joined members
info, err := db.RoomInfo(ctx, roomID)
if err != nil {
- return nil, err
+ return nil, visibility, nil
}
joinEventNIDs, err := db.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, true, false)
if err != nil {
- return nil, err
+ return nil, visibility, err
}
- return db.Events(ctx, joinEventNIDs)
+ evs, err := db.Events(ctx, joinEventNIDs)
+ return evs, visibility, err
}
func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixserverlib.HeaderedEvent) (types.RoomNID, map[string]types.Event) {