|
| 1 | +--- |
| 2 | +toc_hide: true |
| 3 | +--- |
| 4 | + |
| 5 | +Events must be signed by the server denoted by the `sender` key. |
| 6 | + |
| 7 | +`m.room.redaction` events are not explicitly part of the auth rules. |
| 8 | +They are still subject to the minimum power level rules, but should always |
| 9 | +fall into "10. Otherwise, allow". Instead of being authorized at the time |
| 10 | +of receipt, they are authorized at a later stage: see the |
| 11 | +[Redactions](#redactions) section below for more information. |
| 12 | + |
| 13 | +The types of state events that affect authorization are: |
| 14 | + |
| 15 | +- `m.room.create` |
| 16 | +- `m.room.member` |
| 17 | +- `m.room.join_rules` |
| 18 | +- `m.room.power_levels` |
| 19 | +- `m.room.third_party_invite` |
| 20 | + |
| 21 | +{{% boxes/note %}} |
| 22 | +Power levels are inferred from defaults when not explicitly supplied. |
| 23 | +For example, mentions of the `sender`'s power level can also refer to |
| 24 | +the default power level for users in the room. |
| 25 | +{{% /boxes/note %}} |
| 26 | + |
| 27 | +The rules are as follows: |
| 28 | + |
| 29 | +1. If type is `m.room.create`: |
| 30 | + 1. If it has any previous events, reject. |
| 31 | + 2. If the domain of the `room_id` does not match the domain of the |
| 32 | + `sender`, reject. |
| 33 | + 3. If `content.room_version` is present and is not a recognised |
| 34 | + version, reject. |
| 35 | + 4. If `content` has no `creator` field, reject. |
| 36 | + 5. Otherwise, allow. |
| 37 | +2. Reject if event has `auth_events` that: |
| 38 | + 1. have duplicate entries for a given `type` and `state_key` pair |
| 39 | + 2. have entries whose `type` and `state_key` don't match those |
| 40 | + specified by the [auth events |
| 41 | + selection](/server-server-api#auth-events-selection) |
| 42 | + algorithm described in the server specification. |
| 43 | +3. If event does not have a `m.room.create` in its `auth_events`, |
| 44 | + reject. |
| 45 | +4. If type is `m.room.member`: |
| 46 | + 1. If no `state_key` key or `membership` key in `content`, reject. |
| 47 | + 2. If `content` has a `join_authorised_via_users_server` |
| 48 | + key: |
| 49 | + 1. If the event is not validly signed by the user ID denoted |
| 50 | + by the key, reject. |
| 51 | + 3. If `membership` is `join`: |
| 52 | + 1. If the only previous event is an `m.room.create` and the |
| 53 | + `state_key` is the creator, allow. |
| 54 | + 2. If the `sender` does not match `state_key`, reject. |
| 55 | + 3. If the `sender` is banned, reject. |
| 56 | + 4. If the `join_rule` is `invite` then allow if membership |
| 57 | + state is `invite` or `join`. |
| 58 | + 5. If the `join_rule` is `restricted`: |
| 59 | + 1. If membership state is `join` or `invite`, allow. |
| 60 | + 2. If the `join_authorised_via_users_server` key in `content` |
| 61 | + is not a user with sufficient permission to invite other |
| 62 | + users, reject. |
| 63 | + 3. Otherwise, allow. |
| 64 | + 6. If the `join_rule` is `public`, allow. |
| 65 | + 7. Otherwise, reject. |
| 66 | + 4. If `membership` is `invite`: |
| 67 | + 1. If `content` has `third_party_invite` key: |
| 68 | + 1. If *target user* is banned, reject. |
| 69 | + 2. If `content.third_party_invite` does not have a `signed` |
| 70 | + key, reject. |
| 71 | + 3. If `signed` does not have `mxid` and `token` keys, |
| 72 | + reject. |
| 73 | + 4. If `mxid` does not match `state_key`, reject. |
| 74 | + 5. If there is no `m.room.third_party_invite` event in the |
| 75 | + current room state with `state_key` matching `token`, |
| 76 | + reject. |
| 77 | + 6. If `sender` does not match `sender` of the |
| 78 | + `m.room.third_party_invite`, reject. |
| 79 | + 7. If any signature in `signed` matches any public key in |
| 80 | + the `m.room.third_party_invite` event, allow. The public |
| 81 | + keys are in `content` of `m.room.third_party_invite` as: |
| 82 | + 1. A single public key in the `public_key` field. |
| 83 | + 2. A list of public keys in the `public_keys` field. |
| 84 | + 8. Otherwise, reject. |
| 85 | + 2. If the `sender`'s current membership state is not `join`, |
| 86 | + reject. |
| 87 | + 3. If *target user*'s current membership state is `join` or |
| 88 | + `ban`, reject. |
| 89 | + 4. If the `sender`'s power level is greater than or equal to |
| 90 | + the *invite level*, allow. |
| 91 | + 5. Otherwise, reject. |
| 92 | + 5. If `membership` is `leave`: |
| 93 | + 1. If the `sender` matches `state_key`, allow if and only if |
| 94 | + that user's current membership state is `invite` or `join`. |
| 95 | + 2. If the `sender`'s current membership state is not `join`, |
| 96 | + reject. |
| 97 | + 3. If the *target user*'s current membership state is `ban`, |
| 98 | + and the `sender`'s power level is less than the *ban level*, |
| 99 | + reject. |
| 100 | + 4. If the `sender`'s power level is greater than or equal to |
| 101 | + the *kick level*, and the *target user*'s power level is |
| 102 | + less than the `sender`'s power level, allow. |
| 103 | + 5. Otherwise, reject. |
| 104 | + 6. If `membership` is `ban`: |
| 105 | + 1. If the `sender`'s current membership state is not `join`, |
| 106 | + reject. |
| 107 | + 2. If the `sender`'s power level is greater than or equal to |
| 108 | + the *ban level*, and the *target user*'s power level is less |
| 109 | + than the `sender`'s power level, allow. |
| 110 | + 3. Otherwise, reject. |
| 111 | + 7. If `membership` is `knock`: |
| 112 | + 1. If the `join_rule` is anything other than `knock`, reject. |
| 113 | + 2. If `sender` does not match `state_key`, reject. |
| 114 | + 3. If the `sender`'s current membership is not `ban`, `invite`, |
| 115 | + or `join`, allow. |
| 116 | + 8. Otherwise, the membership is unknown. Reject. |
| 117 | +5. If the `sender`'s current membership state is not `join`, reject. |
| 118 | +6. If type is `m.room.third_party_invite`: |
| 119 | + 1. Allow if and only if `sender`'s current power level is greater |
| 120 | + than or equal to the *invite level*. |
| 121 | +7. If the event type's *required power level* is greater than the |
| 122 | + `sender`'s power level, reject. |
| 123 | +8. If the event has a `state_key` that starts with an `@` and does not |
| 124 | + match the `sender`, reject. |
| 125 | +9. If type is `m.room.power_levels`: |
| 126 | + 1. If `users` key in `content` is not a dictionary with keys that |
| 127 | + are valid user IDs with values that are integers (or a string |
| 128 | + that is an integer), reject. |
| 129 | + 2. If there is no previous `m.room.power_levels` event in the room, |
| 130 | + allow. |
| 131 | + 3. For the keys `users_default`, `events_default`, `state_default`, |
| 132 | + `ban`, `redact`, `kick`, `invite` check if they were added, |
| 133 | + changed or removed. For each found alteration: |
| 134 | + 1. If the current value is higher than the `sender`'s current |
| 135 | + power level, reject. |
| 136 | + 2. If the new value is higher than the `sender`'s current power |
| 137 | + level, reject. |
| 138 | + 4. For each entry being added, changed or removed in both the |
| 139 | + `events`, `users`, and `notifications` keys: |
| 140 | + 1. If the current value is higher than the `sender`'s current |
| 141 | + power level, reject. |
| 142 | + 2. If the new value is higher than the `sender`'s current power |
| 143 | + level, reject. |
| 144 | + 5. For each entry being changed under the `users` key, other than |
| 145 | + the `sender`'s own entry: |
| 146 | + 1. If the current value is equal to the `sender`'s current |
| 147 | + power level, reject. |
| 148 | + 6. Otherwise, allow. |
| 149 | +10. Otherwise, allow. |
| 150 | + |
| 151 | +{{% boxes/note %}} |
| 152 | +Some consequences of these rules: |
| 153 | + |
| 154 | +- Unless you are a member of the room, the only permitted operations |
| 155 | + (apart from the initial create/join) are: joining a public room; |
| 156 | + accepting or rejecting an invitation to a room. |
| 157 | +- To unban somebody, you must have power level greater than or equal |
| 158 | + to both the kick *and* ban levels, *and* greater than the target |
| 159 | + user's power level. |
| 160 | +{{% /boxes/note %}} |
0 commit comments