Commit Graph

25777 Commits

Author SHA1 Message Date
Erik Johnston 9e2a076144 Port Event class to Rust (#19701)
Ports the event class to Rust.

The main difference here are:
1. There is now a single event class
2. We now validate a lot more at event construction time than we
previously did (we basically checked nothing before). This required some
changes to the tests, including
https://github.com/matrix-org/sytest/pull/1423

Reviewable commit-by-commit.

### Overview of Event Rust structure

The format of the event struct in Rust is quite different than that in
Python.

The top-level looks like:

```rust
pub struct Event {
    /// The parsed event JSON.
    fields: FormattedEvent,

    /// The event ID. For format v1 this is read directly from the JSON;
    /// for v2+ it is computed from the canonical-JSON hash at
    /// construction time and cached here.
    event_id: Arc<str>,

    /// Synapse-internal per-event state that lives outside the federated
    /// JSON (e.g. outlier flag, soft-failure, stream positions).
    #[pyo3(get)]
    internal_metadata: EventInternalMetadata,

    /// The room version this event was parsed for.
    #[pyo3(get)]
    room_version: &'static RoomVersion,

    /// `None` for accepted events; otherwise a short reason set by auth
    /// when the event was rejected.
    rejected_reason: Option<Box<str>>,
}
```

which includes the actual parsed event in `FormattedEvent`, plus the
rest of the event metadata.

```rust
pub struct FormattedEvent<E = Arc<EventFormatEnum>> {
    #[serde(default)]
    pub signatures: Signatures,

    #[serde(default)]
    pub unsigned: Unsigned,

    #[serde(flatten)]
    pub specific_fields: E,

    #[serde(flatten)]
    pub common_fields: Arc<EventCommonFields>,
}
```

The struct is further split into the common fields, format specific
fields, plus the signatures and unsigned. We split out the signature and
unsigned fields as they are mutable, so when we clone the event we can
still share the common and specific fields and only copy signature and
unsigned.

The `specific_fields` are the fields that depend on the format version.
They can either be a specific format (e.g. `E = EventFormatV1`) or a
type-erased enum `EventFormatEnum` that is across all room versions:

```rust
pub enum EventFormatEnum {
    V1(EventFormatV1),
    V2V3(EventFormatV2V3),
    V4(EventFormatV4),
    VMSC4242(EventFormatVMSC4242),
}
```

For example:

```rust
/// Shared flat-list encoding of `auth_events` and `prev_events`, reused
/// by every format from v2/v3 onwards.
#[derive(Serialize, Deserialize)]
pub struct SimpleAuthPrevEvents {
    pub auth_events: Vec<String>,
    pub prev_events: Vec<String>,
}

/// Version-specific fields for room versions 3-10.
#[derive(Serialize, Deserialize)]
pub struct EventFormatV2V3 {
    pub room_id: Box<str>,
    #[serde(flatten)]
    pub auth_prev_events: SimpleAuthPrevEvents,
}
```


### Dev notes

As discussed in
[`#element-backend-internal:matrix.org`](https://matrix.to/#/!SGNQGPGUwtcPBUotTL:matrix.org/$3gTjDO440GbAz57cXcCawwiyFLiD0crrarvS1uhzKOY?via=jki.re&via=element.io&via=matrix.org)

---------

Co-authored-by: Eric Eastwood <erice@element.io>
2026-06-02 11:05:38 +01:00
dependabot[bot] 6c3ba2205b Bump idna from 3.11 to 3.15 (#19790)
Bumps [idna](https://github.com/kjd/idna) from 3.11 to 3.15.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/kjd/idna/blob/master/HISTORY.md">idna's
changelog</a>.</em></p>
<blockquote>
<h2>3.15 (2026-05-12)</h2>
<ul>
<li>Enforce DNS-length cap on individual labels early in
<code>check_label</code>,
short-circuiting contextual-rule processing for oversized input
while staying compatible with UTS 46 usage.</li>
<li>Tidy core helpers: hoist bidi category sets to module-level
frozensets (avoiding per-codepoint list construction), simplify
length checks, and reuse the shared <code>_unicode_dots_re</code> from
<code>idna.core</code> in the codec module.</li>
<li>Use <code>raise ... from err</code> for proper exception chaining
and
switch internal string formatting to f-strings.</li>
<li>Allow <code>flit_core</code> 4.x in the build backend.</li>
<li>Expand the ruff lint set (flake8-bugbear, flake8-simplify,
pyupgrade, perflint) and apply the surfaced fixes; pin lint CI
to Python 3.14.</li>
<li>Add Dependabot configuration for GitHub Actions.</li>
<li>Convert README and HISTORY from reStructuredText to Markdown.</li>
<li>Reference CVE-2026-45409 for the 3.14 advisory in place of the
initial GHSA identifier.</li>
</ul>
<p>Thanks to Felix Yan, Stan Ulbrych, and metsw24-max for
contributions to this release.</p>
<h2>3.14 (2026-05-10)</h2>
<ul>
<li>Removed opportunity to process long inputs into quadratic
time by rejecting oversize inputs up-front. Closes a bypass
of the CVE-2024-3651 mitigation. [CVE-2026-45409]</li>
</ul>
<p>Thanks to Stan Ulbrych for reporting the issue.</p>
<h2>3.13 (2026-04-22)</h2>
<ul>
<li>Correct classification error for codepoint U+A7F1</li>
</ul>
<h2>3.12 (2026-04-21)</h2>
<ul>
<li>Update to Unicode 17.0.0.</li>
<li>Issue a deprecation warning for the transitional argument.</li>
<li>Added lazy-loading to provide some performance improvements.</li>
<li>Removed vestiges of code related to Python 2 support, including
segmentation of data structures specific to Jython.</li>
</ul>
<p>Thanks to Rodrigo Nogueira for contributions to this release.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/kjd/idna/commit/af30a092e158181d0b35ac66dfa813788126bdd8"><code>af30a09</code></a>
Release 3.15</li>
<li><a
href="https://github.com/kjd/idna/commit/30314d4628744ca14cf2b5820564e5127a9f86f2"><code>30314d4</code></a>
Pre-release 3.15rc0</li>
<li><a
href="https://github.com/kjd/idna/commit/05d4b219aa9eddc47371fcbd2000f0301016f3e9"><code>05d4b21</code></a>
Merge pull request <a
href="https://redirect.github.com/kjd/idna/issues/237">#237</a> from
kjd/convert-docs-to-markdown</li>
<li><a
href="https://github.com/kjd/idna/commit/2987fdba1962bbb2358399e0084ba062b98a0bee"><code>2987fdb</code></a>
Convert README and HISTORY from reStructuredText to Markdown</li>
<li><a
href="https://github.com/kjd/idna/commit/59fa8002d514bf4a5ce7b58f67b9ec587d53fa9c"><code>59fa800</code></a>
Merge pull request <a
href="https://redirect.github.com/kjd/idna/issues/236">#236</a> from
kjd/dependabot/github_actions/actions-f3e34333ea</li>
<li><a
href="https://github.com/kjd/idna/commit/def69834ced5d4b3c50439d8b99c4c856ec19ca2"><code>def6983</code></a>
Merge branch 'master' into
dependabot/github_actions/actions-f3e34333ea</li>
<li><a
href="https://github.com/kjd/idna/commit/bbd8004a797185d8c56bb555cd5c88fde05e0631"><code>bbd8004</code></a>
Merge pull request <a
href="https://redirect.github.com/kjd/idna/issues/234">#234</a> from
StanFromIreland/patch-1</li>
<li><a
href="https://github.com/kjd/idna/commit/edd07c05024344a6ccb517414ccb36683aee99fc"><code>edd07c0</code></a>
Bump github/codeql-action from 3.35.2 to 4.35.2 in the actions
group</li>
<li><a
href="https://github.com/kjd/idna/commit/5557db030c11bdec50d62aa5f631d705d33ba123"><code>5557db0</code></a>
Merge branch 'master' into patch-1</li>
<li><a
href="https://github.com/kjd/idna/commit/f11746cf4981d25123ef7830d3ee60f07de8ae3d"><code>f11746c</code></a>
Merge pull request <a
href="https://redirect.github.com/kjd/idna/issues/235">#235</a> from
StanFromIreland/patch-2</li>
<li>Additional commits viewable in <a
href="https://github.com/kjd/idna/compare/v3.11...v3.15">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=idna&package-manager=pip&previous-version=3.11&new-version=3.15)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/element-hq/synapse/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-06-01 14:45:41 +02:00
dependabot[bot] 71e07d4c75 Bump hashicorp/vault-action from 3.4.0 to 4.0.0 (#19804)
Bumps
[hashicorp/vault-action](https://github.com/hashicorp/vault-action) from
3.4.0 to 4.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/hashicorp/vault-action/releases">hashicorp/vault-action's
releases</a>.</em></p>
<blockquote>
<h2>v4.0.0</h2>
<h2>4.0.0 (May 12, 2026)</h2>
<p>Improvements:</p>
<ul>
<li>Bump node runtime from node20 to node24 <a
href="https://redirect.github.com/hashicorp/vault-action/pull/604">GH-604</a></li>
<li>Fix leading slash in secret paths causing HTTP 400 errors (e.g.
<code>/cubbyhole/test</code> → <code>v1/cubbyhole/test</code> instead of
<code>v1//cubbyhole/test</code>)</li>
<li>bump jsrsasign from 11.1.0 to 11.1.3</li>
<li>bump body-parser from 1.20.3 to 1.20.5</li>
<li>bump qs from 6.13.0 to 6.15.1</li>
<li>bump http-errors from 2.0.0 to 2.0.1</li>
<li>bump minimatch from 3.1.2 to 3.1.5</li>
<li>bump underscore from 1.13.4 to 1.13.8</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/hashicorp/vault-action/blob/main/CHANGELOG.md">hashicorp/vault-action's
changelog</a>.</em></p>
<blockquote>
<h2>4.0.0 (May 12, 2026)</h2>
<p>Improvements:</p>
<ul>
<li>Bump node runtime from node20 to node24 <a
href="https://redirect.github.com/hashicorp/vault-action/pull/604">GH-604</a></li>
<li>Fix leading slash in secret paths causing HTTP 400 errors (e.g.
<code>/cubbyhole/test</code> → <code>v1/cubbyhole/test</code> instead of
<code>v1//cubbyhole/test</code>)</li>
<li>bump jsrsasign from 11.1.0 to 11.1.3</li>
<li>bump body-parser from 1.20.3 to 1.20.5</li>
<li>bump qs from 6.13.0 to 6.15.1</li>
<li>bump http-errors from 2.0.0 to 2.0.1</li>
<li>bump minimatch from 3.1.2 to 3.1.5</li>
<li>bump underscore from 1.13.4 to 1.13.8</li>
</ul>
<h2>3.4.0 (June 13, 2025)</h2>
<p>Bugs:</p>
<ul>
<li>replace all dot chars during normalization (<a
href="https://redirect.github.com/hashicorp/vault-action/pull/580">hashicorp/vault-action#580</a>)</li>
</ul>
<p>Improvements:</p>
<ul>
<li>Prevent possible DoS via polynomial regex (<a
href="https://redirect.github.com/hashicorp/vault-action/pull/583">hashicorp/vault-action#583</a>)</li>
</ul>
<h2>3.3.0 (March 3, 2025)</h2>
<p>Features:</p>
<ul>
<li>Wildcard secret imports can use <code>**</code> to retain case of
exported env keys <a
href="https://redirect.github.com/hashicorp/vault-action/pull/545">GH-545</a></li>
</ul>
<h2>3.2.0 (March 3, 2025)</h2>
<p>Improvements:</p>
<ul>
<li>Add retry for jwt auth login to fix intermittent login failures <a
href="https://redirect.github.com/hashicorp/vault-action/pull/574">GH-574</a></li>
</ul>
<h2>3.1.0 (January 9, 2025)</h2>
<p>Improvements:</p>
<ul>
<li>fix wildcard handling when field contains dot <a
href="https://redirect.github.com/hashicorp/vault-action/pull/542">GH-542</a></li>
<li>bump body-parser from 1.20.0 to 1.20.3</li>
<li>bump braces from 3.0.2 to 3.0.3</li>
<li>bump cross-spawn from 7.0.3 to 7.0.6</li>
<li>bump micromatch from 4.0.5 to 4.0.8</li>
</ul>
<p>Features:</p>
<ul>
<li><code>secretId</code> is no longer required for approle to support
advanced use cases like machine login when <code>bind_secret_id</code>
is false. <a
href="https://redirect.github.com/hashicorp/vault-action/pull/522">GH-522</a></li>
<li>Use <code>pki</code> configuration to generate certificates from
Vault <a
href="https://redirect.github.com/hashicorp/vault-action/pull/564">GH-564</a></li>
</ul>
<h2>3.0.0 (February 15, 2024)</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/hashicorp/vault-action/commit/892a26828f195e65540a40b4768ae4571f51ebfc"><code>892a268</code></a>
Update copywrite headers for v.4.0.0 release (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/607">#607</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/a7ffa26e2e6ede175ca2e4f7dec54e78425d6936"><code>a7ffa26</code></a>
Prepare for release v4.0.0 (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/606">#606</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/a049f0183861f1dbbd996f64b48335487cc968db"><code>a049f01</code></a>
[COMPLIANCE] Add/Update Copyright Headers (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/605">#605</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/95977a3e2387e93244aaae1232de66fc47b379a3"><code>95977a3</code></a>
Adding team-vault-consumption as CODEOWNERS (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/600">#600</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/7e48e563b6a9b4b0ba8b028c5ee89c41a8ae2671"><code>7e48e56</code></a>
Upgrade Node.js to 24 and update dependencies (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/604">#604</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/79632e33d6953d190b940ffa440bf97821cabd80"><code>79632e3</code></a>
[COMPLIANCE] Add Copyright and License Headers (Batch 1 of 1) (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/589">#589</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/734c523c4fbdb289cdf26dd2dc177f3627d1e140"><code>734c523</code></a>
README.md: Removing jwtGithubAudience default (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/590">#590</a>)</li>
<li><a
href="https://github.com/hashicorp/vault-action/commit/2c5827061f1ad91ca97897d6257ebe638e033699"><code>2c58270</code></a>
[Compliance] - PR Template Changes Required (<a
href="https://redirect.github.com/hashicorp/vault-action/issues/586">#586</a>)</li>
<li>See full diff in <a
href="https://github.com/hashicorp/vault-action/compare/4c06c5ccf5c0761b6029f56cfb1dcf5565918a3b...892a26828f195e65540a40b4768ae4571f51ebfc">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=hashicorp/vault-action&package-manager=github_actions&previous-version=3.4.0&new-version=4.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-06-01 14:38:08 +02:00
Richard van der Hoff 2aef6c33a8 Add logging to help diagnose missing to-device messages (#19801)
Some attempts to debug
https://github.com/element-hq/synapse/issues/19795.

---------

Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
Co-authored-by: Eric Eastwood <erice@element.io>
2026-06-01 11:34:12 +01:00
shcherbak 306d8b23bd Feat/gcp json formatter (#19775)
Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
2026-05-29 10:57:33 +00:00
dependabot[bot] c45096e7e8 Bump sigstore/cosign-installer from 4.1.1 to 4.1.2 in the minor-and-patches group (#19803)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-29 09:00:39 +00:00
Tulir Asokan a6b8a19ac7 Add workaround for missing events in _should_perform_remote_join (#19730) 2026-05-28 17:44:17 +00:00
dependabot[bot] 0a6aed8df2 Bump rand from 0.9.2 to 0.9.4 (#19687)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-28 17:35:45 +00:00
dependabot[bot] 65ddc7118a Bump go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp from 1.34.0 to 1.43.0 in /complement (#19673)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-28 17:33:26 +00:00
Olivier 'reivilibre f9f08db4c3 Changelog tweaks v1.154.0rc1 2026-05-27 14:27:37 +01:00
Olivier 'reivilibre 82d66fa0f1 1.154.0rc1 2026-05-27 12:27:43 +01:00
Tulir Asokan 0e39c0c8f6 Fix policy server signature merging again (#19797)
Fixes #19796
2026-05-26 14:12:20 -05:00
Olivier 'reivilibre 4655b435ee Follow #19468 (Fix sending heroes in Sliding Sync) with small tweaks (#19791)
Follows: #19468


The main change is from this comment
https://github.com/element-hq/synapse/pull/19468#discussion_r2810364196
I am pretty sure it's safe and was tempted to add it to that PR, but for
easier bisection and reversion in case it goes wrong, thought a separate
commit would be the best.

The other drive-by change is a boolean logic simplification


Simplify condition (boolean equivalence) 

Don't fetch name state from `meta_room_state` since it's no longer used
there

---------

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-05-20 16:58:39 +01:00
dependabot[bot] 57299fd5bd Bump lxml from 6.0.2 to 6.1.0 (#19716)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-20 13:32:08 +00:00
Joe Groocock 966e193e4e Fix sending heroes in SSS when m.room.name="" (#19468)
As per the spec, a room with m.room.name value that is absent, null or
empty should be treated as if there is no m.room.name event at all:
https://spec.matrix.org/v1.17/client-server-api/#mroomname

This fetches the full m.room.name event and checks the content.name
instead of only checking the existence of the m.room.name event. This
results in correctly sending heroes for those rooms.

Fixes: https://github.com/element-hq/synapse/issues/19447

Signed-off-by: Joe Groocock <me@frebib.net>
2026-05-20 12:10:54 +01:00
Oleg Girko be03be7b50 Partially revert "Bump attrs from 25.4.0 to 26.1.0 (#19684)" (#19789)
Accidental bump broke build for Fedora and RHEL.

This reverts commit 2e9d6f7f35.

As discussed in the [Synapse Package
Maintainers](https://matrix.to/#/!rh9Uxk45AsPongyP3ypgpsCmuIufiggD6mDXFWh4_FM/$0mdulZEyJFdI6bwS8GFwYnFt-zmpyCyx2DwcA8JyuY8?via=jki.re&via=matrix.org&via=element.io)
room (private)
2026-05-20 11:47:43 +01:00
FrenchGithubUser 87095ae500 fix: invalidate access token cache on device deletion (#19483)
when an access token had a refresh token associated to it in the
database, deleting this refresh token (for example when deleting the
device using it) would cascade delete the access token, which wouldn't
be returned by the sql query that was supposed to delete it on its own,
and an empty array was passed to the cache invalidation function.
2026-05-20 11:06:16 +01:00
Olivier 'reivilibre f83e8c34c5 Merge branch 'master' into develop 2026-05-19 14:34:40 +01:00
Olivier 'reivilibre 7b1c4da5df 1.153.0 v1.153.0 2026-05-19 14:13:03 +01:00
dependabot[bot] ec4950b438 Bump types-jsonschema from 4.26.0.20260202 to 4.26.0.20260508 (#19683)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-18 16:10:40 +00:00
Olivier 'reivilibre 4d0e4ff935 Fix /sync failing when MSC4354 Sticky Events are enabled and the sync request filters out Ephemeral Data Units (EDUs). (#19787)
Fixes: #19779
Fixes: https://github.com/element-hq/synapse/issues/19618

See also: #19786 (which would have caught this, but currently has too
many findings to enable)

Fix UnboundLocalError when MSC4354 is enabled in sync and all EDUs are
filtered out

---------

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-05-18 12:15:57 +01:00
Gaëtan d8b4ffdf2d Fix validation of frozen message event with mentions. (#19634)
Fixes: #19689

# What

This PR fixes a bug I found when I run synapse (from dockerhub) and
register a `check_event_allowed` callback and my client makes use of the
mentions field in messages (`cinny:latest`). The bug doesn't appear when
the `check_event_allowed` callback is not loaded.

After some digging I noticed that the current validation of the mentions
doesn't work when an event has been frozen with `event.freeze()`. For
the messages this seems to happen when a the `check_event_allowed` is
registered (but not otherwise), see [where the event is frozen for
check_event_allowed
callback](https://github.com/element-hq/synapse/blob/b0fc0b7a612a42e6f15b87dee2a1db4c383645fb/synapse/module_api/callbacks/third_party_event_rules_callbacks.py#L289)
and [where the validation function is
called](https://github.com/element-hq/synapse/blob/b0fc0b7a612a42e6f15b87dee2a1db4c383645fb/synapse/handlers/message.py#L1404).

To have a minimal reproduction example, the following scripts fails on
`develop` but succeeds in this branch:

``` python
from synapse.api.room_versions import RoomVersions
from synapse.events import EventBase, make_event_from_dict
from synapse.events.validator import EventValidator

from tests.utils import default_config


def make_message_event(content: dict) -> EventBase:
    return make_event_from_dict(
        {
            "room_id": "!room:test",
            "type": "m.room.message",
            "sender": "@alice:test",
            "content": content,
            "auth_events": [],
            "prev_events": [],
            "hashes": {"sha256": "aGVsbG8="},
            "signatures": {},
            "depth": 1,
            "origin_server_ts": 1000,
        },
        room_version=RoomVersions.V9,
    )


event = make_message_event(
    {
        "msgtype": "m.text",
        "body": "@moderator:example.com hello",
        "m.mentions": {"user_ids": ["@moderator:jailbreak-challenge.aqtiveguard.com"]},
    }
)

EventValidator().validate_new(event, default_config)  # Ok
event.freeze()
EventValidator().validate_new(event, default_config)  # throws
# pydantic_core._pydantic_core.ValidationError: 1 validation error for Mentions
#   Input should be a valid dictionary or instance of Mentions [type=model_type, input_value=immutabledict({'user_ids'...nge.aqtiveguard.com',)}), input_type=immutabledict]
#     For further information visit https://errors.pydantic.dev/2.12/v/model_type
```

# How

I made the validation logic also validate the transformation performed
by the freezing process, namely:
- `immutabledict` validates as `dict`. (was already implemented for
POWER_LEVELS)
- `tuple` validates as array (added this to the validator in this PR).


---------

Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
Co-authored-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-05-18 10:27:10 +01:00
Eric Eastwood 8eb220a5e2 Replace wait_for_quarantined_media_stream_id(...) with standard wait_for_stream_token(...) (#19764)
In order to be able to use `wait_for_stream_token(...)`, we have to add
the `quarantined_media` stream to the `StreamToken`. Even though we
don't care about `/sync`'ing `quarantined_media`, this aligns with the
future where all endpoints should probably use `StreamToken`, see
https://github.com/element-hq/synapse/issues/19647

Follow-up to https://github.com/element-hq/synapse/pull/19558 and
https://github.com/element-hq/synapse/pull/19644
2026-05-15 13:51:03 -05:00
Eric Eastwood 19f636244c Prefer close backfill points (absolute distance) (#19748)
This isn't fixing any particular issue. It's just a follow-up I thought
about after merging https://github.com/element-hq/synapse/pull/19611
since we're now also dealing with backfill points in the nearby range
ahead of the `current_depth`. And it's possible that the previous sort
could bias to all nearby backfill points ahead of the `current_depth`
that don't extend into the visible window of events we're paginating
through.
2026-05-15 11:49:11 -05:00
mhlas7 0c6e0f79e5 doc: Enhance update_profile_information documentation with picture claim (#19508)
Added details how synapse syncs the picture claim when
update_profile_information setting is true. Addresses #17836

---------

Co-authored-by: Michael Hlas <3398654+mhlas7@users.noreply.github.com>
2026-05-15 15:29:53 +00:00
Olivier 'reivilibre c9c3fc769a Merge branch 'release-v1.153' into develop 2026-05-15 13:21:14 +01:00
Olivier 'reivilibre 0ff50720d8 1.153.0rc3 v1.153.0rc3 2026-05-15 11:43:12 +01:00
Olivier 'reivilibre 71e1da976c Revert "Send a SSS response immediately if the config has changed and there are new results to sync (#19714)" (#19784)
Reverts: #19714

Opens: #19783

Closes: https://github.com/element-hq/backend-internal/issues/242

Related: #18880 (the performance problem that is aggravated by #19714)

This reverts commit 2691d0b8b1.

---------

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-05-15 11:41:21 +01:00
Olivier 'reivilibre 3f0f03d536 Revert "Send a SSS response immediately if the config has changed and there are new results to sync (#19714)" (#19784)
Reverts: #19714

Opens: #19783

Closes: https://github.com/element-hq/backend-internal/issues/242

Related: #18880 (the performance problem that is aggravated by #19714)

This reverts commit 2691d0b8b1.

---------

Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
2026-05-15 10:36:47 +00:00
dependabot[bot] 9ce68a6a4a Bump gitpython from 3.1.47 to 3.1.50 (#19767)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-15 10:29:39 +00:00
dependabot[bot] 5c8419eed7 Bump authlib from 1.6.11 to 1.6.12 (#19776)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-15 10:26:51 +00:00
dependabot[bot] cf64199ea0 Bump urllib3 from 2.6.3 to 2.7.0 (#19771)
Signed-off-by: dependabot[bot] <support@github.com>
2026-05-15 10:24:49 +00:00
Erik Johnston ff55aff5b2 Fix up event-construction in tests ahead of the Rust event port (#19781)
When we port the `Event` class to Rust, the constructor will check for
the existence of required fields. To support that, we tidy up the test
code where we construct fake events to add all the required fields.

There should be no behavioural changes.

Review commit-by-commit.
2026-05-15 10:12:42 +01:00
Eric Eastwood b233892a13 Update wait_for_stream_token(...) patterns and fix sync fetching with unbounded token (#19644)
Spawning from trying to find the proper way to wait for a token, see
https://github.com/element-hq/synapse/pull/19558#discussion_r2977673208

- Update `wait_for_stream_token(...)` patterns so
validation/sanitization is handled upstream in usage.
- Fix sync waiting for bounded token but using unbounded token to fetch
data. Noticed while working on adding the new method.

Part of https://github.com/element-hq/synapse/issues/19647
2026-05-14 14:53:16 -05:00
Erik Johnston 86a1e73ef4 Consolidate MSC4242 state DAG checks via a TypeIs helper (#19774)
The reason for the change is to make it easier to support these checks
when porting event class to Rust.

Previously, code that needed to access `prev_state_events` had to
combine a `room_version.msc4242_state_dags` boolean check with an
`isinstance(event, FrozenEventVMSC4242)` cast (or `cast()`) for the type
checker. Introduce `supports_msc4242_state_dag()` in a new
`synapse/events/py_protocol.py` which does both in one step via
`TypeIs[MSC4242Event]`, removing the need to import the concrete
`FrozenEventVMSC4242` class at every call site.

`MSC4242Event` is an `EventBase` subclass used purely for type narrowing
— it's marked with a metaclass that rejects `isinstance()` to make
accidental runtime use loud.

No behavioural change: callers continue to gate on the same room version
flag and access the same `prev_state_events` attribute.
2026-05-14 18:02:33 +00:00
Erik Johnston ace8447037 Tidy up Rust RoomVersion structs (#19766)
This is in prep for using the room versions more from Rust.

Main changes:
- Change it so each room version is defined as a delta to the last one.
This is a cosmetic change that makes it easier to ensure the room
version definitions are correct (as they're defined as deltas from
previous versions).
- Move constants to `RoomVersion` constants, like `RoomVersion::V1`, for
convenience.
- Change visibility of various attributes.
2026-05-14 11:21:00 +01:00
Erik Johnston b90a0e9fe9 Use StrCollection for prev_state_events. (#19777)
Convert `prev_state_events` to use `StrCollection` rather than requiring
it to be a mutable list. None of the usages require it to be a proper
list, and besides, events are immutable and therefore so should
`event.prev_state_events`.
2026-05-14 10:29:16 +01:00
Eric Eastwood ff0420a03c Improve We can't get valid state history. logging (#19765)
Add `event_id` so you can actually correlate everything together in the logs.
2026-05-13 12:31:38 -05:00
Olivier 'reivilibre 4eaee2b879 Merge branch 'release-v1.152' into release-v1.153 2026-05-13 16:29:19 +01:00
Andrew Morgan 1409dbc229 Merge remote-tracking branch 'origin/release-v1.152' into develop 2026-05-13 17:27:06 +02:00
Denis Kasak 16c17f3a42 Add CVE IDs to changelog for 1.152.1. (#19778)
Since this is just a change log update, I've removed the entire
checklist. Please tell me if this is incorrect.
2026-05-13 15:26:16 +00:00
Olivier 'reivilibre 1b0622fa99 Merge branch 'release-v1.153' into develop 2026-05-13 13:10:18 +01:00
Olivier 'reivilibre f109c25960 1.153.0rc2 v1.153.0rc2 2026-05-13 12:01:11 +01:00
Erik Johnston 5efeac44b2 Handle arbitrary sized integers in unsigned. (#19769)
Handle arbitrary sized integers in `unsigned` (and other Rust objects
that use `serde_json::Value`)
2026-05-13 11:28:06 +01:00
Eric Eastwood b8bd35105f Update WorkerLock tests to better stress the WORKER_LOCK_MAX_RETRY_INTERVAL (#19772)
There is no behavioral change, only a change to the tests. See
https://github.com/element-hq/synapse/pull/19772#discussion_r3222059105
for an explanation of why the tests needed changing (and diff comments).

Follow-up to https://github.com/element-hq/synapse/pull/19394. The test
discussion originally happened in
https://github.com/element-hq/synapse/pull/19394#discussion_r2789673181

This is spawning from thinking about the problem again.
2026-05-12 10:10:09 -05:00
Will Hunt 5c87faf9e9 MSC4452: Preview URL capability (#19715)
Implementation of
https://github.com/matrix-org/matrix-spec-proposals/pull/4452
2026-05-11 12:39:38 +01:00
Olivier 'reivilibre b2d196f3ed Merge branch 'release-v1.153' into develop 2026-05-08 16:20:19 +01:00
Erik Johnston c430c16df4 Port event content to Rust (#19725)
Based on #19708.

This is on the path to porting the entire event class to Rust, as
`event.content` will then return the new Rust class `JsonObject`.

This PR adds a pure Rust `JsonObject` class that is a `Mapping`
representing a json-style object. It uses `serde_json::Value` as its
in-memory representation and `pythonize` for conversion when a field is
looked up on the object.

I'm not thrilled with the name, but couldn't think of a better one.

This also adds `JsonObject` handling to the JSON serialisation functions
we use, as well as to the `freeze(..)` function.

Reviewable commit-by-commit.
2026-05-08 14:19:03 +01:00
Olivier 'reivilibre eb2ae9d3da Tweak changelog v1.153.0rc1 2026-05-08 14:03:41 +01:00
Olivier 'reivilibre 0e508ba80f 1.153.0rc1 2026-05-08 13:22:15 +01:00