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

Commit 2bd022e

Browse files
committed
Merge commit 'abeab964d' into anoa/dinsic_release_1_21_x
* commit 'abeab964d': Make _get_e2e_device_keys_and_signatures_txn return an attrs (#8224) Fix errors when updating the user directory with invalid data (#8223) Explain better what GDPR-erased means (#8189) Convert additional databases to async/await part 3 (#8201) Convert appservice code to async/await. (#8207) Rename `_get_e2e_device_keys_txn` (#8222)
2 parents e85c635 + abeab96 commit 2bd022e

File tree

17 files changed

+207
-124
lines changed

17 files changed

+207
-124
lines changed

changelog.d/8189.doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Explain better what GDPR-erased means when deactivating a user.

changelog.d/8201.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert various parts of the codebase to async/await.

changelog.d/8207.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert various parts of the codebase to async/await.

changelog.d/8222.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor queries for device keys and cross-signatures.

changelog.d/8223.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes a longstanding bug where user directory updates could break when unexpected profile data was included in events.

changelog.d/8224.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor queries for device keys and cross-signatures.

docs/admin_api/user_admin_api.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ Deactivate Account
214214

215215
This API deactivates an account. It removes active access tokens, resets the
216216
password, and deletes third-party IDs (to prevent the user requesting a
217-
password reset). It can also mark the user as GDPR-erased (stopping their data
218-
from distributed further, and deleting it entirely if there are no other
219-
references to it).
217+
password reset).
218+
219+
It can also mark the user as GDPR-erased. This means messages sent by the
220+
user will still be visible by anyone that was in the room when these messages
221+
were sent, but hidden from users joining the room afterwards.
220222

221223
The api is::
222224

synapse/appservice/api.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@
1414
# limitations under the License.
1515
import logging
1616
import urllib
17+
from typing import TYPE_CHECKING, Optional
1718

1819
from prometheus_client import Counter
1920

20-
from twisted.internet import defer
21-
2221
from synapse.api.constants import EventTypes, ThirdPartyEntityKind
2322
from synapse.api.errors import CodeMessageException
2423
from synapse.events.utils import serialize_event
2524
from synapse.http.client import SimpleHttpClient
26-
from synapse.types import ThirdPartyInstanceID
25+
from synapse.types import JsonDict, ThirdPartyInstanceID
2726
from synapse.util.caches.response_cache import ResponseCache
2827

28+
if TYPE_CHECKING:
29+
from synapse.appservice import ApplicationService
30+
2931
logger = logging.getLogger(__name__)
3032

3133
sent_transactions_counter = Counter(
@@ -163,19 +165,20 @@ async def query_3pe(self, service, kind, protocol, fields):
163165
logger.warning("query_3pe to %s threw exception %s", uri, ex)
164166
return []
165167

166-
def get_3pe_protocol(self, service, protocol):
168+
async def get_3pe_protocol(
169+
self, service: "ApplicationService", protocol: str
170+
) -> Optional[JsonDict]:
167171
if service.url is None:
168172
return {}
169173

170-
@defer.inlineCallbacks
171-
def _get():
174+
async def _get() -> Optional[JsonDict]:
172175
uri = "%s%s/thirdparty/protocol/%s" % (
173176
service.url,
174177
APP_SERVICE_PREFIX,
175178
urllib.parse.quote(protocol),
176179
)
177180
try:
178-
info = yield defer.ensureDeferred(self.get_json(uri, {}))
181+
info = await self.get_json(uri, {})
179182

180183
if not _is_valid_3pe_metadata(info):
181184
logger.warning(
@@ -196,7 +199,7 @@ def _get():
196199
return None
197200

198201
key = (service.id, protocol)
199-
return self.protocol_meta_cache.wrap(key, _get)
202+
return await self.protocol_meta_cache.wrap(key, _get)
200203

201204
async def push_bulk(self, service, events, txn_id=None):
202205
if service.url is None:

synapse/handlers/profile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ async def set_displayname(
262262
Codes.FORBIDDEN,
263263
)
264264

265+
if not isinstance(new_displayname, str):
266+
raise SynapseError(400, "Invalid displayname")
267+
265268
if len(new_displayname) > MAX_DISPLAYNAME_LEN:
266269
raise SynapseError(
267270
400, "Displayname is too long (max %i)" % (MAX_DISPLAYNAME_LEN,)
@@ -386,6 +389,9 @@ async def set_avatar_url(
386389
400, "Changing avatar is disabled on this server", Codes.FORBIDDEN
387390
)
388391

392+
if not isinstance(new_avatar_url, str):
393+
raise SynapseError(400, "Invalid displayname")
394+
389395
if len(new_avatar_url) > MAX_AVATAR_URL_LEN:
390396
raise SynapseError(
391397
400, "Avatar URL is too long (max %i)" % (MAX_AVATAR_URL_LEN,)

synapse/handlers/user_directory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async def _handle_deltas(self, deltas):
234234
async def _handle_room_publicity_change(
235235
self, room_id, prev_event_id, event_id, typ
236236
):
237-
"""Handle a room having potentially changed from/to world_readable/publically
237+
"""Handle a room having potentially changed from/to world_readable/publicly
238238
joinable.
239239
240240
Args:
@@ -388,9 +388,15 @@ async def _handle_profile_change(self, user_id, room_id, prev_event_id, event_id
388388

389389
prev_name = prev_event.content.get("displayname")
390390
new_name = event.content.get("displayname")
391+
# If the new name is an unexpected form, do not update the directory.
392+
if not isinstance(new_name, str):
393+
new_name = prev_name
391394

392395
prev_avatar = prev_event.content.get("avatar_url")
393396
new_avatar = event.content.get("avatar_url")
397+
# If the new avatar is an unexpected form, do not update the directory.
398+
if not isinstance(new_avatar, str):
399+
new_avatar = prev_avatar
394400

395401
if prev_name != new_name or prev_avatar != new_avatar:
396402
await self.store.update_profile_in_user_dir(user_id, new_name, new_avatar)

0 commit comments

Comments
 (0)