Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Various auth.py fixes. #919

Merged
merged 4 commits into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, hs):
"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:
Expand All @@ -79,6 +79,13 @@ def check(self, event, auth_events):

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)
Expand All @@ -87,7 +94,6 @@ def check(self, event, auth_events):

if event.type == EventTypes.Create:
room_id_domain = get_domain_from_id(event.room_id)
sender_domain = get_domain_from_id(event.sender)
if room_id_domain != sender_domain:
raise AuthError(
403,
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def on_make_join_request(self, room_id, user_id):
logger.warn("Failed to create join %r because %s", event, e)
raise e

self.auth.check(event, auth_events=context.current_state)
self.auth.check(event, auth_events=context.current_state, do_sig_check=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment to explain why we can do do_sig_check=False here?


defer.returnValue(event)

Expand Down Expand Up @@ -918,7 +918,7 @@ def on_make_leave_request(self, room_id, user_id):
)

try:
self.auth.check(event, auth_events=context.current_state)
self.auth.check(event, auth_events=context.current_state, do_sig_check=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment to explain why we can do do_sig_check=False here?

except AuthError as e:
logger.warn("Failed to create new leave %r because %s", event, e)
raise e
Expand Down
4 changes: 2 additions & 2 deletions synapse/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def _resolve_auth_events(self, events, auth_events):
try:
# FIXME: hs.get_auth() is bad style, but we need to do it to
# get around circular deps.
self.hs.get_auth().check(event, auth_events)
self.hs.get_auth().check(event, auth_events, do_sig_check=False)
Copy link
Contributor

@NegativeMjark NegativeMjark Jul 14, 2016

Choose a reason for hiding this comment

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

Maybe add a comment to explain why we can do do_sig_check=False here?

prev_event = event
except AuthError:
return prev_event
Expand All @@ -391,7 +391,7 @@ def _resolve_normal_events(self, events, auth_events):
try:
# FIXME: hs.get_auth() is bad style, but we need to do it to
# get around circular deps.
self.hs.get_auth().check(event, auth_events)
self.hs.get_auth().check(event, auth_events, do_sig_check=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment to explain why we can do do_sig_check=False here?

return event
except AuthError:
pass
Expand Down