Skip to content

Commit

Permalink
Add option to allow profile queries without sharing a room (matrix-or…
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot authored and anoadragon453 committed Dec 16, 2019
1 parent 6920d88 commit bfb9565
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/6523.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add option `limit_profile_requests_to_users_who_share_rooms` to prevent requirement of a local user sharing a room with another user to query their profile information.
7 changes: 7 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ pid_file: DATADIR/homeserver.pid
#
#require_auth_for_profile_requests: true

# Uncomment to require a user to share a room with another user in order
# to retrieve their profile information. Only checked on Client-Server
# requests. Profile requests from other servers should be checked by the
# requesting server. Defaults to 'false'.
#
#limit_profile_requests_to_users_who_share_rooms: true

# If set to 'true', removes the need for authentication to access the server's
# public rooms directory through the client API, meaning that anyone can
# query the room directory. Defaults to 'false'.
Expand Down
13 changes: 13 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def read_config(self, config, **kwargs):
"require_auth_for_profile_requests", False
)

# Whether to require sharing a room with a user to retrieve their
# profile data
self.limit_profile_requests_to_users_who_share_rooms = config.get(
"limit_profile_requests_to_users_who_share_rooms", False,
)

if "restrict_public_rooms_to_local_users" in config and (
"allow_public_rooms_without_auth" in config
or "allow_public_rooms_over_federation" in config
Expand Down Expand Up @@ -621,6 +627,13 @@ def generate_config_section(
#
#require_auth_for_profile_requests: true
# Uncomment to require a user to share a room with another user in order
# to retrieve their profile information. Only checked on Client-Server
# requests. Profile requests from other servers should be checked by the
# requesting server. Defaults to 'false'.
#
#limit_profile_requests_to_users_who_share_rooms: true
# If set to 'true', removes the need for authentication to access the server's
# public rooms directory through the client API, meaning that anyone can
# query the room directory. Defaults to 'false'.
Expand Down
6 changes: 5 additions & 1 deletion synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,16 @@ def check_profile_query_allowed(self, target_user, requester=None):
be found to be in any room the server is in, and therefore the query
is denied.
"""

# Implementation of MSC1301: don't allow looking up profiles if the
# requester isn't in the same room as the target. We expect requester to
# be None when this function is called outside of a profile query, e.g.
# when building a membership event. In this case, we must allow the
# lookup.
if not self.hs.config.require_auth_for_profile_requests or not requester:
if (
not self.hs.config.limit_profile_requests_to_users_who_share_rooms
or not requester
):
return

# Always allow the user to query their own profile.
Expand Down
2 changes: 2 additions & 0 deletions tests/rest/client/v1/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def make_homeserver(self, reactor, clock):

config = self.default_config()
config["require_auth_for_profile_requests"] = True
config["limit_profile_requests_to_users_who_share_rooms"] = True
self.hs = self.setup_test_homeserver(config=config)

return self.hs
Expand Down Expand Up @@ -309,6 +310,7 @@ class OwnProfileUnrestrictedTestCase(unittest.HomeserverTestCase):
def make_homeserver(self, reactor, clock):
config = self.default_config()
config["require_auth_for_profile_requests"] = True
config["limit_profile_requests_to_users_who_share_rooms"] = True
self.hs = self.setup_test_homeserver(config=config)

return self.hs
Expand Down

0 comments on commit bfb9565

Please sign in to comment.