summary refs log tree commit diff
path: root/synapse (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Use create_and_send_new_client_events for bulk sending emma/patchesRory&2025-08-161-77/+27
|
* Further optimisation attemptsRory&2025-08-161-14/+25
|
* Try to optimise bulk sending some moreRory&2025-08-161-4/+38
|
* Clarify assertsRory&2025-08-161-1/+1
|
* Add bulk send events endpointRory&2025-08-162-1/+119
|
* RequestRatelimiter: expose can_do_actionRory&2025-08-161-0/+75
|
* Fix pagination with large gaps of rejected eventsNicolas Werner2025-08-161-2/+11
|
* fix: Always recheck `/messages` pagination data if a backfill might have โ†ตJason Little2025-08-162-37/+34
| | | | been needed (#28)
* Expose tombstone in room admin apiRory&2025-08-163-2/+40
|
* Use parse_boolean for unredacted contentRory&2025-08-161-3/+2
|
* Log policy server rejected eventsRory&2025-08-161-0/+7
|
* Log entire room if accessibility check failsRory&2025-08-161-0/+4
| | | | Signed-off-by: Rory& <root@rory.gay>
* Add too much logging to room summary over federationRory&2025-08-161-4/+36
| | | | Signed-off-by: Rory& <root@rory.gay>
* Hotfix: ignore rejected events in delayed_eventsRory&2025-08-161-1/+6
|
* Fast auth linksRory&2025-08-162-4/+47
|
* Make the Make Room Admin API choose to puppet the room creator in v12 rooms โ†ตAndrew Morgan2025-08-121-1/+1
| | | | (#18805)
* Add missing additional_creators fieldDevon Hudson2025-08-111-0/+1
|
* Update impl of `_calculate_upgraded_room_creation_content`Andrew Morgan2025-08-111-0/+6
|
* Add `HydraV11` to known room versionsAndrew Morgan2025-08-111-0/+1
|
* Update MSC4293 redact logic for hydra (#80)Devon Hudson2025-08-111-11/+26
|
* Add a parameter to allow room upgrades to auto join local users (#83)Erik Johnston2025-08-113-10/+231
|
* Fix olddeps & mypy errorsDevon Hudson2025-08-111-1/+1
|
* Support for room version 12Kegan Dougal2025-08-1119-138/+1286
|
* Set type of `user_id` on `is_server_admin` to str (#18786)Andrew Morgan2025-08-076-10/+7
|
* Revert "Fix `LaterGauge` metrics to collect from all servers (#18751)" (#18789)Eric Eastwood2025-08-0612-197/+140
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR reverts https://github.com/element-hq/synapse/pull/18751 ### Why revert? @reivilibre [found](https://matrix.to/#/!vcyiEtMVHIhWXcJAfl:sw1v.org/$u9OEmMxaFYUzWHhCk1A_r50Y0aGrtKEhepF7WxWJkUA?via=matrix.org&via=node.marinchik.ink&via=element.io) that our CI was failing in bizarre ways (thanks for stepping up to dive into this :bow:). Examples: - `twisted.internet.error.ProcessTerminated: A process has ended with a probable error condition: process ended by signal 9.` - `twisted.internet.error.ProcessTerminated: A process has ended with a probable error condition: process ended by signal 15.` <details> <summary>More detailed part of the log</summary> https://github.com/element-hq/synapse/actions/runs/16758038107/job/47500520633#step:9:6809 ``` tests.util.test_wheel_timer.WheelTimerTestCase.test_single_insert_fetch =============================================================================== Error: Traceback (most recent call last): File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/trial/_dist/disttrial.py", line 371, in task await worker.run(case, result) File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/trial/_dist/worker.py", line 305, in run return await self.callRemote(workercommands.Run, testCase=testCaseId) # type: ignore[no-any-return] File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/internet/defer.py", line 1187, in __iter__ yield self File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/internet/defer.py", line 1092, in _runCallbacks current.result = callback( # type: ignore[misc] File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/protocols/amp.py", line 1968, in _massageError error.trap(RemoteAmpError) File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/python/failure.py", line 431, in trap self.raiseException() File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/python/failure.py", line 455, in raiseException raise self.value.with_traceback(self.tb) twisted.internet.error.ProcessTerminated: A process has ended with a probable error condition: process ended by signal 9. tests.util.test_macaroons.MacaroonGeneratorTestCase.test_guest_access_token ------------------------------------------------------------------------------- Ran 4325 tests in 669.321s FAILED (skips=159, errors=62, successes=4108) while calling from thread Traceback (most recent call last): File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/internet/base.py", line 1064, in runUntilCurrent f(*a, **kw) File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/internet/base.py", line 790, in stop raise error.ReactorNotRunning("Can't stop reactor that isn't running.") twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running. joining disttrial worker #0 failed Traceback (most recent call last): File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/internet/defer.py", line 1853, in _inlineCallbacks result = context.run( File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/python/failure.py", line 467, in throwExceptionIntoGenerator return g.throw(self.value.with_traceback(self.tb)) File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/trial/_dist/worker.py", line 406, in exit await endDeferred File "/home/runner/.cache/pypoetry/virtualenvs/matrix-synapse-pswDeSvb-py3.9/lib/python3.9/site-packages/twisted/internet/defer.py", line 1187, in __iter__ yield self twisted.internet.error.ProcessTerminated: A process has ended with a probable error condition: process ended by signal 15. ``` </details> With more debugging (thanks @devonh for also stepping in as maintainer), we were finding that the CI was consistently failing at `test_exposed_to_prometheus` which was a bit of smoke because of all of the [metrics changes](https://github.com/element-hq/synapse/issues/18592) that were merged recently. Locally, although I wasn't able to reproduce the bizarre errors, I could easily see increased memory usage (~20GB vs ~2GB) and the `test_exposed_to_prometheus` test taking a while to complete when running a full test run (`SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests`). <img width="1485" height="78" alt="Lots of memory usage" src="https://github.com/user-attachments/assets/811e2a96-75e5-4a3c-966c-00dc0512cea9" /> After updating `test_exposed_to_prometheus` to dump the `latest_metrics_response = generate_latest(REGISTRY)`, I could see that it's a massive 3.2GB response. Inspecting the contents, we can see 4.1M (4,137,123) entries for just `synapse_background_update_status{server_name="test"} 3.0` which is a `LaterGauge`. I don't think we have 4.1M test cases so it's also unclear why we end up with so many samples but it does make sense that we do see a lot of duplicates because each `HomeserverTestCase` will create a homeserver for each test case that will `LaterGauge.register_hook(...)` (part of the https://github.com/element-hq/synapse/pull/18751 changes). `tests/storage/databases/main/test_metrics.py` ```python latest_metrics_response = generate_latest(REGISTRY) with open("/tmp/synapse-test-metrics", "wb") as f: f.write(latest_metrics_response) ``` After reverting the https://github.com/element-hq/synapse/pull/18751 changes, running the full test suite locally doesn't result in memory spikes and seems to run normally. ### Dev notes Discussion in the [`#synapse-dev:matrix.org`](https://matrix.to/#/!vcyiEtMVHIhWXcJAfl:sw1v.org/$vkMATs04yqZggVVd6Noop5nU8M2DVoTkrAWshw7u1-w?via=matrix.org&via=node.marinchik.ink&via=element.io) room. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [ ] 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. * [ ] [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))
* Implement the push rules for experimental MSC4306: Thread Subscriptions. โ†ตreivilibre2025-08-064-11/+84
| | | | | | | | | | | | (#18762) Follows: #18756 Implements: MSC4306 --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org> Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Update implementation of MSC4306: Thread Subscriptions to include automatic โ†ตreivilibre2025-08-059-54/+361
| | | | | | | | | | | | subscription conflict prevention as introduced in later drafts. (#18756) Follows: #18674 Implements new drafts of MSC4306 --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org> Co-authored-by: Eric Eastwood <erice@element.io>
* Fix `LaterGauge` metrics to collect from all servers (#18751)Eric Eastwood2025-08-0512-140/+197
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix `LaterGauge` metrics to collect from all servers Follow-up to https://github.com/element-hq/synapse/pull/18714 Previously, our `LaterGauge` metrics did include the `server_name` label as expected but we were only seeing the last server being reported in some cases. Any `LaterGauge` that we were creating multiple times was only reporting the last instance. This PR updates all `LaterGauge` to be created once and then we use `LaterGauge.register_hook(...)` to add in the metric callback as before. This works now because we store a list of callbacks instead of just one. I noticed this problem thanks to some [tests in the Synapse Pro for Small Hosts](https://github.com/element-hq/synapse-small-hosts/pull/173) repo that sanity check all metrics to ensure that we can see each metric includes data from multiple servers. ### Testing strategy 1. This is only noticeable when you run multiple Synapse instances in the same process. 1. TODO (see test that was added) ### Dev notes Previous non-global `LaterGauge`: ``` synapse_federation_send_queue_xxx synapse_federation_transaction_queue_pending_destinations synapse_federation_transaction_queue_pending_pdus synapse_federation_transaction_queue_pending_edus synapse_handlers_presence_user_to_current_state_size synapse_handlers_presence_wheel_timer_size synapse_notifier_listeners synapse_notifier_rooms synapse_notifier_users synapse_replication_tcp_resource_total_connections synapse_replication_tcp_command_queue synapse_background_update_status synapse_federation_known_servers synapse_scheduler_running_tasks ``` ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Make `.sleep(..)` return a coroutine (#18772)Erik Johnston2025-08-052-7/+3
| | | | | | | | This helps ensure that mypy can catch places where we don't await on it, like in #18763. --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Improve order of validation and ratelimiting in room creation (#18723)Eric Eastwood2025-08-041-31/+32
| | | | Spawning from looking at this stuff while reviewing https://github.com/element-hq/synapse/pull/18721
* Stabilise MAS integration (#18759)Quentin Gliech2025-08-0426-91/+815
| | | | | | | | | | | | | | | | | | | | | | | | | | This can be reviewed commit by commit There are a few improvements over the experimental support: - authorisation of Synapse <-> MAS requests is simplified, with a single shared secret, removing the need for provisioning a client on the MAS side - the tests actually spawn a real server, allowing us to test the rust introspection layer - we now check that the device advertised in introspection actually exist, making it so that when a user logs out, the tokens are immediately invalidated, even if the cache doesn't expire - it doesn't rely on discovery anymore, rather on a static endpoint base. This means users don't have to override the introspection endpoint to avoid internet roundtrips - it doesn't depend on `authlib` anymore, as we simplified a lot the calls done from Synapse to MAS We still have to update the MAS documentation about the Synapse setup, but that can be done later. --------- Co-authored-by: reivilibre <oliverw@element.io>
* Make room upgrades faster for rooms with many bans (#18574)Erik Johnston2025-08-043-24/+132
| | | | | | | | | | | | | We do this by a) not pulling out all membership events, and b) batch inserting bans. One blocking concern is that this bypasses the `update_membership` function, which otherwise all other membership events go via. In this case it's fine (having audited what it is doing), but I'm hesitant to set the precedent of bypassing it, given it has a lot of logic in there. --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Update metrics linting to be able to handle custom metrics (#18733)Eric Eastwood2025-08-016-18/+43
| | | Part of https://github.com/element-hq/synapse/issues/18592
* Fix cache metrics to collect from all servers (#18748)Eric Eastwood2025-08-011-4/+1
| | | | | | | | | | | | | | | | | | Follow-up to https://github.com/element-hq/synapse/pull/18604 Previously, our cache metrics did include the `server_name` label as expected but we were only seeing the last server being reported. This was caused because we would `CACHE_METRIC_REGISTRY.register_hook(metric_name, metric.collect)` where the `metric_name` only took into account the cache name so it would be overwritten every time we spawn a new server. This PR updates the register logic to include the `server_name` so we have a hook for every cache on every server as expected. I noticed this problem thanks to some [tests in the Synapse Pro for Small Hosts](https://github.com/element-hq/synapse-small-hosts/pull/173) repo that sanity check all metrics to ensure that we can see each metric includes data from multiple servers.
* Add missing `await` to `sleep` calls (#18763)Andrew Morgan2025-08-012-2/+2
|
* Fix `Failed to stop metrics` warnings in request metrics (#18753)Eric Eastwood2025-07-311-1/+0
| | | | | | | | | | ``` Failed to stop metrics: TypeError("prometheus_client.metrics.MetricWrapperBase.labels() got multiple values for keyword argument 'server_name'") ``` Noticed while running and debugging some tests. This bug was introduced in https://github.com/element-hq/synapse/pull/18724
* Allow suspended users to be auto-joined to server notice rooms (#18750)Andrew Morgan2025-07-302-53/+67
|
* Merge branch 'release-v1.135' into developAndrew Morgan2025-07-309-52/+220
|\
| * Improve performance of `is_server_admin` by adding a cache (#18747)Andrew Morgan2025-07-301-0/+4
| | | | | | | | Fixes https://github.com/element-hq/synapse/issues/18738
| * Fix deactivation running off the main process (#18716)Quentin Gliech2025-07-249-52/+216
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Best reviewed commit by commit. With the new dedicated MAS API (https://github.com/element-hq/synapse/pull/18520), it's possible that deactivation starts off the main process, which was not possible because of a few calls. I basically looked at everything that the deactivation handler was doing, reviewed whether it could run on workers or not, and find a workaround when possible --------- Co-authored-by: Eric Eastwood <erice@element.io>
* | Remove some obsolete Twisted version checks. (#18729)reivilibre2025-07-302-62/+4
| | | | | | | | | | | | Follows: #18727 --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* | Remove obsolete `/send_event` replication endpoint. (#18730)reivilibre2025-07-303-168/+0
| | | | | | | | | | Fixes: #18441 Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* | Refactor `Histogram` metrics to be homeserver-scoped (#18724)Eric Eastwood2025-07-2922-71/+182
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bulk refactor `Histogram` metrics to be homeserver-scoped. We also add lints to make sure that new `Histogram` metrics don't sneak in without using the `server_name` label (`SERVER_NAME_LABEL`). Part of https://github.com/element-hq/synapse/issues/18592 ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Observe response includes the TODO metrics with the `server_name` label ### Todo - [x] Wait for https://github.com/element-hq/synapse/pull/18656 to merge ### Dev notes ``` LoggingDatabaseConnection make_conn make_pool make_fake_db_pool ``` ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* | Resolve breaking change to `run_as_background_process` in module API (#18737)Eric Eastwood2025-07-292-6/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix https://github.com/element-hq/synapse/issues/18735 In https://github.com/element-hq/synapse/pull/18670, we updated `run_as_background_process` to add a `server_name` argument. Because this function is directly exported from the Synapse module API, this is a breaking change to any downstream Synapse modules that use `run_as_background_process`. This PR shims and deprecates the existing `run_as_background_process(...)` for modules by providing a stub `server_name` value and introduces a new `ModuleApi.run_as_background_process(...)` that covers the `server_name` logic automagically.
* | Allow admins to see policy server-flagged events (#18585)Travis Ralston2025-07-296-7/+37
| |
* | Refactor `LaterGauge` metrics to be homeserver-scoped (#18714)Eric Eastwood2025-07-2912-103/+141
| | | | | | | | Part of https://github.com/element-hq/synapse/issues/18592
* | MSC4306: expose feature in the client version (#18722)Benjamin Bouvier2025-07-291-0/+2
| |
* | Refactor `GaugeBucketCollector` metrics to be homeserver-scoped (#18715)Eric Eastwood2025-07-292-14/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactor `GaugeBucketCollector` metrics to be homeserver-scoped Part of https://github.com/element-hq/synapse/issues/18592 ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Adjust the number of [`msecs` in the `looping_call` so that `_read_forward_extremities`](https://github.com/element-hq/synapse/blob/a82b8a966a7dbe218cb788548683a83ec404e468/synapse/storage/databases/main/metrics.py#L79) runs immediately instead of after an hour. 1. Observe response includes the `synapse_forward_extremities` and `synapse_excess_extremity_events` metrics with the `server_name` label
* | Refactor `Gauge` metrics to be homeserver-scoped (#18725)Eric Eastwood2025-07-2923-78/+200
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bulk refactor `Gauge` metrics to be homeserver-scoped. We also add lints to make sure that new `Gauge` metrics don't sneak in without using the `server_name` label (`SERVER_NAME_LABEL`). Part of https://github.com/element-hq/synapse/issues/18592 ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Observe response includes the TODO metrics with the `server_name` label ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* | Refactor `Counter` metrics to be homeserver-scoped (#18656)Eric Eastwood2025-07-2535-228/+628
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bulk refactor `Counter` metrics to be homeserver-scoped. We also add lints to make sure that new `Counter` metrics don't sneak in without using the `server_name` label (`SERVER_NAME_LABEL`). All of the "Fill in" commits are just bulk refactor. Part of https://github.com/element-hq/synapse/issues/18592 ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Observe response includes the `synapse_user_registrations_total`, `synapse_http_server_response_count_total`, etc metrics with the `server_name` label
* | Reduce database usage in Sliding Sync by not querying for background update โ†ตreivilibre2025-07-241-1/+13
| | | | | | | | | | | | completion after the update is known to be complete. (#18718) Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org> Co-authored-by: Eric Eastwood <erice@element.io>
* | Add configurable rate limiting for the creation of rooms. (#18514)reivilibre2025-07-242-7/+35
| | | | | | | | | | | | | | | | | | | | | | | | Default values will be 1 room per minute, with a burst count of 10. It's hard to imagine most users will be affected by this default rate, but it's intentionally non-invasive in case of bots or other users that need to create rooms at a large rate. Server admins might want to down-tune this on their deployments. --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* | MSC4306: register the thread subscriptions servlet in the client servlet โ†ตBenjamin Bouvier2025-07-242-2/+6
| | | | | | | | | | | | section (#18726) The MSC4306 endpoints were never registered, and thus never made available, even if the experimental feature flag was enabled.
* | Refactor background process metrics to be homeserver-scoped (#18670)Eric Eastwood2025-07-2364-394/+812
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Part of https://github.com/element-hq/synapse/issues/18592 Separated out of https://github.com/element-hq/synapse/pull/18656 because it's a bigger, unique piece of the refactor ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Observe response includes the background processs metrics (`synapse_background_process_start_count`, `synapse_background_process_db_txn_count_total`, etc) with the `server_name` label
* | Add support for MSC4293 - Redact on Kick/Ban (#18540)Shay2025-07-235-13/+209
| |
* | Allow return code 403 when fetching profile via federation (#18696)Andreas Fischer2025-07-221-1/+1
| |
* | Add debug log when `HMAC incorrect` (#18474)Eric Eastwood2025-07-222-0/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Spawning from getting `HMAC incorrect` errors that seem unexplainable except for the `registration_shared_secret` being misconfigured. It's also possible my HMAC calculation is incorrect but every time I double-check the result with the [known-good Python example](https://github.com/element-hq/synapse/blob/553e124f766584456fbdb6d1aa37fdd12ad54dad/docs/admin_api/register_api.md) (which matches [Synapse's source](https://github.com/element-hq/synapse/blob/24e849e483820762fa2d231ad702e6aeaa23829c/synapse/rest/admin/users.py#L618-L633)), it's as expected. With these logs, we can actually debug whether `registration_shared_secret` is being configured correctly or not. It also helps specifically when using `registration_shared_secret_path` since the default Synapse behavior (of creating the file and secret if it doesn't exist) can mask deployment race condition where we would start up Synapse before the `registration_shared_secret_path` file was put in place: > **`registration_shared_secret_path`** > > [...] > > If this file does not exist, Synapse will create a new shared secret on startup and store it in this file. > > *-- [Synapse config docs](https://github.com/element-hq/synapse/blob/6521406a37a40a490a1a435f3616c02cfcbbac16/docs/usage/configuration/config_documentation.md#registration_shared_secret_path)* This only applies to the [`POST /_synapse/admin/v1/register`](https://github.com/element-hq/synapse/blob/553e124f766584456fbdb6d1aa37fdd12ad54dad/docs/admin_api/register_api.md) endpoint but does log very sensitive information so we've made it so you have to explicitly enable the logs by configuring `synapse.rest.admin.users.registration_debug` (does not inherit root log level) (via our new `ExplicitlyConfiguredLogger`) `homeserver.yaml` ```yaml log_config: "/myserver.log.config.yaml" ``` `myserver.log.config.yaml` ```yaml version: 1 formatters: precise: format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s' handlers: # ... file/buffer handler (see `sample_log_config.yaml`) # A handler that writes logs to stderr. Unused by default, but can be used # instead of "buffer" and "file" in the logger handlers. console: class: logging.StreamHandler formatter: precise loggers: synapse.storage.SQL: # beware: increasing this to DEBUG will make synapse log sensitive # information such as access tokens. level: INFO # Has to be explicitly configured as such. Will not inherit from the root level even if it's set to DEBUG synapse.rest.admin.users.registration_debug: level: DEBUG root: level: INFO handlers: [console] disable_existing_loggers: false ```
* | Configure HTTP proxy in file config (#18686)Eric Eastwood2025-07-226-56/+202
|/ | | | | | This PR makes it possible to configure the HTTP proxy on a per-homeserver-tenant basis. `http_proxy`, `https_proxy`, `no_proxy_hosts`
* Remove stray dev logOlivier 'reivilibre2025-07-221-1/+0
|
* Reduce log spam when client stops downloading media while it is being โ†ตDevon Hudson2025-07-211-9/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | streamed to them (`ConsumerStopProducingError`) (#18699) The case where a consumer stops downloading media that is currently being streamed is now able to be handled explicitly. That scenario isn't really an error, it is expected behaviour. This PR adds a custom exception which allows us to drop the log level for this specific case from `WARNING` to `INFO`. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Add an option to issue redactions as admin user on admin redaction endpoint โ†ตShay2025-07-212-4/+20
| | | | | | | | | (#18671) Currently the [admin redaction endpoint](https://element-hq.github.io/synapse/latest/admin_api/user_admin_api.html#redact-all-the-events-of-a-user) defaults to puppeting the user being redacted. This PR adds an optional param `use_admin`, which when provided issues the redactions as the admin user instead.
* Dedicated MAS API (#18520)Quentin Gliech2025-07-217-3/+849
| | | | | | | | | | | | | | | | | | | | | This introduces a dedicated API for MAS to consume. Companion PR on the MAS side: element-hq/matrix-authentication-service#4801 This has a few advantages over the previous admin API: - it works on workers (this will be documented once we stabilise MSC3861 as a whole) - it is more efficient because more focused - it propagates trace contexts from MAS - it is only accessible to MAS (through the shared secret) and will let us remove the weird hack that made this token 'admin' with a ghost '@__oidc_admin:' user The next MAS version should support it, but will be opt-in. The version after that should use this new API by default --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Add experimental and incomplete support for MSC4306: Thread Subscriptions. โ†ตreivilibre2025-07-2120-3/+826
| | | | | | | | | | | | (#18674) Implements: [MSC4306](https://github.com/matrix-org/matrix-spec-proposals/blob/rei/msc_thread_subscriptions/proposals/4306-thread-subscriptions.md) (partially) What's missing: - Changes to push rules Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Update msc3861_delegated.py spelling correction (#18697)Strac Consulting Engineers Pty Ltd2025-07-181-1/+1
|
* Don't allow tagnames longer than 255 bytes (#18660)Alex Durham2025-07-181-1/+14
|
* Move device changes off the main process (#18581)Quentin Gliech2025-07-1831-1375/+1689
| | | | | | | | | | | | | | | | | | | | | | | | | The main goal of this PR is to handle device list changes onto multiple writers, off the main process, so that we can have logins happening whilst Synapse is rolling-restarting. This is quite an intrusive change, so I would advise to review this commit by commit; I tried to keep the history as clean as possible. There are a few things to consider: - the `device_list_key` in stream tokens becomes a `MultiWriterStreamToken`, which has a few implications in sync and on the storage layer - we had a split between `DeviceHandler` and `DeviceWorkerHandler` for master vs. worker process. I've kept this split, but making it rather writer vs. non-writer worker, using method overrides for doing replication calls when needed - there are a few operations that need to happen on a single worker at a time. Instead of using cross-worker locks, for now I made them run on the first writer on the list --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Clean up `MetricsResource` and Prometheus hacks (#18687)Eric Eastwood2025-07-173-70/+86
| | | | | | | | | Clean up `MetricsResource`, Prometheus hacks (`_set_prometheus_client_use_created_metrics`), and better document why we care about having a separate `metrics` listener type. These clean-up changes have been split out from https://github.com/element-hq/synapse/pull/18584 since that PR was closed.
* Start and stop the Tokio runtime with the Twisted reactor (#18691)Quentin Gliech2025-07-172-2/+5
| | | | | | | | | | | | | | | Fixes https://github.com/element-hq/synapse/issues/18659 This changes the Tokio runtime to be attached to the Twisted reactor. This way, the Tokio runtime starts when the Twisted reactor starts, and *not* when the module gets loaded. This is important as starting the runtime on module load meant that it broke when Synapse was started with `daemonize`/`synctl`, as forks only retain the calling threads, breaking the Tokio runtime. This also changes so that the HttpClient gets the Twisted reactor explicitly as parameter instead of loading it from `twisted.internet.reactor`
* Stabilize support for custom profile fields. (#18635)Patrick Cloke2025-07-173-192/+52
|
* Include `event_id` when getting state with `?format=event` (#18675)Tulir Asokan2025-07-171-2/+14
|
* Fix sequence migration for autoincrement tables in synapse_port_db (#18677)Mรคrt2025-07-171-8/+81
| | | | Closes https://github.com/element-hq/synapse/issues/18053 - the sliding sync tables will now migrate properly.
* Refactor cache metrics to be homeserver-scoped (#18604)Eric Eastwood2025-07-1652-130/+403
| | | | | (add `server_name` label to cache metrics). Part of https://github.com/element-hq/synapse/issues/18592
* Refactor `Measure` block metrics to be homeserver-scoped (v2) (#18601)Eric Eastwood2025-07-1531-94/+373
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactor `Measure` block metrics to be homeserver-scoped (add `server_name` label to block metrics). Part of https://github.com/element-hq/synapse/issues/18592 ### Testing strategy #### See behavior of previous `metrics` listener 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9323/metrics` 1. Observe response includes the block metrics (`synapse_util_metrics_block_count`, `synapse_util_metrics_block_in_flight`, etc) #### See behavior of the `http` `metrics` resource 1. Add the `metrics` resource to a new or existing `http` listeners in your `homeserver.yaml` ```yaml listeners: - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` (it's just a `GET` request so you can even do in the browser) 1. Observe response includes the block metrics (`synapse_util_metrics_block_count`, `synapse_util_metrics_block_in_flight`, etc)
* Remove `allow_no_prev_events` option (MSC2716 cleanup) (#18676)Eric Eastwood2025-07-152-55/+6
| | | | | | | | | | This option is no longer used since we backed out the MSC2716 changes in https://github.com/matrix-org/synapse/pull/15748 and is even mentioned as a follow-up task in the PR description there. The `allow_no_prev_events` option was first introduced in https://github.com/matrix-org/synapse/pull/11243 to support MSC2716 back in the day.
* Advertise support for Matrix v1.12 (#18647)Andrew Morgan2025-07-151-0/+1
|
* Update URL Preview code to work with `lxml` 6.0.0 (#18622)Andrew Morgan2025-07-151-4/+26
|
* Bump mypy from 1.13.0 to 1.16.1 (#18653)dependabot[bot]2025-07-1516-29/+58
|
* Fix CPU and database spinning when retrying sending events to servers whilst โ†ตreivilibre2025-07-151-1/+13
| | | | | | | | | | | | at the same time purging those events. (#18499) Fixes: #18491 Fix hotlooping due to skipped PDUs if there is still no progress to be made. This could bite if the event was purged since being skipped during catch-up. Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Add recaptcha_{private,public}_key_path config option (#17984)V024602025-07-141-1/+25
| | | | | | | | Another config option on my quest to a `*_path` variant for every secret. Adds the config options `recaptcha_private_key_path` and `recaptcha_public_key_path`. Tests and docs are included. A public key is of course no secret, but it is closely related to the private key, so itโ€™s still useful to have a `*_path` variant for it.
* Allow admins to see soft failed events (if they want to) (#18238)Travis Ralston2025-07-146-4/+86
|
* Update `latest_deps` workflow to migrate `poetry --no-dev` -> `--without โ†ตAndrew Morgan2025-07-111-1/+1
| | | | dev` (#18617)
* Document config file merge behavior (#18664)V024602025-07-111-1/+4
| | | | Explains in the doc comment of `synapse.config._base.read_config_file` how config files are merged.
* Remove unnecessary replication calls (#18564)Quentin Gliech2025-07-116-111/+96
| | | | | | | | | | | | | | | | | | | This should be reviewed commit by commit. Nowadays it's trivial to propagate cache invalidations, which means we can move some things off the main process, and not go through HTTP replication. `ReplicationGetQueryRestServlet` appeared to be unused, and was very weird, as it was being called if the current instance is the main oneโ€ฆ to RPC to the main one (if no instance is set on a replication client, it makes it to the main process) The other two handlers could be relatively trivially moved to any workers, moving some methods to the worker store. **I've intentionally not removed the replication servlets yet** so that it's safe to rollout, and will do another PR that clean those up to remove on the N+1 version
* Move registrations off the main worker (#18552)Quentin Gliech2025-07-104-189/+173
| | | | This is mainly moving a few store methods around. Note that this doesn't yet remove the replication servlet to avoid breaking during rollout.
* Add ability to limit amount uploaded by a user (#18527)Erik Johnston2025-07-105-66/+122
| | | | | | | You can now configure how much media can be uploaded by a user in a given time period. Note the first commit here is a refactor of create/upload content function
* Add plain-text handling for rich-text topics as per MSC3765 (#18195)Johannes Marbach2025-07-0910-53/+184
| | | | | | | | | | | | | | | | | | | | | | | | | | This implements https://github.com/matrix-org/matrix-spec-proposals/pull/3765 which is already merged and, therefore, can use stable identifiers. For `/publicRooms` and `/hierarchy`, the topic is read from the eponymous field of the `current_state_events` table. Rather than introduce further columns in this table, I changed the insertion / update logic to write the plain-text topic from the rich topic into the existing field. This will not take effect for existing rooms unless their topic is changed. However, existing rooms shouldn't have rich topics to begin with. Similarly, for server-side search, I changed the insertion logic of the `event_search` table to prefer the value from the rich topic. Again, existing events shouldn't have rich topics and, therefore, don't need to be migrated in the table. Spec doc: https://spec.matrix.org/v1.15/client-server-api/#mroomtopic Part of supporting Matrix v1.15: https://spec.matrix.org/v1.15/client-server-api/#mroomtopic Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org> Co-authored-by: Eric Eastwood <erice@element.io>
* Add experimental support for MSC4277: Harmonizing the reporting endpoints โ†ตJohannes Marbach2025-07-092-6/+25
| | | | | | (#18263) [MSC4277](https://github.com/matrix-org/matrix-spec-proposals/pull/4277): Harmonizing the reporting endpoints
* Speed up inserting into stream_positions (#18672)Erik Johnston2025-07-091-9/+5
| | | | By ensuring we don't do a no-op `UPDATE`, as this causes new tuples to be written in postgres.
* Replace PyICU with Rust `icu_segmenter` crate (#18553)Andrew Morgan2025-07-032-41/+11
| | | | | Co-authored-by: anoa's Codex Agent <codex@amorgan.xyz> Co-authored-by: Quentin Gliech <quenting@element.io>
* Fix GET /_matrix/federation/v1/query/profile response (#18593)Alex Durham2025-07-031-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't send the fields `avatar_url` and `displayname` when they are not defined for the queried user. Before this change they would be sent and set to null in the JSON response object, which would violate the OpenAPI definitions (https://spec.matrix.org/v1.11/server-server-api/#get_matrixfederationv1queryprofile). Fixes: #18442 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Quentin Gliech <quenting@element.io>
* Forbid locked users from using `POST /login` (#18594)Andrew Ferrazzutti2025-07-023-12/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Discussed in the [Synapse Dev room](https://matrix.to/#/!vcyiEtMVHIhWXcJAfl:sw1v.org/$K4UojQtvaSpxSe35TWFXtKWGoAuHwHFcKo8qn2lwxSs?via=matrix.org&via=element.io&via=envs.net) ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Log the room ID we're purging state for (#18625)Erik Johnston2025-07-021-0/+7
| | | So we can see what we're deleting.
* Stop sending or processing the `origin` field in PDUs (#18418)Andrew Morgan2025-07-015-15/+4
| | | | | Co-authored-by: Quentin Gliech <quenting@element.io> Co-authored-by: Eric Eastwood <erice@element.io>
* Add `via` param to hierarchy enpoint (#18070)Krishan2025-06-303-3/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Pull Request Checklist Implementation of [MSC4235](https://github.com/matrix-org/matrix-spec-proposals/pull/4235) as per suggestion in [pull request 17750](https://github.com/element-hq/synapse/pull/17750#issuecomment-2411248598). <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Quentin Gliech <quenting@element.io>
* Speed up device deletion (#18602)Erik Johnston2025-06-306-84/+224
| | | | | | | | | This is to handle the case of deleting lots of "bot" devices at once. Reviewable commit-by-commit --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Skip processing policy server events through policy server (#18605)Travis Ralston2025-06-301-0/+3
| | | | Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
* Improve performance of device deletion by adding missing index. (#18582)reivilibre2025-06-302-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <ol> <li> Reorder columns in `event_txn_id_device_id_txn_id` index \ This now satisfies the foreign key on `(user_id, device_id)` making reverse lookups, as needed for device deletions, more efficient. This improves device deletion performance by on the order of 8 to 10ร— on matrix.org. </li> </ol> Rationale: ## On the `event_txn_id_device_id` table: We currently have this index: ```sql -- This ensures that there is only one mapping per (room_id, user_id, device_id, txn_id) tuple. CREATE UNIQUE INDEX IF NOT EXISTS event_txn_id_device_id_txn_id ON event_txn_id_device_id(room_id, user_id, device_id, txn_id); ``` The main way we use this table is ```python return await self.db_pool.simple_select_one_onecol( table="event_txn_id_device_id", keyvalues={ "room_id": room_id, "user_id": user_id, "device_id": device_id, "txn_id": txn_id, }, retcol="event_id", allow_none=True, desc="get_event_id_from_transaction_id_and_device_id", ) ``` But this foreign key is relatively unsupported, making deletions in the devices table inefficient (full index scan on the above index): ```sql FOREIGN KEY (user_id, device_id) REFERENCES devices (user_id, device_id) ON DELETE CASCADE ``` I propose re-ordering the columns in that index to: `(user_id, device_id, room_id, txn_id)` (by replacing it). That way the foreign key back-check can rely on the prefix of this index, but it's still useful for the original purpose it was made for. It doesn't take any extra disk space and does not harm write performance (because the same amount of writing work needs to be performed). --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Improve docstring on `simple_upsert_many`. (#18573)reivilibre2025-06-301-4/+42
| | | | | | | | | It came up that this was somewhat confusing and an example might help. So here's an example :) --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Add `forget_forced_upon_leave` capability as per MSC4267 (#18196)Johannes Marbach2025-06-273-1/+9
| | | | | | | This adds the capability from https://github.com/matrix-org/matrix-spec-proposals/pull/4267 under an experimental feature. Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
* Fix backwards compat for `DirectServeJsonResource` (#18600)Erik Johnston2025-06-2616-19/+39
| | | | | As that appears in the module API. Broke in #18595.
* Add `federated_user_may_invite` spam checker callback (#18241)Tulir Asokan2025-06-263-2/+68
| | | | | Co-authored-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Lift pausing on ratelimited requests to http layer (#18595)Erik Johnston2025-06-2519-27/+40
| | | | | | | | | | | | | | | | When a request gets ratelimited we (optionally) wait ~500ms before returning to mitigate clients that like to tightloop on request failures. However, this is currently implemented by pausing request processing when we check for ratelimits, which might be deep within request processing, and e.g. while locks are held. Instead, let's hoist the pause to the very top of the HTTP handler. Hopefully, this mitigates the issue where a user sending lots of events to a single room can see their requests time out due to the combination of the linearizer and the pausing of the request. Instead, they should see the requests 429 after ~500ms. The first commit is a refactor to pass the `Clock` to `AsyncResource`, the second commit is the behavioural change.
* Fix registering of background updates for split main/state db (#18509)Patrick Cloke2025-06-253-31/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The background updates are being registered on an object that is for the _state_ database, but the actual tables are on the _main_ database. This just moves them to a different store that can access the right stuff. I noticed this when trying to do a full schema dump cause I was curious what has changed since the last one. Fixes #16054 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Unbreak unit tests with Twisted `25.5.0` by add `parsePOSTFormSubmission` โ†ตAndrew Morgan2025-06-243-9/+23
| | | | | | arg to `FakeSite` (#18577) Co-authored-by: anoa's Codex Agent <codex@amorgan.xyz>
* Add report user API from MSC4260 (#18120)Travis Ralston2025-06-206-0/+201
| | | | | Co-authored-by: turt2live <1190097+turt2live@users.noreply.github.com> Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Clean up old `device_federation_inbox` rows (#18546)Erik Johnston2025-06-183-1/+100
| | | Fixes https://github.com/element-hq/synapse/issues/17370
* Speed up MAS token introspection (#18357)Erik Johnston2025-06-163-27/+60
| | | | | | | | | | We do this by shoving it into Rust. We believe our python http client is a bit slow. Also bumps minimum rust version to 1.81.0, released last September (over six months ago) To allow for async Rust, includes some adapters between Tokio in Rust and the Twisted reactor in Python.
* bugfix: assert we always pass the create event to get_user_power_level (#18545)Kegan Dougal2025-06-135-31/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The create event is required if there is no PL event, in which case the creator gets PL100. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* bugfix: calculate the PL for non-creators correctly in v11 rooms (#18547)Kegan Dougal2025-06-131-1/+1
| | | | Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Fix typo of Math.pow, `^` -> `**` (#18543)Andrew Morgan2025-06-133-5/+24
|
* Fix bug where sliding sync ignored `room_id_to_include` option (#18535)Erik Johnston2025-06-132-40/+93
| | | | | | | | This was correctly handled for the "fallback" case where the background updates hadn't finished --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Enable `flake8-logging` and `flake8-logging-format` rules in Ruff and fix โ†ตQuentin Gliech2025-06-1344-109/+142
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | related issues throughout the codebase (#18542) This can be reviewed commit by commit. This enables the `flake8-logging` and `flake8-logging-format` rules in Ruff, as well as logging exception stack traces in a few places where it makes sense - https://docs.astral.sh/ruff/rules/#flake8-logging-log - https://docs.astral.sh/ruff/rules/#flake8-logging-format-g ### Linting to avoid pre-formatting log messages See [`adamchainz/flake8-logging` -> *LOG011 avoid pre-formatting log messages*](https://github.com/adamchainz/flake8-logging/blob/152db2f167355fb23e401bf68046c57cb128a2ae/README.rst#log011-avoid-pre-formatting-log-messages) Practically, this means prefer placeholders (`%s`) over f-strings for logging. This is because placeholders are passed as args to loggers, so they can do special handling of them. For example, Sentry will record the args separately in their logging integration: https://github.com/getsentry/sentry-python/blob/c15b390dfe1ca5c01b30dd56b35d693bb50b413c/sentry_sdk/integrations/logging.py#L280-L284 One theoretical small perf benefit is that log levels that aren't enabled won't get formatted, so it doesn't unnecessarily create formatted strings
* Log user deactivations (#18541)Will Hunt2025-06-121-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | One liner to give us more clarity when auditing deactivations of user accounts. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [ ] Pull request is based on the develop branch * [ ] 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. * [ ] [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))
* bugfix: ensure _get_power_level_for_sender works when there is no PL event โ†ตKegan Dougal2025-06-101-1/+13
| | | | (#18534)
* Default to `public` join rule in remote summary (#18493)nexy75742025-06-091-1/+1
| | | See: https://github.com/element-hq/synapse/issues/18358#issuecomment-2866119550
* Don't allow users to ignore themselves. (#18508)Will Hunt2025-06-061-0/+4
| | | | | | | | | | | Fixes the self-ignore issues we've being seeing of reports of by ignoring bad requests from clients. Fixes https://github.com/element-hq/synapse/issues/11963 Fix https://github.com/element-hq/element-web/issues/29969 although this should also be fixed on the client to avoid confusing errors popping up while rejecting invites. Related to https://github.com/matrix-org/matrix-rust-sdk/issues/5073
* Recover an appservice if a successful ping occurs. (#18521)Will Hunt2025-06-062-3/+40
| | | | | | | | | | | | | | Fixes https://github.com/element-hq/synapse/issues/14240 This scratches an itch that i've had for years. We regularly run into the issue where (especially in development) appservices can go down for a period and them come back up. The ping endpoint was introduced some time ago which means Synapse can determine if an AS is up more or less immediately, so we might as well use that to schedule transaction redelivery. I believe transaction scheduling logic is largely implementation specific, so we should be in the clear to do this without any spec changes.
* Remove destinations from sending if not whitelisted (#18484)Devon Hudson2025-06-062-8/+70
| | | | Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
* Export RatelimitOverride from ModuleApi (#18513)Hugh Nimmo-Smith2025-06-064-3/+19
|
* Reduce disk wastage by cleaning up `received_transactions` older than 1 day, โ†ตreivilibre2025-06-051-2/+2
| | | | | | | | | | | | rather than 30 days. (#18310) Clean up `received_transactions` older than 1 day, rather than 30 days \ Reduces disk waste by homeservers Closes #6437 --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Add support for MSC4155 Invite filtering (#18288)Will Hunt2025-06-0512-4/+205
| | | | | | | | | | This implements https://github.com/matrix-org/matrix-spec-proposals/pull/4155, which adds support for a new account data type that blocks an invite based on some conditions in the event contents. --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Add ratelimit callbacks to module API to allow dynamic ratelimiting (#18458)Hugh Nimmo-Smith2025-06-046-3/+111
|
* Add user_may_send_state_event callback to spam checker module API (#18455)Hugh Nimmo-Smith2025-06-043-0/+80
|
* Add media repository callbacks to module API to control media upload size โ†ตHugh Nimmo-Smith2025-06-046-9/+137
| | | | | | | | (#18457) Adds new callbacks for media related functionality: - `get_media_config_for_user` - `is_user_allowed_to_upload_media_of_size`
* Pass room_config argument to user_may_create_room spam checker module โ†ตHugh Nimmo-Smith2025-06-042-28/+65
| | | | | | | | | | | | | | callback (#18486) This PR adds an additional `room_config` argument to the `user_may_create_room` spam checker module API callback. It will continue to work with implementations of `user_may_create_room` that do not expect the additional parameter. A side affect is that on a room upgrade the spam checker callback is called *after* doing some work to calculate the state rather than before. However, I hope that this is acceptable given the relative infrequency of room upgrades.
* Make user_type extensible and allow default user_type to be set (#18456)Hugh Nimmo-Smith2025-06-037-10/+75
|
* Mark dehydrated devices in admin get devices endpoint (#18252)Hubert Chathi2025-05-281-0/+11
| | | | Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Add option to limit key queries to users sharing rooms as per MSC4263 (#18180)Johannes Marbach2025-05-283-6/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements https://github.com/matrix-org/matrix-spec-proposals/pull/4263. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
* fix(device-handler): make _maybe_retry_device_resync thread-safe (#18391)3nprob2025-05-261-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | A race-condition may render concurrent retry loops. Use an actual `Lock` for guarding single access of device resyncing retrying. ### 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))
* Don't move invited users to new room when shutting down room (#18471)Shay2025-05-231-11/+12
| | | This is confusing to users who received unwanted invites.
* Policy server part 1: Actually call the policy server (#18387)Travis Ralston2025-05-217-1/+242
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Roughly reviewable commit-by-commit. This is the first part of adding policy server support to Synapse. Other parts (unordered), which may or may not be bundled into fewer PRs, include: * Implementation of a bulk API * Supporting a moderation server config (the `fallback_*` options of https://github.com/element-hq/policyserv_spam_checker ) * Adding an "early event hook" for appservices to receive federation transactions *before* events are processed formally * Performance and stability improvements ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: turt2live <1190097+turt2live@users.noreply.github.com> Co-authored-by: Devon Hudson <devon.dmytro@gmail.com>
* Include room ID in room deletion status response (#18318)Dagfinn Ilmari Mannsรฅker2025-05-201-0/+1
| | | | When querying by `delete_id` it's handy to see which room the delete pertains to.
* Merge branch 'master' into developDevon Hudson2025-05-205-3/+110
|\
| * Fix up the topological ordering for events above `MAX_DEPTH` (#18447)Erik Johnston2025-05-193-1/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Synapse previously did not correctly cap the max depth of an event to the max canonical json int. This can cause ordering issues for any events that were sent locally at the time. This background update goes and correctly caps the topological ordering to the new `MAX_DEPTH`. c.f. GHSA-v56r-hwv5-mxg6 --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
| * Move index creation to background update (#18439)Erik Johnston2025-05-152-2/+10
| | | | | | | | | | | | | | | | Follow on from #18375. This prevents blocking startup on creating the index, which can take a while --------- Co-authored-by: Devon Hudson <devon.dmytro@gmail.com>
* | Add a unit test for the phone home stats (#18463)Andrew Morgan2025-05-201-4/+29
| |
* | Bump ruff from 0.7.3 to 0.11.10 (#18451)dependabot[bot]2025-05-2040-142/+121
| | | | | | | | | | | | Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andrew Morgan <andrew@amorgan.xyz> Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* | Allow only requiring a field be present in an SSO response, rather than โ†ตAndrew Morgan2025-05-191-6/+1
| | | | | | | | specifying a required value (#18454)
* | Fix admin redaction endpoint not redacting encrypted messages (#18434)Shay2025-05-191-1/+1
| |
* | remove room without listeners from Notifier.room_to_user_streams (#18380)Stanislav Kazantsev2025-05-151-0/+3
| | | | | | | | Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
* | Add option to allow registrations that begin with '_' (#18262)_2025-05-152-1/+8
| | | | | | | | Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* | Fix a couple type annotations in the `RootConfig`/`Config` (#18409)Eric Eastwood2025-05-135-11/+13
|/ | | | | | | | | Fix a couple type annotations in the `RootConfig`/`Config`. Discovered while cribbing this code for another project. It's really sucks that `mypy` type checking doesn't catch this. I assume this is because we also have a `synapse/config/_base.pyi` that overrides all of this. Still unclear to me why the `Iterable[str]` vs `StrSequence` issue wasn't caught as that's what `ConfigError` expects.
* Pass leave from remote invite rejection down Sliding Sync (#18375)Devon Hudson2025-05-084-1/+289
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #17753 ### Dev notes The `sliding_sync_membership_snapshots` and `sliding_sync_joined_rooms` database tables were added in https://github.com/element-hq/synapse/pull/17512 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Erik Johnston <erik@matrix.org> Co-authored-by: Olivier 'reivilibre <oliverw@matrix.org> Co-authored-by: Eric Eastwood <erice@element.io>
* Convert Sliding Sync tests to use higher-level `compute_interested_rooms` โ†ตDevon Hudson2025-05-075-41/+251
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#18399) Spawning from https://github.com/element-hq/synapse/pull/18375#discussion_r2071768635, This updates some sliding sync tests to use a higher level function in order to move test coverage to cover both fallback & new tables. Important when https://github.com/element-hq/synapse/pull/18375 is merged. In other words, adjust tests to target `compute_interested_room(...)` (relevant to both new and fallback path) instead of the lower level `get_room_membership_for_user_at_to_token(...)` that only applies to the fallback path. ### Dev notes ``` SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.handlers.test_sliding_sync.ComputeInterestedRoomsTestCase_new ``` ``` SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.rest.client.sliding_sync ``` ``` SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.handlers.test_sliding_sync.ComputeInterestedRoomsTestCase_new.test_display_name_changes_leave_after_token_range ``` ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Merge branch 'master' into developAndrew Morgan2025-05-066-93/+57
|\
| * Unschedule the background update scheduled in #18068. (#18372)Quentin Gliech2025-04-303-92/+18
| | | | | | Fixes #18356
| * Remove the trigger added in #18260 and then reverted (#18373)Quentin Gliech2025-04-303-1/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See #18260 This is useful for anyone who tried Synapse v1.129.0rc1 out Fixes #18349 To test: - checkout v1.129.0rc1 and start - check that the events table has the trigger (`\dS events` with postgres) - checkout this PR and start - check that the events table doesn't have the trigger anymore
* | Ensure the url previewer also hashes and quarantines media (#18297)Will Hunt2025-05-062-4/+14
| | | | | | | | Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* | Return specific error code when email / phone not supported (#17578)David Baker2025-05-053-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implements https://github.com/matrix-org/matrix-spec-proposals/pull/4178 If this would need tests, could you give some idea of what tests would be needed and how best to add them? ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [ ] Pull request is based on the develop branch * [ ] 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. * [ ] [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))
* | Add the ability to exclude remote users in user directory search results โ†ตWill Lewis2025-05-023-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#18300) This change adds a new configuration `user_directory.exclude_remote_users`, which defaults to False. When set to True, remote users will not appear in user directory search results. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* | Allow a few admin APIs used by MAS to run on workers (#18313)Quentin Gliech2025-05-028-200/+239
| | | | | | | | | | | | | | | | | | | | | | | | This should be reviewed commit by commit. It adds a few admin servlets that are used by MAS when in delegation mode to workers --------- Co-authored-by: Olivier 'reivilibre <oliverw@matrix.org> Co-authored-by: Devon Hudson <devon.dmytro@gmail.com> Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* | Apply `should_drop_federated_event` to federation invites (#18330)Shay2025-05-021-0/+6
| | | | | | Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* | Fix lint which broke in #18374 (#18385)Quentin Gliech2025-05-021-1/+1
| | | | | | | | https://github.com/element-hq/synapse/pull/18374 did not pass linting but was merged
* | Don't check the `at_hash` (access token hash) in OIDC ID Tokens if we don't โ†ตAndrew Morgan2025-05-021-2/+27
| | | | | | | | | | | | use the access token (#18374) Co-authored-by: Eric Eastwood <erice@element.io>
* | Do not auto-provision missing users & devices when delegating auth to MAS โ†ตQuentin Gliech2025-05-021-28/+11
| | | | | | | | | | | | | | | | | | | | (#18181) Since MAS 0.13.0, the provisionning of devices and users is done synchronously and reliably enough that we don't need to auto-provision on the Synapse side anymore. It's important to remove this behaviour if we want to start caching token introspection results.
* | Add an Admin API endpoint to fetch scheduled tasks (#18214)Shay2025-05-012-0/+72
| |
* | Minor performance improvements to notifier/replication (#18367)Erik Johnston2025-04-291-30/+31
| | | | | | | | | | | | These are some improvements to `on_new_event` which is a hot path. Not sure how much this will save, but maybe like ~5%? Possibly easier to review commit-by-commit
* | Slight performance increase when using the ratelimiter (#18369)Erik Johnston2025-04-292-15/+11
| | | | | | See the commits.
* | Do not retry push during backoff period (#18363)Erik Johnston2025-04-291-0/+6
| | | | | | | | | | This fixes a bug where if a pusher gets told about a new event to push it will ignore the backoff and immediately retry sending any pending push.
* | Allow /rooms/ admin API to be on workers (#18360)Erik Johnston2025-04-252-3/+5
| | | | | | Tested by https://github.com/matrix-org/sytest/pull/1400
* | Move GET /devices/ off main process (#18355)Erik Johnston2025-04-251-2/+18
|/ | | | | | | | We can't move PUT/DELETE as they do need to happen on main process (due to notification of device changes). --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Revert "Add total event, unencrypted message, and e2ee event counts to stats โ†ตDevon Hudson2025-04-166-405/+7
| | | | | | | | | | | reporting" (#18346) Reverts element-hq/synapse#18260 It is causing a failure when building release debs for `debian:bullseye` with the following error: ``` sqlite3.OperationalError: near "RETURNING": syntax error ```
* Fix query for room participation (#18345)Erik Johnston2025-04-161-12/+8
| | | | | | | | | | | Follow on from #18068 Currently the subquery in `UPDATE` is pointless, as it will still just update all `room_membership` rows. Instead, we should look at the current membership event ID (which is easily retrieved from `local_current_membership`). We also add a `AND NOT participant` to noop the `UPDATE` when the `participant` flag is already set. cc @H-Shay
* Fix ExternalIDReuse exception for concurrent transactions (#18342)Quentin Gliech2025-04-161-6/+23
|
* Don't cache introspection failures (#18339)Quentin Gliech2025-04-151-3/+9
|
* Fix `force_tracing_for_users` config when using MAS (#18334)Erik Johnston2025-04-151-0/+51
| | | | | | | This is a copy of what we do for internal auth, and we should figure out a way to deduplicate some of this stuff: https://github.com/element-hq/synapse/blob/dd05cc55eedbf086ae224a13c9ae9f0332d96b1f/synapse/api/auth/internal.py#L62-L110
* Fix the token introspection cache logging access tokens when MAS integration โ†ตreivilibre2025-04-152-10/+25
| | | | | | | | | | | is in use. (#18335) The `ResponseCache` logs keys by default. Let's not do that for access tokens. --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Add total event, unencrypted message, and e2ee event counts to stats โ†ตAndrew Morgan2025-04-156-7/+405
| | | | | | reporting (#18260) Co-authored-by: Eric Eastwood <erice@element.io>
* Add caches to new hot path functions (#18337)Erik Johnston2025-04-143-15/+22
| | | | We call these two functions for every authed request when using delegated auth.
* Add passthrough_authorization_parameters support to OIDC configuration (#18232)Olivier D2025-04-102-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # Add passthrough_authorization_parameters support to OIDC configuration This PR adds `the passthrough_authorization_parameters` option to OIDC configuration, allowing specific query parameters (like `login_hint`) to be passed from the redirect endpoint to the authorization grant URL. This enables clients to provide additional context to identity providers during authentication flows. # Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Quentin Gliech <quenting@element.io>
* Disable Postgres statement timeouts while purging room state (#18133)Jason Little2025-04-021-0/+7
|
* Make sure media hashes are not queried until the index is up (#18302)Quentin Gliech2025-04-012-3/+19
|
* Add an access token introspection cache to make Matrix Authentication โ†ตreivilibre2025-04-011-17/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Service integration (MSC3861) more efficient. (#18231) Evolution of https://github.com/element-hq/synapse/commit/cd78f3d2ee15ccf3e8229a1f529e0e2c16e15c45 This cache does not have any explicit invalidation, but this is deemed acceptable (see code comment). We may still prefer to add it eventually, letting us bump up the Time-To-Live (TTL) on the cache as we currently set a 2 minute expiry to balance the fact that we have no explicit invalidation. This cache makes several things more efficient: - reduces number of outbound requests from Synapse, reducing CPU utilisation + network I/O - reduces request handling time in Synapse, which improves client-visible latency - reduces load on MAS and its database --- Other than that, this PR also introduces support for `expires_in` (seconds) on the introspection response. This lets the cached responses expire at the proper expiry time of the access token, whilst avoiding clock skew issues. Corresponds to: https://github.com/element-hq/matrix-authentication-service/pull/4241 --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Store hashes of media files, and allow quarantining by hash. (#18277)Will Hunt2025-03-276-45/+377
| | | | | | | | | | | | | | | | This PR makes a few radical changes to media. This now stores the SHA256 hash of each file stored in the database (excluding thumbnails, more on that later). If a set of media is quarantined, any additional uploads of the same file contents or any other files with the same hash will be quarantined at the same time. Currently this does NOT: - De-duplicate media, although a future extension could be to do that. - Run any background jobs to identify the hashes of older files. This could also be a future extension, though the value of doing so is limited to combat the abuse of recent media. - Hash thumbnails. It's assumed that thumbnails are parented to some form of media, so you'd likely be wanting to quarantine the media and the thumbnail at the same time.
* Add DB delta to remove the old state group deletion job (#18284)Devon Hudson2025-03-271-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This background DB delta removes the old state group deletion background update from the `background_updates` table if it exists. The `delete_unreferenced_state_groups_bg_update` update should only exist in that table if a homeserver ran v1.126.0rc1/v1.126.0rc2, and rolled back or forward to any other version of Synapse before letting the update finish. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Merge branch 'master' into developAndrew Morgan2025-03-267-27/+63
|\
| * Fix GHSA-v56r-hwv5-mxg6 โ€” Federation denialErik Johnston2025-03-267-27/+63
| | | | | | | | | | | | Fixes https://github.com/element-hq/synapse/security/advisories/GHSA-v56r-hwv5-mxg6 Federation denial of service via malformed events.
* | Delete unreferenced state groups in background (#18254)Devon Hudson2025-03-217-12/+338
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR fixes #18154 to avoid de-deltaing state groups which resulted in DB size temporarily increasing until the DB was `VACUUM`'ed. As a result, less state groups will get deleted now. It also attempts to improve performance by not duplicating work when processing state groups it has already processed in previous iterations. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Erik Johnston <erikj@element.io>
* | Add index to sliding sync membership snapshot table, to fix a performance โ†ตreivilibre2025-03-182-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | issue. (#18074) To address a performance problem due to the foreign key on the same column. cc @erikjohnston --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* | Add a column `participant` to `room_memberships` table (#18068)Shay2025-03-185-1/+179
|/
* Remove `SYNAPSE_USE_FROZEN_DICTS` environment variable (#18123)Eric Eastwood2025-03-181-10/+9
| | | | | | | | | | I got rid of the `SYNAPSE_USE_FROZEN_DICTS` environment variable because it will be overridden by the Synapse worker apps anyway and if we want to support `SYNAPSE_USE_FROZEN_DICTS`, it should be in `synapse/config/server.py`. It's also not documented so I'm assuming no one is using it anyway. Spawning from looking at the frozen dict stuff during the review of https://github.com/element-hq/synapse/pull/18103#discussion_r1935876168
* MSC4140: don't cancel delayed state on own state (#17810)Andrew Ferrazzutti2025-03-172-10/+40
| | | | | | | When a user sends a state event, do not cancel their own delayed events for the same piece of state. For context, see [the relevant section in the MSC](https://github.com/matrix-org/matrix-spec-proposals/blob/a09a883d9a013ac4b6ffddebd7ea87a827d211b9/proposals/4140-delayed-events-futures.md#delayed-state-events-are-cancelled-by-a-more-recent-state-event).
* Add caching support to media endpoints (#18235)Erik Johnston2025-03-133-7/+103
| | | | | | | | | | | | | | | | | We do a few things in this PR to better support caching: 1. Change `Cache-Control` header to allow intermediary proxies to cache media *only* if they revalidate on every request. This means that the intermediary cache will still send the request to Synapse but with a `If-None-Match` header, at which point Synapse can check auth and respond with a 304 and empty content. 2. Add `ETag` response header to all media responses. We hardcode this to `1` since all media is immutable (beyond being deleted). 3. Check for `If-None-Match` header (after checking for auth), and if it matches then respond with a 304 and empty body. --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Revert the background job to clear unreferenced state groups (that was โ†ตreivilibre2025-03-077-276/+73
| | | | | | | | | | | | | | | | | introduced in v1.126.0rc1), due to a suspected issue that causes increased disk usage. (#18222) Revert "Add background job to clear unreferenced state groups (#18154)" This mechanism is suspected of inserting large numbers of rows into `state_groups_state`, thus unreasonably increasing disk usage. See: https://github.com/element-hq/synapse/issues/18217 This reverts commit 5121f9210c989fcc909e78195133876dff3bc9b9 (#18154). --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
* Support getting the device ID explicitly from MAS (#18174)Quentin Gliech2025-03-041-17/+32
| | | | | | | | | | | | | | | | | | | | | | | The context for this is that the Matrix spec allows basically anything in the device ID. With MSC3861, we're restricting this to strings that can be represented as scopes. Whilst this works well for next-gen auth sessions, compatibility/legacy sessions still can have characters that can't be encoded (mainly spaces) in them. To work around that, we added in MAS a behaviour where the device_id is given as an explicit property of the token introspection response, and remove it from the scope. Because we don't expect users to rollout new Synapse and MAS versions in sync, we needed a way to 'advertise' support for this behaviour: the easiest way to do that was through an extra header in the introspection response. On the longer term, I expect MAS and Synapse to move away from the introspection endpoint, and instead define a specific API for Synapse -> MAS communication. PR on the MAS side: https://github.com/element-hq/matrix-authentication-service/pull/4067
* Add `redirect_uri` option to `oidc_providers` entries (#18197)Andrew Morgan2025-03-032-1/+22
| | | | | | | | | | | | | | | | | | | | | Allows overriding the `redirect_uri` parameter sent to both the authorization and token endpoints of the IdP. Typically this parameter is hardcoded to `<public_baseurl>/_synapse/client/oidc/callback`. Yet it can be useful in certain contexts to allow a different callback URL. For instance, if you would like to intercept the authorization code returned from the IdP and do something with it, before eventually calling Synapse's OIDC callback URL yourself. This change enables enterprise use cases but does not change the default behaviour. --- Best reviewed commit-by-commit. --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Add worker_replication_secret_path config option (#18191)V024602025-02-261-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Workers now get their secrets from files, too! There are not many config options left to pathify :) Includes documentation and unit tests. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Devon Hudson <devon.dmytro@gmail.com>
* Add form_secret_path config option (#18090)V024602025-02-251-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I [was told](https://github.com/element-hq/synapse/pull/17983#issuecomment-2593370897) about another config option with a secret, so I got `form_secret` a companion: `form_secret_path` This PR makes NixOS and Kubernetes users a little bit happy. Includes docs and tests. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Define delayed event ratelimit category (#18019)Andrew Ferrazzutti2025-02-252-4/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Apply ratelimiting on delayed event management separately from messages. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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. * [ ] [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)) --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Add --no-secrets-in-config command line option (#18092)V024602025-02-259-13/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds the `--no-secrets-in-config` command line option that makes Synapse reject all configurations containing keys with in-line secret values. Currently this rejects - `turn_shared_secret` - `registration_shared_secret` - `macaroon_secret_key` - `recaptcha_private_key` - `recaptcha_public_key` - `experimental_features.msc3861.client_secret` - `experimental_features.msc3861.jwk` - `experimental_features.msc3861.admin_token` - `form_secret` - `redis.password` - `worker_replication_secret` > [!TIP] > Hey, you! Yes, you! ๐Ÿ˜Š If you think this list is missing an item, please leave a comment below. Thanks :) This PR complements my other PRs[^1] that add the corresponding `_path` variants for this class of config options. It enables admins to enforce a policy of no secrets in configuration files and guards against accident and malice. Because I consider the flag `--no-secrets-in-config` to be security-relevant, I did not add a corresponding `--secrets-in-config` flag; this way, if Synapse command line options are appended at various places, there is no way to weaken the once-set setting with a succeeding flag. [^1]: [#17690](https://github.com/element-hq/synapse/pull/17690), [#17717](https://github.com/element-hq/synapse/pull/17717), [#17983](https://github.com/element-hq/synapse/pull/17983), [#17984](https://github.com/element-hq/synapse/pull/17984), [#18004](https://github.com/element-hq/synapse/pull/18004), [#18090](https://github.com/element-hq/synapse/pull/18090) ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Add background job to clear unreferenced state groups (#18154)Devon Hudson2025-02-257-73/+276
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #18150 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Erik Johnston <erikj@element.io>
* Disable room list publication by default (#18175)Erik Johnston2025-02-241-3/+1
| | | | | | This is in line with our general policy of ensuring that the default config is reasonably locked down. SyTest PR to fix tests: https://github.com/matrix-org/sytest/pull/1396
* Prevent suspended users from sending encrypted messages (#18157)Shay2025-02-211-5/+27
| | | Missed in the first round.
* Add support for overriding `id_token_signing_alg_values_supported` for an โ†ตEric Eastwood2025-02-202-0/+40
| | | | | | | | | | | | | OpenID identity provider (#18177) Normally, when `discovery` is enabled, `id_token_signing_alg_values_supported` comes from the OpenID Discovery Document (`/.well-known/openid-configuration`). If nothing was specified, we default to supporting `RS256` in the downstream usage. This PR just adds support for adding a default/overriding the the discovered value [just like we do for other things like the `token_endpoint`](https://github.com/element-hq/synapse/blob/1525a3b4d48a0f5657d61423e1f205bff9a77948/docs/usage/configuration/config_documentation.md#oidc_providers), etc.
* Make sure we advertise registration as disabled when MSC3861 is enabled (#17661)Quentin Gliech2025-02-181-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | This has been a problem with Element Web, as it will proble /register with an empty body, which gave this error: ``` curl -d '{}' -HContent-Type:application/json /_matrix/client/v3/register {"errcode": "M_UNKNOWN", "error": "Invalid username"} ``` And Element Web would choke on it. This changes that so we reply instead: ``` {"errcode": "M_FORBIDDEN", "error": "Registration has been disabled. Only m.login.application_service registrations are allowed."} ``` Also adds a test for this. See https://github.com/element-hq/element-web/issues/27993 --------- Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
* Cleanup deleted state group references (#18165)Devon Hudson2025-02-181-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Add method to get current server time in milliseconds in ModuleApi (#18144)qashlan2025-02-181-0/+4
| | | | | | | | | | - Add `get_current_time_msec()` method to the [module API](https://matrix-org.github.io/synapse/latest/modules/writing_a_module.html) for sound time comparisons with Synapse. - Fixes #18104 Signed-off-by: Ahmed Qashlan <ahmedelqashlan@gmail.com> Co-authored-by: Eric Eastwood <madlittlemods@gmail.com> Co-authored-by: Erik Johnston <erikj@jki.re>
* Add support to proxy outbound requests from Synapse in tests (#18158)Eric Eastwood2025-02-171-0/+6
| | | | | | | | | | | | | | | | | | | | Adds new environment variables that can be used with the Docker image (`SYNAPSE_HTTP_PROXY`/`SYNAPSE_HTTPS_PROXY`/`SYNAPSE_NO_PROXY`) Useful for things like the [Secure Border Gateway](https://element.io/server-suite/secure-border-gateways) ### Why is this necessary? You can already configure the `HTTP_PROXY`/`HTTPS_PROXY` environment variables to proxy outbound requests but setting this globally in the Docker image affects all processes which isn't always desirable or workable in the case where the proxy is running in the Docker image itself (because the Debian packages will fail to download because the proxy isn't up and running yet) . Adding Synapse specific environment variables (`SYNAPSE_HTTP_PROXY`/`SYNAPSE_HTTPS_PROXY`/`SYNAPSE_NO_PROXY`) makes things much more targetable.
* Limit size of user directory search queries (#18172)Erik Johnston2025-02-171-1/+7
| | | | | | | | If a user search has many words we can end up creating really large queries that take a long time for the database to process. Generally, such searches don't return any results anyway (due to limits on user ID and display name length). We "fix" this by cheating and only searching for the first ten words.
* Add log message when worker lock timeouts get large (#18124)Devon Hudson2025-02-121-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to help track down a possible, but very rare, worker deadlock that was seen on matrix.org. In theory, you could work back from an instance of these new logs to the approximate time when the lock was obtained and focus the diagnostic efforts there. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Fix internal server error when updating 3pid address with invalid email (#18125)qashlan2025-02-121-2/+8
| | | | | | | | When updating 3pid for a user email from admin api and sending invalid email the server throws 500 internal server error. changed to 400 Bad request and returned the error message Signed-off-by: qashlan <ahmedelqashlan@gmail.com> Signed-off-by: Ahmed Qashlan <ahmedelqashlan@gmail.com>
* Cleanup Python 3.8 leftovers (#17967)V024602025-02-1043-76/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some small cleanups after Python3.8 became EOL. - Move some type imports from `typing_extensions` to `typing` - Remove the `abi3-py38` feature from pyo3 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Quentin Gliech <quenting@element.io>
* Overload "allow_none" on DB pool static method (#17616)Andrew Ferrazzutti2025-02-104-33/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Quentin Gliech <quenting@element.io>
* feat: Allow multiple values for SSO attribute_requirements via comma โ†ตmeise2025-02-102-6/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | separation (#17949) In the current `attribute_requirements` implementation it is only possible to allow exact matching attribute values. Multiple allowed values for one attribute are not possible as described in #13238. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Sebastian Neuser <pzkz@infra.run> Co-authored-by: Quentin Gliech <quenting@element.io>
* Don't log exceptions for obviously incorrect stream tokens (#18139)Erik Johnston2025-02-101-0/+5
| | | | | | | | We log incorrect ones as we want to catch bugs where Synapse returns bad tokens. However, sometimes clients just send tokens that are e.g. empty. --------- Co-authored-by: Eric Eastwood <erice@element.io>
* Merge branch 'release-v1.124' into developErik Johnston2025-02-072-15/+43
|\
| * Fix performance of `check_state_groups_and_bump_deletion` (#18141)Erik Johnston2025-02-072-15/+43
| | | | | | | | | | | | | | | | | | | | Regressed as part of https://github.com/element-hq/synapse/pull/18107 This does two things: 1. Only check if the state groups have been deleted when calculating the event context (as that's when we will insert them). This avoids lots of checks for read operations. 2. Don't lock the `state_groups` rows when doing the check. This adds overhead, and it doesn't prevent any races.
* | Merge branch 'release-v1.124' into developErik Johnston2025-02-051-2/+12
|\|
| * Fix bug where persisting some events fails after unclean shutdown. (#18137)Erik Johnston2025-02-051-2/+12
| | | | | | | | | | | | Introduced in #18107 `UniqueViolation: duplicate key value violates unique constraint "state_groups_persisting_pkey"`
* | Fix legacy modules `check_username_for_spam` (#18135)Erik Johnston2025-02-051-0/+2
| | | | | | | | | | Broke in #17916, as the signature inspection incorrectly looks at the wrapper function. We fix this by setting the signature on the wrapper function to that of the wrapped function via `@functools.wraps`.
* | Add MSC3861 config options admin_token_path and client_secret_path (#18004)V024602025-02-042-13/+104
|/ | | | | | | | | | | | | | Another PR on my quest to a `*_path` variant for every secret. Adds two config options `admin_token_path` and `client_secret_path` to the experimental config under `experimental_features.msc3861`. Also includes tests. I tried to be a good citizen here by following `attrs` conventions and not rewriting the corresponding non-path variants in the class, but instead adding methods to retrieve the value. Reading secrets from files has the security advantage of separating the secrets from the config. It also simplifies secrets management in Kubernetes. Also useful to NixOS users.
* Fix bug where purging history could lead to increase in disk space usage โ†ตErik Johnston2025-02-032-1/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | (#18131) When purging history, we try and delete any state groups that become unreferenced (i.e. there are no longer any events that directly reference them). When we delete a state group that is referenced by another state group, we "de-delta" that state group so that it no longer refers to the state group that is deleted. There are two bugs with this approach that we fix here: 1. There is a common pattern where we end up storing two state groups when persisting a state event: the state before and after the new state event, where the latter is stored as a delta to the former. When deleting state groups we only deleted the "new" state and left (and potentially de-deltaed) the old state. This was due to a bug/typo when trying to find referenced state groups. 2. There are times where we store unreferenced state groups in the DB, during the purging of history these would not get rechecked and instead always de-deltaed. Instead, we should check for this case and delete any unreferenced state groups rather than de-deltaing them. The effect of the above bugs is that when purging history we'd end up with lots of unreferenced state groups that had been de-deltaed (i.e. stored as the full state). This can lead to dramatic increases in storage space used.
* Add locking to more safely delete state groups: Part 2 (#18130)Erik Johnston2025-02-033-11/+162
| | | | | | This actually makes it so that deleting state groups goes via the new mechanism. c.f. #18107
* Add locking to more safely delete state groups: Part 1 (#18107)Erik Johnston2025-02-038-39/+611
| | | | | | | | | | | | | | | | Currently we don't really have anything that stops us from deleting state groups when an in-flight event references it. This is a fairly rare race currently, but we want to be able to more aggressively delete state groups so it is important to address this to ensure that the database remains valid. This implements the locking, but doesn't actually use it. See the class docstring of the new data store for an explanation for how this works. --------- Co-authored-by: Devon Hudson <devon.dmytro@gmail.com>
* Allow (un)block_room storage functions to be called on workers (#18119)Andrew Morgan2025-01-301-44/+44
| | | | | | | | | | | | This is so workers can call these functions. This was preventing the [Delete Room Admin API](https://element-hq.github.io/synapse/latest/admin_api/rooms.html#version-2-new-version) from succeeding when `block: true` was specified. This was because we had `run_background_tasks_on` configured to run on a separate worker. As workers weren't able to call the `block_room` storage function before this PR, the (delete room) task failed when taken off the queue by the worker.
* Raise an error if someone is using an incorrect suffix in a config duration โ†ตEric Eastwood2025-01-291-2/+17
| | | | | | | string (#18112) Previously, a value like `5q` would be interpreted as 5 milliseconds. We should just raise an error instead of letting someone run with a misconfiguration.
* Never autojoin deactivated & suspended users. (#18073)Will Hunt2025-01-281-34/+51
| | | | | | | | | This PR changes the logic so that deactivated users are always ignored. Suspended users were already effectively ignored as Synapse forbids a join while suspended. --------- Co-authored-by: Devon Hudson <devon.dmytro@gmail.com>
* OIDC: increase length of generated `nonce` parameter from 30->32 chars (#18109)Andrew Morgan2025-01-271-1/+15
|
* Fix join being denied after being invited over federation (#18075)Eric Eastwood2025-01-275-7/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This also happens for rejecting an invite. Basically, any out-of-band membership transition where we first get the membership as an `outlier` and then rely on federation filling us in to de-outlier it. This PR mainly addresses automated test flakiness, bots/scripts, and options within Synapse like [`auto_accept_invites`](https://element-hq.github.io/synapse/v1.122/usage/configuration/config_documentation.html#auto_accept_invites) that are able to react quickly (before federation is able to push us events), but also helps in generic scenarios where federation is lagging. I initially thought this might be a Synapse consistency issue (see issues labeled with [`Z-Read-After-Write`](https://github.com/matrix-org/synapse/labels/Z-Read-After-Write)) but it seems to be an event auth logic problem. Workers probably do increase the number of possible race condition scenarios that make this visible though (replication and cache invalidation lag). Fix https://github.com/element-hq/synapse/issues/15012 (probably fixes https://github.com/matrix-org/synapse/issues/15012 (https://github.com/element-hq/synapse/issues/15012)) Related to https://github.com/matrix-org/matrix-spec/issues/2062 Problems: 1. We don't consider [out-of-band membership](https://github.com/element-hq/synapse/blob/develop/docs/development/room-dag-concepts.md#out-of-band-membership-events) (outliers) in our `event_auth` logic even though we expose them in `/sync`. 1. (This PR doesn't address this point) Perhaps we should consider authing events in the persistence queue as events already in the queue could allow subsequent events to be allowed (events come through many channels: federation transaction, remote invite, remote join, local send). But this doesn't save us in the case where the event is more delayed over federation. ### What happened before? I wrote some Complement test that stresses this exact scenario and reproduces the problem: https://github.com/matrix-org/complement/pull/757 ``` COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh -run TestSynapseConsistency ``` We have `hs1` and `hs2` running in monolith mode (no workers): 1. `@charlie1:hs2` is invited and joins the room: 1. `hs1` invites `@charlie1:hs2` to a room which we receive on `hs2` as `PUT /_matrix/federation/v1/invite/{roomId}/{eventId}` (`on_invite_request(...)`) and the invite membership is persisted as an outlier. The `room_memberships` and `local_current_membership` database tables are also updated which means they are visible down `/sync` at this point. 1. `@charlie1:hs2` decides to join because it saw the invite down `/sync`. Because `hs2` is not yet in the room, this happens as a remote join `make_join`/`send_join` which comes back with all of the auth events needed to auth successfully and now `@charlie1:hs2` is successfully joined to the room. 1. `@charlie2:hs2` is invited and and tries to join the room: 1. `hs1` invites `@charlie2:hs2` to the room which we receive on `hs2` as `PUT /_matrix/federation/v1/invite/{roomId}/{eventId}` (`on_invite_request(...)`) and the invite membership is persisted as an outlier. The `room_memberships` and `local_current_membership` database tables are also updated which means they are visible down `/sync` at this point. 1. Because `hs2` is already participating in the room, we also see the invite come over federation in a transaction and we start processing it (not done yet, see below) 1. `@charlie2:hs2` decides to join because it saw the invite down `/sync`. Because `hs2`, is already in the room, this happens as a local join but we deny the event because our `event_auth` logic thinks that we have no membership in the room :x: (expected to be able to join because we saw the invite down `/sync`) 1. We finally finish processing the `@charlie2:hs2` invite event from and de-outlier it. - If this finished before we tried to join we would have been fine but this is the race condition that makes this situation visible. Logs for `hs2`: ``` ๐Ÿ—ณ๏ธ on_invite_request: handling event <FrozenEventV3 event_id=$PRPCvdXdcqyjdUKP_NxGF2CcukmwOaoK0ZR1WiVOZVk, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=invite, outlier=False> ๐Ÿ”ฆ _store_room_members_txn update room_memberships: <FrozenEventV3 event_id=$PRPCvdXdcqyjdUKP_NxGF2CcukmwOaoK0ZR1WiVOZVk, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=invite, outlier=True> ๐Ÿ”ฆ _store_room_members_txn update local_current_membership: <FrozenEventV3 event_id=$PRPCvdXdcqyjdUKP_NxGF2CcukmwOaoK0ZR1WiVOZVk, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=invite, outlier=True> ๐Ÿ“จ Notifying about new event <FrozenEventV3 event_id=$PRPCvdXdcqyjdUKP_NxGF2CcukmwOaoK0ZR1WiVOZVk, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=invite, outlier=True> โœ… on_invite_request: handled event <FrozenEventV3 event_id=$PRPCvdXdcqyjdUKP_NxGF2CcukmwOaoK0ZR1WiVOZVk, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=invite, outlier=True> ๐Ÿงฒ do_invite_join for @user-2-charlie1:hs2 in !sfZVBdLUezpPWetrol:hs1 ๐Ÿ”ฆ _store_room_members_txn update room_memberships: <FrozenEventV3 event_id=$bwv8LxFnqfpsw_rhR7OrTjtz09gaJ23MqstKOcs7ygA, type=m.room.member, state_key=@user-1-alice:hs1, membership=join, outlier=True> ๐Ÿ”ฆ _store_room_members_txn update room_memberships: <FrozenEventV3 event_id=$oju1ts3G3pz5O62IesrxX5is4LxAwU3WPr4xvid5ijI, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=join, outlier=False> ๐Ÿ“จ Notifying about new event <FrozenEventV3 event_id=$oju1ts3G3pz5O62IesrxX5is4LxAwU3WPr4xvid5ijI, type=m.room.member, state_key=@user-2-charlie1:hs2, membership=join, outlier=False> ... ๐Ÿ—ณ๏ธ on_invite_request: handling event <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=False> ๐Ÿ”ฆ _store_room_members_txn update room_memberships: <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=True> ๐Ÿ”ฆ _store_room_members_txn update local_current_membership: <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=True> ๐Ÿ“จ Notifying about new event <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=True> โœ… on_invite_request: handled event <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=True> ๐Ÿ“ฌ handling received PDU in room !sfZVBdLUezpPWetrol:hs1: <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=False> ๐Ÿ“ฎ handle_new_client_event: handling <FrozenEventV3 event_id=$WNVDTQrxy5tCdPQHMyHyIn7tE4NWqKsZ8Bn8R4WbBSA, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=join, outlier=False> โŒ Denying new event <FrozenEventV3 event_id=$WNVDTQrxy5tCdPQHMyHyIn7tE4NWqKsZ8Bn8R4WbBSA, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=join, outlier=False> because 403: You are not invited to this room. synapse.http.server - 130 - INFO - POST-16 - <SynapseRequest at 0x7f460c91fbf0 method='POST' uri='/_matrix/client/v3/join/%21sfZVBdLUezpPWetrol:hs1?server_name=hs1' clientproto='HTTP/1.0' site='8080'> SynapseError: 403 - You are not invited to this room. ๐Ÿ“จ Notifying about new event <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=False> โœ… handled received PDU in room !sfZVBdLUezpPWetrol:hs1: <FrozenEventV3 event_id=$O_54j7O--6xMsegY5EVZ9SA-mI4_iHJOIoRwYyeWIPY, type=m.room.member, state_key=@user-3-charlie2:hs2, membership=invite, outlier=False> ```
* Ratelimit presence updates (#18000)Sven Mรคder2025-01-244-6/+49
|
* Support the new `/auth_metadata` endpoint defined in MSC2965. (#18093)Quentin Gliech2025-01-213-3/+46
| | | | | | | See the updated MSC2965 --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Implement MSC4133 to support custom profile fields. (#17488)Patrick Cloke2025-01-219-25/+671
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implementation of [MSC4133](https://github.com/matrix-org/matrix-spec-proposals/pull/4133) to support custom profile fields. It is behind an experimental flag and includes tests. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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)) --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Drop indices concurrently on background updates (#18091)Erik Johnston2025-01-201-2/+2
| | | | | | | | | | Otherwise these can race with other long running queries and lock out all other queries. This caused problems in v1.22.0 as we added an index to `events` table in #17948, but that got interrupted and so next time we ran the background update we needed to delete the half-finished index. However, that got blocked behind some long running queries and then locked other queries out (stopping workers from even starting).
* Bust `_membership_stream_cache` cache when current state changes (#17732)Eric Eastwood2025-01-084-2/+62
| | | | | | | | | | | | | | | | | | | | | | | This is particularly a problem in a state reset scenario where the membership might change without a corresponding event. This PR is targeting a scenario where a state reset happens which causes room membership to change. Previously, the cache would just hold onto stale data and now we properly bust the cache in this scenario. We have a few tests for these scenarios which you can see are now fixed because we can remove the `FIXME` where we were previously manually busting the cache in the test itself. This is a general Synapse thing so by it's nature it helps out Sliding Sync. Fix https://github.com/element-hq/synapse/issues/17368 Prerequisite for https://github.com/element-hq/synapse/issues/17929 --- Match when are busting `_curr_state_delta_stream_cache`
* Add the ability to filter by state event type on admin room state endpoint โ†ตShay2025-01-081-1/+13
| | | | | | | | | | (#18035) Adds a query param `type` to `/_synapse/admin/v1/rooms/{room_id}/state` that filters the state event query by state event type. --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* Drop unstable MSC4151 implementation (#18052)Travis Ralston2025-01-073-17/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's been rotated out of known clients, and should be safe for removal now. Fixes https://github.com/element-hq/synapse/issues/17373 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [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))
* Properly purge state groups tables when purging a room (#18024)Mathieu Velten2025-01-063-68/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently purging a complex room can lead to a lot of orphaned rows left behind in the state groups tables. It seems it is because we are loosing track of state groups sometimes. This change uses the `room_id` indexed column of `state_groups` table to decide what to delete instead of doing an indirection through `event_to_state_groups`. Related to https://github.com/element-hq/synapse/issues/3364. ### 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). * [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)) --------- Co-authored-by: Erik Johnston <erikj@jki.re>
* Refactor get_profile: do not return missing fields. (#18063)Patrick Cloke2025-01-036-28/+43
| | | | | | | | | | Refactor `get_profile` to avoid returning "empty" (`None` / `null`) fields. Currently this is not very important, but will be more useful once #17488 lands. It does update the servlet to use this now which has a minor change in behavior: additional fields served over federation will now be properly sent back to clients. It also adds constants for `avatar_url` / `displayname` although I did not attempt to use it everywhere possible.
* Make admin api redactions use the requester to send the redaction (#18029)morguldir2024-12-231-1/+1
|
* Stop using twisted.internet.defer.returnValue (#18020)Colin Watson2024-12-202-20/+3
| | | | | | | | | `defer.returnValue` was only needed in Python 2; in Python 3, a simple `return` is fine. `twisted.internet.defer.returnValue` is deprecated as of Twisted 24.7.0. Most uses of `returnValue` in synapse were removed a while back; this cleans up some remaining bits.
* Remove support for PostgreSQL 11 and 12 (#18034)Patrick Cloke2024-12-191-2/+2
| | | | | | | This is essentially matrix-org/synapse#14392. I didn't see anything in there about updating sytest or complement. The main driver of this is so that I can use `jsonb_path_exists` in #17488. ๐Ÿ˜„
* Disable statement timeout during room purge (#18017)Mathieu Velten2024-12-191-0/+5
| | | | This is already done for `purge_history` but seems to have been forgotten for `purge_room`.
* Fix mypy errors on Twisted 24.11.0 (#17998)Andrew Morgan2024-12-183-8/+16
| | | | | | | | | Fixes various `mypy` errors associated with Twisted `24.11.0`. Hopefully addresses https://github.com/element-hq/synapse/issues/17075, though I've yet to test against `trunk`. Changes should be compatible with our currently pinned Twisted version of `24.7.0`.
* Wording improvements for the `TaskScheduler` (#17992)Andrew Morgan2024-12-181-37/+53
| | | | As I found the current docstrings a bit unclear while trying to wrap my head around this class.
* Bump mypy from 1.11.2 to 1.12.1 and fix new typechecking errors (#17999)Andrew Morgan2024-12-184-11/+11
| | | | | | | Supersedes https://github.com/element-hq/synapse/pull/17958. Awkwardly, the changes made to fix the mypy errors in 1.12.1 cause errors in 1.11.2. So you'll need to update your mypy version to 1.12.1 to eliminate typechecking errors during developing.
* Add email.tlsname config option (#17849)cynhr2024-12-172-33/+61
| | | | | | | | | | | | | | | The existing `email.smtp_host` config option is used for two distinct purposes: it is resolved into the IP address to connect to, and used to (request via SNI and) validate the server's certificate if TLS is enabled. This new option allows specifying a different name for the second purpose. This is especially helpful, if `email.smtp_host` isn't a global FQDN, but something that resolves only locally (e.g. "localhost" to connect through the loopback interface, or some other internally routed name), that one cannot get a valid certificate for. Alternatives would of course be to specify a global FQDN as `email.smtp_host`, or to disable TLS entirely, both of which might be undesirable, depending on the SMTP server configuration.
* Add `macaroon_secret_key_path` config option (#17983)V024602024-12-161-5/+16
| | | | | | Another config option on my quest to a `*_path` variant for every secret. This time itโ€™s `macaroon_secret_key_path`. Reading secrets from files has the security advantage of separating the secrets from the config. It also simplifies secrets management in Kubernetes. Also useful to NixOS users.
* Add some useful endpoints to Admin API (#17948)Shay2024-12-167-8/+169
| | | | | | | | | - Fetch the number of invites the provided user has sent after a given timestamp - Fetch the number of rooms the provided user has joined after a given timestamp, regardless if they have left/been banned from the rooms subsequently - Get report IDs of event reports where the provided user was the sender of the reported event
* forward requester id to check username for spam callbacks (#17916)Wilson2024-12-132-4/+28
|
* Fix bug when rejecting withdrew invite with a third_party_rules module (#17930)Mathieu Velten2024-12-101-5/+5
| | | | | | | | | | | | | | | | | | | When rejecting a withdrew invite through federation, an out of band event needs to be created. When doing so with a third_party_rules module installed, `get_prev_state_ids` [is called](https://github.com/element-hq/synapse/blob/e0fdb862cbbddc920a30233024eb99038ee2fb28/synapse/module_api/callbacks/third_party_event_rules_callbacks.py#L285) on the context to calculate the state to pass at `check_event_allowed` callbacks. The context for outliers is defined [here](https://github.com/element-hq/synapse/blob/e0fdb862cbbddc920a30233024eb99038ee2fb28/synapse/events/snapshot.py#L168), and `state_group_before_event` is None. This change makes the behavior of `get_prev_state_ids` and `get_current_state_ids` match the one presented in the docstring regarding null state_group.
* Promote account suspension to stable (#17964)Travis Ralston2024-12-043-8/+4
| | | MSC: https://github.com/matrix-org/matrix-spec-proposals/pull/3823
* Support for MSC4190: device management for application services (#17705)Quentin Gliech2024-12-046-25/+99
| | | | | | | | This is an implementation of MSC4190, which allows appservices to manage their user's devices without /login & /logout. --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
* MSC4076: Add disable_badge_count to pusher configuration (#17975)manuroe2024-12-032-5/+14
| | | | | This PR implements [MSC4076: Let E2EE clients calculate app badge counts themselves (disable_badge_count)](https://github.com/matrix-org/matrix-spec-proposals/pull/4076).
* Merge branch 'master' into developQuentin Gliech2024-12-038-11/+144
|\
| * Restrict which image formats we will decode in order to generate thumbnailsOlivier 'reivilibre2024-12-031-1/+6
| |
| * Don't allow unsupported content-typeDevon Hudson2024-12-031-0/+36
| | | | | | | | Co-authored-by: Eric Eastwood <erice@element.io>
| * Handle null invite and knock room stateErik Johnston2024-12-035-9/+33
| |
| * Sliding Sync: Fix state leaking on incremental syncEric Eastwood2024-12-032-1/+69
| |
* | Be able to test `/login/sso/redirect` in Complement (#17986)Eric Eastwood2024-12-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Be able to test `/login/sso/redirect` in Complement Spawning from https://github.com/element-hq/sbg/pull/421#discussion_r1854926218 where we have a proxy that intercepts responses to `/_matrix/client/v3/login/sso/redirect(/{idpId})` in order to upgrade them to use OAuth 2.0 Pushed Authorization Requests (PAR). We have some Complement tests in that codebase that go over this flow and these changes are required [in order for the URL's to line up](https://github.com/element-hq/synapse/blob/d648c8ce3f4cbf61191b9f5302e405f7b0288677/synapse/rest/client/login.py#L652-L673).
* | Sliding Sync: Include invite, ban, kick, targets when `$LAZY`-loading room โ†ตEric Eastwood2024-12-023-8/+17
| | | | | | | | | | members (#17947) Part of https://github.com/element-hq/synapse/issues/17929