Skip to content
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

Fix some event auth issues #430

Merged
merged 8 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
28 changes: 21 additions & 7 deletions eventauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,13 @@
return nil
}

// If the sender is banned, reject, as they can not change their own ban status.
if m.oldMember.Membership == spec.Ban {
return m.membershipFailed(
"sender cannot set their own membership to %q", m.newMember.Membership,
)
}

switch m.newMember.Membership {
case spec.Knock:
if m.joinRule.JoinRule != spec.Knock && m.joinRule.JoinRule != spec.KnockRestricted {
Expand All @@ -1162,15 +1169,15 @@
// Spec: https://github.com/matrix-org/matrix-spec-proposals/pull/3787
return m.roomVersionImpl.CheckKnockingAllowed(m)
case spec.Join:
if m.oldMember.Membership == spec.Leave && (m.joinRule.JoinRule == spec.Restricted || m.joinRule.JoinRule == spec.KnockRestricted) {
if m.joinRule.JoinRule == spec.Restricted || m.joinRule.JoinRule == spec.KnockRestricted {
if err := m.membershipAllowedSelfForRestrictedJoin(); err != nil {
return err
}
}
// A user that is not in the room is allowed to join if the room
// join rules are "public".
if m.oldMember.Membership == spec.Leave && m.joinRule.JoinRule == spec.Public {
return nil
// If, after validating restricted joins, the room is now "public", allow.
// This means that transitions from knock|invite|leave to join are allowed.
devonh marked this conversation as resolved.
Show resolved Hide resolved
if m.joinRule.JoinRule == spec.Public {
return nil
}
}
// An invited user is always allowed to join, regardless of the join rule
if m.oldMember.Membership == spec.Invite {
Expand All @@ -1180,6 +1187,13 @@
if m.oldMember.Membership == spec.Join {
return nil
}

// A user that is not in the room is allowed to join if the room
// join rules are "public".
if m.oldMember.Membership == spec.Leave && m.joinRule.JoinRule == spec.Public {
return nil
}
Comment on lines +1193 to +1195
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the m.oldMember.Membership == spec.Leave portion of the check?
I think it would be more accurate just to check if the room is public. The only case to reject the join for a public room would be if the user was banned, and that is already handled before this switch block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather be explicit here, as not to open up for potential bugs.


return m.membershipFailed(
"join rule %q forbids it", m.joinRule.JoinRule,
)
Expand Down Expand Up @@ -1231,7 +1245,7 @@
}

func checkKnocking(m *membershipAllower) error {
supported := m.joinRule.JoinRule == spec.Restricted || m.joinRule.JoinRule == spec.KnockRestricted
supported := m.joinRule.JoinRule == spec.Knock || m.joinRule.JoinRule == spec.Restricted || m.joinRule.JoinRule == spec.KnockRestricted

Check warning on line 1248 in eventauth.go

View check run for this annotation

Codecov / codecov/patch

eventauth.go#L1248

Added line #L1248 was not covered by tests
if !supported {
return m.membershipFailed(
"room version %q does not support knocking on rooms with join rule %q",
Expand Down
Loading