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

Prevent local user profiles leaking when a "per-room profile" is changed #10695

Closed
wants to merge 48 commits into from

Conversation

DMRobertson
Copy link
Contributor

@DMRobertson DMRobertson commented Aug 25, 2021

The plan is described here. In a nutshell, I want to make it so that local users' entries in the user directory only ever refer to their "public" profile, and completely ignore any per-room nicknames.

This goes some way towards fixing #5677, but we still have the problem of how to handle remote users' profiles.

David Robertson added 3 commits August 31, 2021 11:48
I don't think this will change any behaviour, but it makes PyCharm not
highlight them as warnings which is less distracting.
* type hint _get_next_batch
* Introduce an enum MatchChange so there is a name rather than an `Optional[bool]`
@DMRobertson DMRobertson force-pushed the dmr/user-directory-nickname-leaks branch from 500cea7 to 038a9c5 Compare August 31, 2021 10:48
David Robertson added 12 commits August 31, 2021 13:22
so that search_all_users config flag only controls searching.
Cost: extra rows in user_directory and user_directory_search for users
who are in no rooms. I think this is negligible since we already have
rows for these users in the profiles and users tables.
fixes a unit test. And we all seem to think that profiles should refer
to users, even if that isn't enforced as a foreign key constraint in the
db.
I've made profile changes update the user directory, which in turn
expects the corresponding user to actually exist.
@DMRobertson DMRobertson changed the title Draft: Dmr/user directory nickname leaks Prevent local user profiles leaking when a "per-room profile" is changed Sep 1, 2021
@DMRobertson DMRobertson marked this pull request as ready for review September 1, 2021 12:54
@DMRobertson DMRobertson requested a review from a team September 1, 2021 12:54
@DMRobertson
Copy link
Contributor Author

Tested this locally against element-web. It offered some kind of client-side suggestions which seemed to take into account per-room nicknames. However I confirmed the underlying response to /user_directory/search was returning the expected information: it did not yield results when searching for the per-room name, and it yielded the public name when searching by mxid.

@DMRobertson
Copy link
Contributor Author

There is a bit of a hole here. We still use the event displayname and avatar when handling someone joining a room. I don't think many clients will offer the chance to set a per-room nickname before you join, but it's possible from the protocol's POV.

@reivilibre
Copy link
Contributor

reivilibre commented Sep 2, 2021

There is a bit of a hole here. We still use the event displayname and avatar when handling someone joining a room.

out of interest, why is this the case? Is it difficult for some reason?

@reivilibre reivilibre self-assigned this Sep 2, 2021
@DMRobertson
Copy link
Contributor Author

There is a bit of a hole here. We still use the event displayname and avatar when handling someone joining a room.

out of interest, why is this the case? Is it difficult for some reason?

Just an oversight on my part. Until I started looking at this for remote users, I hadn't properly considered that local users could go down this code path (the branch with elif joined is MatchChange.now_true) with an event whose name didn't match their profile.

changelog.d/10695.bugfix Outdated Show resolved Hide resolved
synapse/handlers/user_directory.py Outdated Show resolved Hide resolved
synapse/handlers/user_directory.py Outdated Show resolved Hide resolved
synapse/handlers/user_directory.py Outdated Show resolved Hide resolved
@reivilibre
Copy link
Contributor

my review got ninja'd so hopefully things didn't get all tangled up and stop making sense

@DMRobertson
Copy link
Contributor Author

There's a lot of duplication between UserDirectoryBackgroundUpdateStore.populate_user_directory_process_rooms and UserDirectoryHandler._track_user_joined_room.

I'd like to introduce free functions in the handler's module that I can import in the store. (Or maybe the other way round?). I was going to say "this can be a separate PR", but...

I've just noticed that _populate_user_directory_process_rooms in UserDirectoryBackgroundUpdateStore will read from room_memberships and so will populate the directory with per-room data. So maybe it is worth introducing those free functions now.

@DMRobertson
Copy link
Contributor Author

I've just noticed that _populate_user_directory_process_rooms in UserDirectoryBackgroundUpdateStore will read from room_memberships and so will populate the directory with per-room data. So maybe it is worth introducing those free functions now.

Nah, this PR is long enough as it is. Let's consider this "don't leak local nicknames on updates". I'll open a separate PR for "don't leak local nicknames on rebuild".

@DMRobertson DMRobertson requested review from reivilibre and removed request for reivilibre September 3, 2021 12:49
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

Some substantial work has been done here; thanks for taking it on.

Happy that you're cleaning it up as you go!

docs/user_directory.md Outdated Show resolved Hide resolved
docs/user_directory.md Outdated Show resolved Hide resolved
docs/user_directory.md Outdated Show resolved Hide resolved
docs/user_directory.md Outdated Show resolved Hide resolved
synapse/handlers/user_directory.py Show resolved Hide resolved
tests/handlers/test_user_directory.py Show resolved Hide resolved
tests/handlers/test_user_directory.py Outdated Show resolved Hide resolved
tests/handlers/test_user_directory.py Outdated Show resolved Hide resolved
tests/handlers/test_user_directory.py Show resolved Hide resolved
changelog.d/10695.bugfix Outdated Show resolved Hide resolved
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

LGTM, though I'm still new to reviewing so would like to get another pair of eyes on this (both to check that I haven't missed anything, and so that I can see what else I should be looking out for as a reviewer).

synapse/handlers/user_directory.py Outdated Show resolved Hide resolved
@reivilibre reivilibre requested a review from a team September 7, 2021 10:11
David Robertson and others added 2 commits September 8, 2021 13:56
* Fix reactivated users not being added to directory

Co-authored-by: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com>
I meant to merge this to develop, but screwed my git-fu.

This reverts commit 401c1e8.
@DMRobertson
Copy link
Contributor Author

@reivilibre thank you for reviewing this. @richvdh took a look at this too but struggled to follow. I offered to chop this up into lots of smaller PRs to make it easier to follow. With that in mind, I'll close this.

@DMRobertson DMRobertson closed this Sep 9, 2021
@DMRobertson DMRobertson deleted the dmr/user-directory-nickname-leaks branch October 8, 2021 14:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants