Commit Graph

25810 Commits

Author SHA1 Message Date
Erik Johnston ae3a03fc4f Sanity check state_key is None instead of some empty string 2026-05-27 13:37:22 +01:00
Erik Johnston 9fa851d7f5 Comment on why state_key_attr 2026-05-27 13:31:59 +01:00
Erik Johnston 141df2ed8b Comment on why we're using a Mock 2026-05-27 13:28:28 +01:00
Erik Johnston 90ee916529 Comment on type ignore 2026-05-27 13:23:38 +01:00
Erik Johnston da42b90fa1 Add back isinstance EventProtocol test 2026-05-27 13:20:10 +01:00
Erik Johnston feaa364f86 Rename bad_key to unknown_key 2026-05-27 13:14:57 +01:00
Erik Johnston d6258ff227 Make test_redact_missing_type clearer 2026-05-27 13:13:42 +01:00
Erik Johnston 925f5a1294 Handle MSC4242 in redact 2026-05-27 12:57:30 +01:00
Erik Johnston 15462d1d44 Lint 2026-05-27 12:57:16 +01:00
Erik Johnston f1ae164ab9 Remove redacted_because TODO 2026-05-27 12:53:46 +01:00
Erik Johnston 51ace0f588 Don't check PDU size in compute_reference_hash 2026-05-27 12:52:45 +01:00
Erik Johnston 1479a94ee7 Pop AGE_TS when redacting as well 2026-05-27 12:47:45 +01:00
Erik Johnston ecf8e8c869 Comment why type_ 2026-05-27 12:05:15 +01:00
Erik Johnston 309f826d21 Note that third-party modules rely on deprecated functions 2026-05-27 12:04:04 +01:00
Erik Johnston ee669251c1 Clean up .sticky_duration() 2026-05-27 12:02:50 +01:00
Erik Johnston ffe6c8b430 Add MSC4354_STICKY constant 2026-05-27 11:51:03 +01:00
Erik Johnston 17b231c3e8 Fix RoomPolicyTestCase to not set signature block 2026-05-27 11:35:11 +01:00
Erik Johnston 7d5f36d2a4 Merge remote-tracking branch 'origin/develop' into erikj/events_rust 2026-05-27 11:22:59 +01:00
Erik Johnston 1d7f67f91b Change new test_validate_new_with_mentions_succeeds_even_when_frozen test
Since we no longer have an `event.freeze()` we simply test that the
validator works on the (already frozen) event.

Test was introduced in #19634
2026-05-27 11:16:06 +01:00
Tulir Asokan 0e39c0c8f6 Fix policy server signature merging again (#19797)
Fixes #19796
2026-05-26 14:12:20 -05:00
Erik Johnston 2d866f945f Merge remote-tracking branch 'origin/develop' into erikj/events_rust 2026-05-21 15:04:37 +01:00
Erik Johnston 025f1a479e Fix tests 2026-05-21 14:56:48 +01:00
Erik Johnston c9e9d76e86 Make MAX_DURATION a SynapseDuration 2026-05-21 14:45:52 +01:00
Erik Johnston b99fd7329d s/debug_assert/ensure 2026-05-21 14:37:30 +01:00
Erik Johnston 1bbb0332bd Drop SimpleAuthPrevEvents 2026-05-21 14:36:19 +01:00
Erik Johnston 894d223132 Mention where get_templated_pdu_json is used 2026-05-21 14:34:55 +01:00
Erik Johnston aae2de1cf0 Update get_dict docstring 2026-05-21 14:32:11 +01:00
Erik Johnston 24e7f8516a Rename to parsed_event 2026-05-21 14:31:26 +01:00
Erik Johnston fc65b1d5bc Add room version to error 2026-05-21 14:27:14 +01:00
Erik Johnston 27e312ddaf Make JsonObject.object private 2026-05-21 14:26:02 +01:00
Erik Johnston 8e6e29cf1a Fix MAX_PDU_SIZE_BYTES 2026-05-21 14:15:02 +01:00
Erik Johnston e82ebe17b2 Small refactor to ensure we call 'validate' for all formats 2026-05-21 14:14:29 +01:00
Erik Johnston 69c8d226b8 Ensure we don't have stray auth_events or event_id fields unexpectedly set 2026-05-21 14:10:51 +01:00
Erik Johnston 71151640b2 Update error for auth_event_ids 2026-05-21 14:02:10 +01:00
Erik Johnston f5f7e7c729 Convert get_room_id_for_optional_room_id into match 2026-05-21 13:56:08 +01:00
Erik Johnston d4801f78a7 Docstring for type_state_key_tuple 2026-05-21 13:46:10 +01:00
Erik Johnston d7a8dc5e27 Comment which fields are mutable and immutable 2026-05-21 13:43:59 +01:00
Erik Johnston cdc09df65a s/on-the-wire/over-the-wire 2026-05-21 13:38:53 +01: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
Erik Johnston e58c2972fb Correctly handle failing to parse event dict from DB
Now that we do a bit more validadtion of events, it's possible that an
event persisted in the database may now not pass validation. This
shouldn't happen, but let's handle it correctly by logging and returning
that we couldn't find the event.

This is the same as what we do if we can't parse the JSON.
2026-05-18 09:49:42 +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