25699 Commits

Author SHA1 Message Date
Olivier 'reivilibre d97b5b9e21 1.152.1 v1.152.1 2026-05-07 13:49:49 +01:00
Olivier 'reivilibre 2d48851438 Prevent pagination ending when a page is full of rejected events (ELEMENTSEC-2025-1636)
Fixes: https://github.com/element-hq/synapse/security/advisories/GHSA-6qf2-7x63-mm6v

Reviewed-on: https://github.com/element-hq/synapse-private/pull/117
2026-05-07 13:26:43 +01:00
Jason Little 0eefdbcb95 fix: Cap WorkerLock timeout intervals to 60 seconds (#19394)
Fixes the symptoms of https://github.com/element-hq/synapse/issues/19315
/ https://github.com/element-hq/synapse/issues/19588 but not the
underlying reason causing the number to grow so large in the first
place.

```
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
```

Copied from the original pull request on [Famedly's Synapse
repo](https://github.com/famedly/synapse/pull/221) (with some edits):

Basing the time interval around a 5 seconds leaves a big window of
waiting especially as this window is doubled each retry, when another
worker could be making progress but can not.

Right now, the retry interval in seconds looks like `[0.2, 5, 10, 20,
40, 80, 160, 320, (continues to double)]` after which logging should
start about excessive times and (relatively quickly) end up with an
extremely large retry interval with an unrealistic expectation past the
heat death of the universe. 1 year in seconds = 31,536,000.

With this change, retry intervals in seconds should look more like:

```
[
0.2,
0.4,
0.8,
1.6,
3.2,
6.4,
12.8,
25.6,
51.2,
60, < never goes higher than this
]
```

Logging about excessive wait times will start at 10 minutes.

<details>
<summary>Previous breakdown when we were using 15 minutes</summary>

```
[
0.2,
0.4,
0.8,
1.6,
3.2,
6.4,
12.8,
25.6,
51.2,
102.4,  # 1.7 minutes
204.8,  # 3.41 minutes
409.6,  # 6.83 minutes
819.2,  # 13.65 minutes  < logging about excessive times will start here, 13th iteration
900,  # 15 minutes < never goes higher than this
]
```
</details>

Further suggested work in this area could be to define the cap, the
retry interval starting point and the multiplier depending on how
frequently this lock should be checked. See data below for reasons why.
Increasing the jitter range may also be a good idea

---------

Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
(cherry picked from commit 3f58bc50df)
2026-05-07 13:25:04 +01:00
Olivier 'reivilibre 16863c87d5 Changelog tweaks v1.152.0 2026-04-28 13:45:53 +01:00
Olivier 'reivilibre fa52c62a89 1.152.0 2026-04-28 11:47:16 +01:00
Olivier 'reivilibre 613cb4df1c Pruning data is a feature v1.152.0rc1 2026-04-22 12:09:35 +01:00
Olivier 'reivilibre 2e0905e4c4 fixup! 1.152.0rc1 (3rd try) 2026-04-22 12:08:19 +01:00
Olivier 'reivilibre b07a7cc285 1.152.0rc1 (3rd try) 2026-04-22 12:05:39 +01:00
Olivier 'reivilibre fbaff67e1b Merge branch 'develop' into release-v1.152 2026-04-22 12:01:44 +01:00
Erik Johnston c8ce96f504 Reinstate removed EventBase methods (#19712)
Both `__getitem__` and `.user_id` were removed in #19680 to simplify the
event class. However, `EventBase` is exposed to modules who might also
make use of those methods, so let's reinstate them (but otherwise not
reinstate the usage of them in the code).
2026-04-22 11:43:59 +01:00
Erik Johnston 3cdae2e278 Fix race in new pruning of device lists tables. (#19709)
Follows on from #19473.

We should be recording where we have deleted up to in the same
transaction as we perform the delete, rather than at the end. This code
only starts deleting rows after a month (and the original PR isn't in a
release yet), so no server should have run into this problem yet.

Also let's log more regularly, as the initial set of deletions will
likely take a long time.
2026-04-21 11:39:39 +01:00
Andrew Morgan a9361c4f51 Bail out if admin_unsafely_bypass_quarantine was used by a non-admin (#19639) 2026-04-17 15:27:41 +00:00
Eric Eastwood 67b4d8e7e3 Add docs for what to document about a new stream (#19696)
Spawning from the follow-up necessary when adding a new stream
(https://github.com/element-hq/synapse/pull/19694)
2026-04-17 09:50:37 -05:00
Erik Johnston 2a8285931e Prune old rows in device_lists_changes_in_room table. (#19473)
Fixes #13043

The usages of the table mostly already correctly handled if we don't
have old entries, as that was needed when we first added the table.

I arbitrarily set the prune time to 30 days. The only use for old
entries is for sync streams that haven't synced since then, and we
should very rarely see sync streams that haven't been used in 30 days.

Reviewable commit-by-commit.

---------

Co-authored-by: Olivier 'reivilibre' <oliverw@element.io>
Co-authored-by: Olivier 'reivilibre' <olivier@librepush.net>
2026-04-17 11:54:22 +01:00
Shay 647fb59190 Add Admin API endpoints to manage user reports (#19657)
Adds [Admin
API](https://element-hq.github.io/synapse/latest/usage/administration/admin_api/index.html)
endpoints to list, fetch and delete user reports from the homeserver.
Follows on from #18120, which added the endpoints to report users.
2026-04-17 11:01:23 +01:00
dependabot[bot] bdb1cf7416 Bump authlib from 1.6.9 to 1.6.11 (#19703) 2026-04-17 10:57:38 +01:00
Kegan Dougal 15c03b9689 MSC4242: State DAGs (CSAPI) (#19424)
This implements [MSC4242: State
DAGs](https://github.com/matrix-org/matrix-spec-proposals/pull/4242),
without support for federation.

A general overview:
 - It adds a new room version and new event type.
 - It adds a new field `calculated_auth_event_ids` to internal metadata.
- It stores the state DAG via new state DAG edges / forward extremities
tables.
 - It adds new auth rules as per the MSC.
- It uses the new `prev_state_events` field instead of
`prev_event_ids()` when doing state resolution.

Complement tests: https://github.com/matrix-org/complement/pull/841

### 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>
2026-04-16 15:46:47 +00:00
Olivier 'reivilibre 09b48cf060 1.152.0rc1 (retry) 2026-04-16 14:23:45 +01:00
Olivier 'reivilibre 4252efa210 Merge branch 'develop' into release-v1.152 2026-04-16 14:16:46 +01:00
Olivier 'reivilibre 964ca65ebb Support MSC4450: Identity Provider selection for User-Interactive Authentication with Legacy Single Sign-On. (#19693)
Closes: #19688

Part of: MSC4450 whose Experimental Feature tracking issue is #19691


Add an unstable, namespaced `idp_id` query parameter to `fallback/web` \
This allows clients to specify the identity provider they'd like to log
in with for SSO when they have multiple upstream IdPs associated with
their account.

Previously, Synapse would just pick one arbitrarily. But this was
undesirable as you may want to use a different one at that point in
time. When logging in, the user is able to choose when IdP they use -
during UIA (which uses fallback auth mechanism) they should be able to
do the same.

-----

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
2026-04-16 12:19:28 +01:00
Travis Ralston e1b56313de Add upgrade notes for new quarantined_media_changes stream (#19694)
Fixes https://github.com/element-hq/synapse/issues/19692

Introduced by https://github.com/element-hq/synapse/pull/19558

---------

Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
2026-04-16 10:31:10 +00:00
Erik Johnston 2d015f78ea Convert EventInternalMetadata to use Arc<RwLock<_>> (#19669)
This moves the reference counting from PyO3 into standard Rust types,
allowing the class to be used natively from Rust without needing a
Python runtime.
2026-04-16 10:59:39 +01:00
Erik Johnston 71781de707 Add a FilteredEvent type to handle per-user data on events (#19640)
When we return events to clients we need to annotate them with the
membership of the user at the time of the event, in the `unsigned`
section. We already check the membership at the event during the
visibility checks, and so we annotate events there. However, since this
a per-user field we end up having to clone the event in question.

Instead, let's add a `FilteredEvent` class that is returned by the
visibility checks, which allows returning the membership without editing
the event. This has three benefits:
1. Avoids the clones of the event.
2. Allows us to statically check that we have filtered events before
returning them to clients.
3. We no longer edit `unsigned` data after event deserialization, this
makes it easier to port the event class to Rust.

The last benefit is why we're doing this *now*, however IMV it shouldn't
affect whether we want this change or not.

Reviewable commit-by-commit

---------

Co-authored-by: Olivier 'reivilibre' <oliverw@element.io>
2026-04-16 09:47:08 +01:00
Olivier 'reivilibre 943da0ace8 Fix database migrations failing on platforms where SQLite is configured with SQLITE_DBCONFIG_DEFENSIVE by default, such as macOS. (#19690)
Fixes: #19616

This caused 2+ people trouble now, so worth batting away with a
low-effort change if we can.

Only seen on macOS so far, but nothing stops SQLite being configured in
defensive mode by default on other platforms, so it is not necessarily
entirely specific to macOS.

We *could* also do this for Python < 3.12 but it'd be more effort and I
don't know if it's worth it.

(For context @kegsay says the interpreter with this problem was
installed through `pyenv install`.)

---------

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-04-15 16:55:46 +01:00
Olivier 'reivilibre 52c05c5ca4 Introduce spam_checker_spammy internal event metadata. (#19453)
Follows: #19365

Part of: MSC4354 Sticky Events (experimental feature #19409)

This PR introduces a `spam_checker_spammy` flag, analogous to
`policy_server_spammy`, as an explicit flag
that an event was decided to be spammy by a spam-checker module.

The original Sticky Events PR (#18968) just reused
`policy_server_spammy`, but it didn't sit right with me
because we (at least appear to be experimenting with features that)
allow users to opt-in to seeing
`policy_server_spammy` events (presumably for moderation purposes).

Keeping these flags separate felt best, therefore.

As for why we need this flag: soon soft-failed status won't be
permanent, at least for sticky events.
The spam checker modules currently work by making events soft-failed.
We want to prevent spammy events from getting
reconsidered/un-soft-failed, so it seems like we need
a flag to track spam-checker spamminess *separately* from soft-failed.

Should be commit-by-commit friendly, but is also small.

---------

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-04-15 16:53:23 +01:00
Quentin Gliech bed00bb766 Allow resigning of events with a new signing key (#19668)
This adds a way to re-sign all locally-created events with a new signing
key, which is useful when rotating server signing keys.

This doesn't trigger automatically, instead needs to be triggered when
needed via the admin API.

c.f.
https://github.com/matrix-org/internal-config/issues/1670#issuecomment-4206020126
for internal discussion.

---------

Co-authored-by: Kegan Dougall <kegan@element.io>
Co-authored-by: Erik Johnston <erikj@element.io>
2026-04-14 16:44:58 +00:00
Olivier 'reivilibre d4034c0cf8 1.152.0rc1 2026-04-14 13:16:25 +01:00
Eric Eastwood 1a949608d5 Re-usable Complement GitHub CI workflow (#19533)
Docs: https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows
2026-04-13 17:03:46 -05:00
Erik Johnston 8c1ac41cea Small simplifications to the events class (#19680)
This is to make it easier to port to Rust, as well as making things
conceptually simpler.

Two changes:
1. Remove the `__getitem__` interface on events
2. Remove `.user_id` as an alias of `.sender`.
2026-04-13 17:52:13 +01:00
Quentin Gliech 784a28bbc8 Reject device_keys: null in POST /keys/upload (#19637)
The spec says `device_keys` may be omitted, but not set to `null`.
This was temporarily allowed as a workaround for misbehaving clients
(see #19023), which have since been fixed.

Fixes #19030
2026-04-13 15:33:19 +02:00
Eric Eastwood 0e3e947bd6 Fix docstring for limit argument in _maybe_backfill_inner(...) (#19630)
Incorrectly labeled in https://github.com/matrix-org/synapse/pull/13535.

`maybe_backfill` already accurately describes `limit` (introduced in
https://github.com/matrix-org/synapse/pull/8349)

Spotted in
https://github.com/element-hq/synapse/pull/19611#discussion_r3011259710
2026-04-10 13:58:30 -05:00
dependabot[bot] 62523d89ba Bump cryptography from 46.0.6 to 46.0.7 (#19674) 2026-04-10 18:09:54 +01:00
dependabot[bot] 2390116e94 Bump sqlglot from 29.0.1 to 30.2.1 (#19656) 2026-04-10 18:09:21 +01:00
dependabot[bot] aceb081771 Bump actions/setup-go and actions/cache. (#19654) 2026-04-10 18:06:39 +01:00
dependabot[bot] 3a30ca66c7 Bump sentry-sdk, hiredis and pygithub (#19655) 2026-04-10 18:06:08 +01:00
Will Hunt 2439990efc Allow 'article' and 'profile' opengraph fields on URL previews. (#19659) 2026-04-10 18:04:11 +01:00
Travis Ralston a7b87e26ab Switch list quarantined media API to use max to_id instead of current (#19677)
Following up on
https://github.com/element-hq/synapse/pull/19558#discussion_r3054831510

Changelog for this PR is intended to overlap with the above PR.

`get_current_quarantined_media_stream_id` wasn't being used anywhere
else, so we can replace it like we do in this PR.

### 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>
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
2026-04-09 22:06:28 +00:00
Travis Ralston fe742653ff Add an API to list changes to quarantine state of media (#19558)
Fixes https://github.com/element-hq/synapse/issues/19352

(See issue for history of this feature and previous PRs)

> First, a [naive
implementation](https://github.com/element-hq/synapse/pull/19268) of the
endpoint was introduced, but it quickly ran into [performance issues on
query](https://github.com/element-hq/synapse/pull/19312) and [long
startup times](https://github.com/element-hq/synapse/issues/19349),
leading to its
[removal](https://github.com/element-hq/synapse/pull/19351). It also
didn't actually work, and would fail to expose media when it was
"unquarantined", so a [partial
fix](https://github.com/element-hq/synapse/pull/19308) was attempted,
where the suggested direction is to use a
[stream](https://element-hq.github.io/synapse/latest/development/synapse_architecture/streams.html#cheatsheet-for-creating-a-new-stream)
instead of a timestamp column.

This PR re-introduces the API building on the previous feedback:
* Adds a stream which tracks when media becomes (un)quarantined.
* Runs a background update to capture already-quarantined media.
* Adds a new admin API to return rows from the stream table.

We track both quarantine and unquarantine actions in the stream to allow
downstream consumers to process the records appropriately. Namely, to
allow our Synapse exchange in HMA to remove hashes for unquarantined
media (use case further explained in the
[issue](https://github.com/element-hq/synapse/issues/19352)).

**Note**: This knowingly does not capture all cases of media being
quarantined. Other call sites are lower priority for T&S, and can be
addressed in a future PR. ~~An issue will be created after this PR is
merged to track those sites.~~
https://github.com/element-hq/synapse/issues/19672

### 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: Eric Eastwood <madlittlemods@gmail.com>
Co-authored-by: Eric Eastwood <erice@element.io>
2026-04-09 11:41:31 -06:00
Eric Eastwood f7c8967604 Update developer stream docs to point out _setup_sequence(...) in portdb (#19675)
Part of https://github.com/element-hq/synapse/issues/19671

Spawning from [discussion in
`#synapse-dev:matrix.org`](https://matrix.to/#/!i5D5LLct_DYG-4hQprLzrxdbZ580U9UB6AEgFnk6rZQ/$Z3nqbH0Qy21FWC3qJOim6LSRCRpJ3pxV5DLXm98IA6I?via=element.io&via=matrix.org&via=beeper.com)
with roots in
https://github.com/element-hq/synapse/pull/19558#discussion_r3013184415.
As trialed/discovered by @turt2live alongside @reivilibre and @clokep
❤️


### Why is this necessary?

If you forget to add `_setup_sequence(...)`, you can run into the
following error if there is 1 row in SQLite and then you use the
`portdb` script to try to migrate to Postgres (as
[explained](https://matrix.to/#/!i5D5LLct_DYG-4hQprLzrxdbZ580U9UB6AEgFnk6rZQ/$mHU6dcTNL7NMfKBCJUekCh7vDj1lr1GDjriZQl7oeeU?via=element.io&via=matrix.org&via=beeper.com)
by @reivilibre)

```
Postgres sequence 'quarantined_media_id_seq' is inconsistent with associated stream position
of 'quarantined_media' in the 'stream_positions' table.
```
2026-04-09 09:49:25 -05:00
Eric Eastwood 35b55e962a Advertise MSC4445 sync timeline order (#19642)
Synapse uses topological ordering for initial sync (first time a room is
sent down `/sync`), https://github.com/element-hq/synapse/blob/2e9b8202f0a1a8ceba9f02bb5ec227498d51dcbd/synapse/handlers/sync.py#L768-L805
2026-04-08 10:47:13 -05:00
Eric Eastwood 15662db095 Fix Docker image link typo in worker docs (#19645)
Fix https://github.com/element-hq/synapse/issues/19521
2026-04-08 10:14:58 -05:00
Quentin Gliech a778497acb Merge branch 'master' into develop 2026-04-07 15:43:26 +02:00
Quentin Gliech 4ea109aa5c Fix the changelog v1.151.0 2026-04-07 14:30:11 +02:00
Quentin Gliech cee606e590 Mention the rc in the bug fix in the changelog 2026-04-07 14:21:23 +02:00
Quentin Gliech 77b329a913 1.151.0 2026-04-07 14:15:50 +02:00
Quentin Gliech 09d83f3127 Fix KNOWN_ROOM_VERSIONS.__contains__ raising TypeError for non-string keys (#19649)
The Rust port of `KNOWN_ROOM_VERSIONS` (#19589) made `__contains__`
strict about key types, raising `TypeError` when called with `None`
instead of returning `False` like a Python dict would.
This broke `/sync` for rooms with a NULL `room_version` in the database.

```
  File "/home/synapse/src/synapse/handlers/sync.py", line 2628, in _get_room_changes_for_initial_sync
    if event.room_version_id not in KNOWN_ROOM_VERSIONS:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument 'key': 'NoneType' object cannot be cast as 'str'
```
2026-04-07 12:12:01 +00:00
Noah Markert 8291a493c7 resolves #19403 Report the rust compiler version used in the prometheus metrics (#19643)
# What is done?
- resolves #19403
- Adds build-time Rust compiler detection and captures the rustc
--version value during the build.
- Exposes the captured compiler version from the Rust extension via a
new Python-callable function.
- Exports a new Prometheus metric for rustc version.

# How to test?
- compile `poetry install`
- add `enable_metrics: true` and 
```yaml
    resources:
    - compress: false
      names:
      - client
      - federation
      - metrics
```
to homeserver.yaml
- start synapse
- find the rustc version at `http://localhost:8008/_synapse/metrics`

### 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>
2026-04-03 11:21:23 +02:00
Neil Johnson 62f23fed27 include workaround for macos (#19615)
Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
2026-04-02 13:29:18 +00:00
dependabot[bot] cb6989514e Bump pygments from 2.19.2 to 2.20.0 (#19632)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-02 11:47:54 +00:00
Eric Eastwood 2e9b8202f0 Document context for why increase timeout for policy server requests (#19633)
See https://github.com/element-hq/synapse/pull/19629#discussion_r3011377886
2026-03-31 14:10:36 -05:00