diff options
author | Shay <shaysquared@gmail.com> | 2021-11-12 10:38:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-12 10:38:24 -0800 |
commit | 0bcae8ad56a64da72f278b4ec425d89c068b5df0 (patch) | |
tree | fb180bad1817783c55af293e21b4e4446c631a0e /synapse | |
parent | Add type hints to media repository storage module (#11311) (diff) | |
download | synapse-0bcae8ad56a64da72f278b4ec425d89c068b5df0.tar.xz |
Change display names/avatar URLs to None if they contain null bytes before storing in DB (#11230)
* change display names/avatar URLS to None if they contain null bytes * add changelog * add POC test, requested changes * add a saner test and remove old one * update test to verify that display name has been changed to None * make test less fragile
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/storage/databases/main/events.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index 596275c23c..120e4807d1 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -1641,8 +1641,8 @@ class PersistEventsStore: def _store_room_members_txn(self, txn, events, backfilled): """Store a room member in the database.""" - def str_or_none(val: Any) -> Optional[str]: - return val if isinstance(val, str) else None + def non_null_str_or_none(val: Any) -> Optional[str]: + return val if isinstance(val, str) and "\u0000" not in val else None self.db_pool.simple_insert_many_txn( txn, @@ -1654,8 +1654,10 @@ class PersistEventsStore: "sender": event.user_id, "room_id": event.room_id, "membership": event.membership, - "display_name": str_or_none(event.content.get("displayname")), - "avatar_url": str_or_none(event.content.get("avatar_url")), + "display_name": non_null_str_or_none( + event.content.get("displayname") + ), + "avatar_url": non_null_str_or_none(event.content.get("avatar_url")), } for event in events ], |