mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 13:46:02 -04:00
Ensure we use a copy of the event content dict before modifying it in serialize_event (#9585)
This bug was discovered by DINUM. We were modifying `serialized_event["content"]`, which - if you've got `USE_FROZEN_DICTS` turned on or are [using a third party rules module](17cd48fe51/synapse/events/third_party_rules.py (L73-L76)
) - will raise a 500 if you try to a edit a reply to a message.
`serialized_event["content"]` could be set to the edit event's content, instead of a copy of it, which is bad as we attempt to modify it. Instead, we also end up modifying the original event's content. DINUM uses a third party rules module, which meant the event's content got frozen and thus an exception was raised.
To be clear, the problem is not that the event's content was frozen. In fact doing so helped us uncover the fact we weren't copying event content correctly.
This commit is contained in:
parent
cc324d53fe
commit
7b06f85c0e
5 changed files with 147 additions and 2 deletions
|
@ -32,6 +32,7 @@ from twisted.python.threadpool import ThreadPool
|
|||
from twisted.trial import unittest
|
||||
from twisted.web.resource import Resource
|
||||
|
||||
from synapse import events
|
||||
from synapse.api.constants import EventTypes, Membership
|
||||
from synapse.config.homeserver import HomeServerConfig
|
||||
from synapse.config.ratelimiting import FederationRateLimitConfig
|
||||
|
@ -229,6 +230,11 @@ class HomeserverTestCase(TestCase):
|
|||
self._hs_args = {"clock": self.clock, "reactor": self.reactor}
|
||||
self.hs = self.make_homeserver(self.reactor, self.clock)
|
||||
|
||||
# Honour the `use_frozen_dicts` config option. We have to do this
|
||||
# manually because this is taken care of in the app `start` code, which
|
||||
# we don't run. Plus we want to reset it on tearDown.
|
||||
events.USE_FROZEN_DICTS = self.hs.config.use_frozen_dicts
|
||||
|
||||
if self.hs is None:
|
||||
raise Exception("No homeserver returned from make_homeserver.")
|
||||
|
||||
|
@ -292,6 +298,10 @@ class HomeserverTestCase(TestCase):
|
|||
if hasattr(self, "prepare"):
|
||||
self.prepare(self.reactor, self.clock, self.hs)
|
||||
|
||||
def tearDown(self):
|
||||
# Reset to not use frozen dicts.
|
||||
events.USE_FROZEN_DICTS = False
|
||||
|
||||
def wait_on_thread(self, deferred, timeout=10):
|
||||
"""
|
||||
Wait until a Deferred is done, where it's waiting on a real thread.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue