From 76c9f09e099aeccf6bcfcc1ef7a96e7230b100dd Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Fri, 15 Aug 2025 10:15:02 +0100 Subject: [PATCH] Fix a bug which could corrupt auth chains (#18746) [Complement tests](https://github.com/matrix-org/complement/pull/790) Basically, when we use `/state_ids` in conjunction with `/event` requests, the `/event` request can fail causing a partial state to be returned. When we persist the state, we process dependent events first. If we fail to process a dependent event due to missing the `auth_event`, we didn't update the in-memory event map. This meant that we could incorrectly persist events that depended on dropped events. Discovered via Chaos testing. ### Pull Request Checklist * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --- changelog.d/18746.bugfix | 1 + synapse/handlers/federation_event.py | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 changelog.d/18746.bugfix diff --git a/changelog.d/18746.bugfix b/changelog.d/18746.bugfix new file mode 100644 index 000000000..b80a880c0 --- /dev/null +++ b/changelog.d/18746.bugfix @@ -0,0 +1 @@ +Fix a bug which could corrupt auth chains making it impossible to perform state resolution. diff --git a/synapse/handlers/federation_event.py b/synapse/handlers/federation_event.py index 2ef7e77b1..511394c66 100644 --- a/synapse/handlers/federation_event.py +++ b/synapse/handlers/federation_event.py @@ -1728,6 +1728,9 @@ class FederationEventHandler: event, auth_event_id, ) + # Drop the event from the auth_map too, else we may incorrectly persist + # events which depend on this dropped event. + auth_map.pop(event.event_id, None) return auth.append(ae)