Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions federation/server_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,20 @@ func InitialRoomEvents(roomVer gomatrixserverlib.RoomVersion, creator string) []
Type: "m.room.create",
StateKey: b.Ptr(""),
Sender: creator,
Content: map[string]interface{}{
"creator": creator,
"room_version": roomVer,
// We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond
// they will get the same room ID, clobbering internal data structures and causing extremely confusing
// behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their
// hashes will not be the same.
"complement_entropy": util.RandomString(18),
},
Content: func() map[string]interface{} {
content := map[string]interface{}{
"room_version": roomVer,
// We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond
// they will get the same room ID, clobbering internal data structures and causing extremely confusing
// behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their
// hashes will not be the same.
"complement_entropy": util.RandomString(18),
}
if gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersion(roomVer)).CreatorInCreateEvent() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Wait for matrix-org/gomatrixserverlib#465 to merge and update the gomatrixserverlib version in this PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go get github.com/matrix-org/gomatrixserverlib@c9c468727353c4835523349dc7c202e5de9a2e37

Though I can't seem to do it on this PR else I would.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

content["creator"] = creator
}
return content
}(),
},
{
Type: "m.room.member",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/docker/go-connections v0.4.0
github.com/gorilla/mux v1.8.0
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
github.com/matrix-org/gomatrixserverlib v0.0.0-20250813150445-9f5070a65744
github.com/matrix-org/gomatrixserverlib v0.0.0-20260506075950-c9c468727353
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
github.com/sirupsen/logrus v1.9.3
github.com/tidwall/gjson v1.18.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
github.com/matrix-org/gomatrixserverlib v0.0.0-20250813150445-9f5070a65744 h1:5GvC2FD9O/PhuyY95iJQdNYHbDioEhMWdeMP9maDUL8=
github.com/matrix-org/gomatrixserverlib v0.0.0-20250813150445-9f5070a65744/go.mod h1:b6KVfDjXjA5Q7vhpOaMqIhFYvu5BuFVZixlNeTV/CLc=
github.com/matrix-org/gomatrixserverlib v0.0.0-20260506075950-c9c468727353 h1:BdGU/8sF4ZaqGhfYN+eFEzc/whU4LpKvEDdM6i0Oqqs=
github.com/matrix-org/gomatrixserverlib v0.0.0-20260506075950-c9c468727353/go.mod h1:b6KVfDjXjA5Q7vhpOaMqIhFYvu5BuFVZixlNeTV/CLc=
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66/go.mod h1:iBI1foelCqA09JJgPV0FYz4qA5dUXYOxMi57FxKBdd4=
github.com/miekg/dns v1.1.66 h1:FeZXOS3VCVsKnEAd+wBkjMC3D2K+ww66Cq3VnCINuJE=
Expand Down
7 changes: 6 additions & 1 deletion tests/csapi/rooms_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
"github.com/matrix-org/gomatrixserverlib"
)

func TestRoomCreationReportsEventsToMyself(t *testing.T) {
Expand All @@ -26,6 +27,7 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) {
LocalpartSuffix: "bob",
Password: "bobpassword",
})
defaultVer := alice.GetDefaultRoomVersion(t)
roomID := alice.MustCreateRoom(t, map[string]interface{}{})

t.Run("parallel", func(t *testing.T) {
Expand All @@ -38,7 +40,10 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) {
return false
}
must.Equal(t, ev.Get("sender").Str, alice.UserID, "wrong sender")
must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator")
// The creator field was removed in room version 11 (MSC4239).
if gomatrixserverlib.MustGetRoomVersion(defaultVer).CreatorInCreateEvent() {
must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator")
}
Comment on lines +43 to +46
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can use the same CreatorInCreateEvent check in this other spot as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed, done!

return true
}))
})
Expand Down
15 changes: 15 additions & 0 deletions tests/federation_room_get_missing_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,21 @@ func TestOutboundFederationEventSizeGetMissingEvents(t *testing.T) {
}).Methods("POST")

ver := alice.GetDefaultRoomVersion(t)
// This test crafts a "bad" event which state_key is 280 bytes but only 70
// codepoints.
//
// Room version 11 in Synapse switched from using codepoints to using
// bytes. Which means the 280-byte state_key would be rejected immediately.
// Use room version 10 in that case so the codepoint-based limit is in effect.
//
// Since upgrading a room (for example from v10 to v11) won't carry the event
// (a new room is created), we don't have to worry about v10 room events in a v11
// room.
//
// So this test is essentially skipped for any default room v11 or higher.
if gomatrixserverlib.MustGetRoomVersion(ver).StrictEventByteLimits() {
ver = gomatrixserverlib.RoomVersion("10")
}
Comment on lines 499 to +514
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like yet another case that we should handle with a new assert iRoomVer.StrictEventByteLimits() check

You can see how we do this in Synapse synapse/event_auth.py#L487-L499

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed, done!

Comment on lines 499 to +514
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this test would be better if we just always used room version 10 🤔 . The current setup is only better if we're trying to support homeservers that don't support room version 10 yet (do we care about that?)

Suggested change
ver := alice.GetDefaultRoomVersion(t)
// This test crafts a "bad" event which state_key is 280 bytes but only 70
// codepoints.
//
// Room version 11 in Synapse switched from using codepoints to using
// bytes. Which means the 280-byte state_key would be rejected immediately.
// Use room version 10 in that case so the codepoint-based limit is in effect.
//
// Since upgrading a room (for example from v10 to v11) won't carry the event
// (a new room is created), we don't have to worry about v10 room events in a v11
// room.
//
// So this test is essentially skipped for any default room v11 or higher.
verNum, _ := strconv.Atoi(string(ver))
if verNum >= 11 {
ver = gomatrixserverlib.RoomVersion("10")
}
// This test crafts a "bad" event which state_key is 280 bytes but only 70
// codepoints.
//
// Room version 11 in Synapse switched from using codepoints to using
// bytes. Which means the 280-byte state_key would be rejected immediately.
// Use room version 10 in that case so the codepoint-based limit is in effect.
//
// Since upgrading a room (for example from v10 to v11) won't carry the event
// (a new room is created), we don't have to worry about v10 room events in a v11
// room.
//
// So this test is essentially skipped for any default room v11 or higher.
ver = gomatrixserverlib.RoomVersion("10")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I thought it's better to be flexible (since it's not a big change in the test code), but I can apply your suggestion if you think it's better

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably simplest to converge on room version 10.

If there is a use case for the alternative, we can go that route but the comment should better explain the intention.

charlie := srv.UserID("charlie")
room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
roomAlias := srv.MakeAliasMapping("flibble", room.RoomID)
Expand Down
Loading