diff options
author | Erik Johnston <erikj@jki.re> | 2016-07-15 11:38:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-15 11:38:33 +0100 |
commit | bd7c51921d4cac3e435ed1b4cb35632141914004 (patch) | |
tree | b133be1c9d80784a4b7fa52b17ef7526a99b22b8 /synapse/api | |
parent | Merge pull request #921 from matrix-org/erikj/account_deactivate (diff) | |
parent | Comment (diff) | |
download | synapse-bd7c51921d4cac3e435ed1b4cb35632141914004.tar.xz |
Merge pull request #919 from matrix-org/erikj/auth_fix
Various auth.py fixes.
Diffstat (limited to 'synapse/api')
-rw-r--r-- | synapse/api/auth.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py index 521a52e001..3d1ce4e09e 100644 --- a/synapse/api/auth.py +++ b/synapse/api/auth.py @@ -63,7 +63,7 @@ class Auth(object): "user_id = ", ]) - def check(self, event, auth_events): + def check(self, event, auth_events, do_sig_check=True): """ Checks if this event is correctly authed. Args: @@ -79,6 +79,13 @@ class Auth(object): if not hasattr(event, "room_id"): raise AuthError(500, "Event has no room_id: %s" % event) + + sender_domain = get_domain_from_id(event.sender) + + # Check the sender's domain has signed the event + if do_sig_check and not event.signatures.get(sender_domain): + raise AuthError(403, "Event not signed by sending server") + if auth_events is None: # Oh, we don't know what the state of the room was, so we # are trusting that this is allowed (at least for now) @@ -86,6 +93,12 @@ class Auth(object): return True if event.type == EventTypes.Create: + room_id_domain = get_domain_from_id(event.room_id) + if room_id_domain != sender_domain: + raise AuthError( + 403, + "Creation event's room_id domain does not match sender's" + ) # FIXME return True @@ -108,6 +121,17 @@ class Auth(object): # FIXME: Temp hack if event.type == EventTypes.Aliases: + if not event.state_key: + raise AuthError( + 403, + "Alias event must have non-empty state_key" + ) + sender_domain = get_domain_from_id(event.sender) + if event.state_key != sender_domain: + raise AuthError( + 403, + "Alias event's state_key does not match sender's domain" + ) return True logger.debug( |