element-hq / element-hq/dendrite
Can't join private federated space rooms from multiple users without a direct invite
- Dominant language
- Go
- Stars
- 965
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
*This issue was originally created by [**@luk3yx**](https://github.com/luk3yx) at .*
### Background information
- **Dendrite version or git SHA**: 3e9c734da5151aac6b7073c0797d26cde529ced7 (with the space summary, threading, and presence features enabled)
- **Monolith or Polylith?**: Monolith
- **SQLite3 or Postgres?**: Postgres
- **Running in Docker?**: No
- **`go version`**: 1.18.3
- **Client used (if applicable)**: Element
### Description
- **What** is the problem: I can't join rooms in spaces on matrix.org that have their access set to "space members" without a direct invite to the room.
- **Who** is affected: Users trying to join rooms inside spaces
- **How** is this bug manifesting: When I attempt to join some rooms in spaces, I get the following error:
> InputRoomEvents auth failed: InputRoomEventsResponse: eventauth: the nominated 'join_authorised_via_users_server' user "*(user)*" is not joined to the room
The user that it says isn't joined to the room is not necessarily the same user that is attempting to join the room. This only seems to affect some rooms in the space.
- **When** did this first appear: After trying Dendrite with two accounts
### Steps to reproduce
- Create a private space on matrix.org
- Invite a user from Dendrite to the space
- Join a room in the space from the first Dendrite user
- Invite a second user from Dendrite to the space and make the second user join the space
For some reason the room shows as "unnamed room" for the second Dendrite user at this point:

- Try to join the room from the second user.
Possibly relevant logs:
```
time="2022-06-09T01:22:06.509121001Z" level=info msg="Sending event" func="github.com/matrix-org/dendrite/federationapi/queue.(*OutgoingQueues).SendEvent" file="/home/dendrite/dendrite/federationapi/queue/queue.go:234" destinations=1 event="$L-mLWTFxMntGYAXIiQ91ZvJDQfXRc0YBSq9Mb577voA"time="2022-06-09T01:22:09.116014634Z" level=info msg="User requested to room join" func="github.com/matrix-org/dendrite/roomserver/internal/perform.(*Joiner).PerformJoin" file="/home/dendrite/dendrite/roomserver/internal/perform/perform_join.go:61" room_id="!TqhISZkeLnITbfnThZ:matrix.org" servers="[matrix.org]" user_id="(Dendrite user MXID)"
time="2022-06-09T01:22:09.182043925Z" level=error msg="internal.DeviceListCatchup failed" func="github.com/matrix-org/dendrite/syncapi/streams.(*DeviceListStreamProvider).IncrementalSync" file="/home/dendrite/dendrite/syncapi/streams/stream_devicelist.go:33" device_id=BVh_ny9G error="GetBulkStateContent: failed to load state for room !TqhISZkeLnITbfnThZ:matrix.org : storage: state NIDs missing from the database (0 != 1)" limit=20 req.id=YWphzFN5BKO3 req.method=GET req.path=/_matrix/client/r0/sync since=s2639_1311_2928_12_2644_2643_5563_806_14538 timeout=30s user_id="(Dendrite user MXID)"
time="2022-06-09T01:22:09.183673237Z" level=info msg="Sending event" func="github.com/matrix-org/dendrite/federationapi/queue.(*OutgoingQueues).SendEvent" file="/home/dendrite/dendrite/federationapi/queue/queue.go:234" destinations=1 event="$EwH5S7FWAFsMlsen-U6SlvWz2acFKjv7hqcrZ06Vk5E"time="2022-06-09T01:22:09.185279066Z" level=info msg="User joined room successfully" func="github.com/matrix-org/dendrite/roomserver/internal/perform.(*Joiner).PerformJoin" file="/home/dendrite/dendrite/roomserver/internal/perform/perform_join.go:76" room_id="!TqhISZkeLnITbfnThZ:matrix.org" servers="[matrix.org]" user_id="(Dendrite user MXID)"
time="2022-06-09T01:22:14.436241205Z" level=info msg="Signalling other goroutines waiting for this goroutine to generate the thumbnail." func=github.com/matrix-org/dendrite/mediaapi/thumbnailer.broadcastGeneration file="/home/dendrite/dendrite/mediaapi/thumbnailer/thumbnailer.go:126" Height=54 MediaID=OWuRjJJOFikFQkDIHKFPgNeb Origin=matrix.org ResizeMethod=crop Width=54 req.id=a04R3SOk02jU req.method=GET req.path=/_matrix/media/r0/thumbnail/matrix.org/OWuRjJJOFikFQkDIHKFPgNeb
time="2022-06-09T01:23:01.754088142Z" level=info msg="Cleaning old notifications" func=github.com/matrix-org/dendrite/userapi.NewInternalAPI.func1 file="/home/dendrite/dendrite/userapi/userapi.go:100"
time="2022-06-09T01:23:49.877650238Z" level=info msg="Signalling other goroutines waiting for this goroutine to generate the thumbnail." func=github.com/matrix-org/dendrite/mediaapi/thumbnailer.broadcastGeneration file="/home/dendrite/dendrite/mediaapi/thumbnailer/thumbnailer.go:126" Height=54 MediaID=OWuRjJJOFikFQkDIHKFPgNeb Origin=matrix.org ResizeMethod=crop Width=54 req.id=MYUaOph3zWiR req.method=GET req.path=/_matrix/media/r0/thumbnail/matrix.org/OWuRjJJOFikFQkDIHKFPgNeb
```
Edit: I've tried again with Dendrite v0.8.8 and still got this error, although it only occurred the second time I tried to reproduce it with a newly created space. I got different log messages this time, maybe the previous logs were irrelevant.
```
time="2022-06-10T00:50:04.397247949Z" level=info msg="User requested to room join" func="github.com/matrix-org/dendrite/roomserver/internal/perform.(*Joiner).PerformJoin" file="/home/dendrite/dendrite/roomserver/internal/perform/perform_join.go:61" room_id="!VNtMIAIaTYEpWfDirJ:matrix.org" servers="[matrix.org]" user_id="(second Dendrite user)"
time="2022-06-10T00:50:04.421880682Z" level=warning msg="Event $0J2CEF-WDvmH843zzyhLAt0Uy-0Cosck2iTYMoEr8GM not allowed by auth events" func="github.com/matrix-org/dendrite/roomserver/internal/input.(*Inputer).processRoomEvent" file="/home/dendrite/dendrite/roomserver/internal/input/input_events.go:199" context=missing error="eventauth: failed to find the membership event for 'join_authorised_via_users_server' user \"(second Dendrite user)\"" event_id="$0J2CEF-WDvmH843zzyhLAt0Uy-0Cosck2iTYMoEr8GM" kind=KindNew origin="" room_id="!VNtMIAIaTYEpWfDirJ:matrix.org" type=m.room.member
time="2022-06-10T00:50:04.424630096Z" level=warning msg="Error authing soft-failed event" func="github.com/matrix-org/dendrite/roomserver/internal/input.(*Inputer).processRoomEvent" file="/home/dendrite/dendrite/roomserver/internal/input/input_events.go:236" context=missing error="eventauth: failed to find the membership event for 'join_authorised_via_users_server' user \"(second Dendrite user)\"" event_id="$0J2CEF-WDvmH843zzyhLAt0Uy-0Cosck2iTYMoEr8GM" kind=KindNew origin="" room_id="!VNtMIAIaTYEpWfDirJ:matrix.org" type=m.room.member
time="2022-06-10T00:50:04.430554994Z" level=warning msg="Stored rejected event" func="github.com/matrix-org/dendrite/roomserver/internal/input.(*Inputer).processRoomEvent" file="/home/dendrite/dendrite/roomserver/internal/input/input_events.go:346" context=missing error="eventauth: failed to find the membership event for 'join_authorised_via_users_server' user \"(second Dendrite user)\"" event_id="$0J2CEF-WDvmH843zzyhLAt0Uy-0Cosck2iTYMoEr8GM" kind=KindNew missing_prev=false origin="" room_id="!VNtMIAIaTYEpWfDirJ:matrix.org" soft_fail=true type=m.room.member
time="2022-06-10T00:50:04.430897702Z" level=warning msg="Roomserver failed to process async event" func="github.com/matrix-org/dendrite/roomserver/internal/input.(*worker)._next" file="/home/dendrite/dendrite/roomserver/internal/input/input.go:259" error="eventauth: failed to find the membership event for 'join_authorised_via_users_server' user \"(second Dendrite user)\"" event_id="$0J2CEF-WDvmH843zzyhLAt0Uy-0Cosck2iTYMoEr8GM" room_id="!VNtMIAIaTYEpWfDirJ:matrix.org" type=m.room.member
time="2022-06-10T00:50:04.431717876Z" level=error msg="Failed to join room" func="github.com/matrix-org/dendrite/roomserver/internal/perform.(*Joiner).PerformJoin" file="/home/dendrite/dendrite/roomserver/internal/perform/perform_join.go:64" error="1 : InputRoomEvents auth failed: InputRoomEventsResponse: eventauth: failed to find the membership event for 'join_authorised_via_users_server' user \"(second Dendrite user)\"" room_id="!VNtMIAIaTYEpWfDirJ:matrix.org" servers="[matrix.org]" user_id="(second Dendrite user)"
```
Contributor guide
Research direction
Reproduce the two-user private-space join flow described in the issue, then start with roomserver/internal/perform/perform_join.go and follow the auth failure through roomserver/internal/input/input_events.go and input.go. Done means the second Dendrite user can join a space room without a direct room invite and the reported join_authorised_via_users_server errors no longer occur.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100