Skip to content

MSC4311: Use full PDU's in stripped state (like invite_room_state) over federation and always include m.room.create event#19723

Draft
MadLittleMods wants to merge 10 commits into
developfrom
madlittlemods/remove-flawed-msc4311-partial-implementation
Draft

MSC4311: Use full PDU's in stripped state (like invite_room_state) over federation and always include m.room.create event#19723
MadLittleMods wants to merge 10 commits into
developfrom
madlittlemods/remove-flawed-msc4311-partial-implementation

Conversation

@MadLittleMods
Copy link
Copy Markdown
Contributor

@MadLittleMods MadLittleMods commented Apr 23, 2026

Background

This PR was originally just trying to remove the flawed MSC4311 partial implementation as client side API's like /sync should still use stripped events. But it turns out we were just re-using the client logic for the federation side and things might break if we didn't include the full m.room.create event so this PR now introduces MSC4311 support to use full PDU's in the invite_room_state/knock_room_state in the federation API's.

The flawed implementation was originally introduced in 0eb7252 (no PR I assume because part of Hydra security fix)

Spawning from reviewing #19722 and noticing that we have TestMSC4311FullCreateEventOnStrippedState in Complement which already passes even though that test looks flawed:

I think this test is mixing up what MSC4311 proposes. Perhaps these were changes to the MSC that came after?

For the client API's like /sync, it only proposes that m.room.create is a required stripped state event.

For the federation API's, alongside requiring m.room.create, it also mandates using the full event PDU format for all events in the invite_room_state/knock_room_state on m.room.member events (in unsigned)

What does this PR do?

  1. Always use stripped state for client API's
    1. Remove flawed MSC4311 partial implementation (as explained above)
    2. Sanitize stripped state when we receive events over federation
  2. Use full PDU's when sending invite_room_state/knock_room_state over federation
  3. Validate PDU's and warn when receiving invite_room_state/knock_room_state over federation

Complement tests: matrix-org/complement#796


Part of #19414

Dev notes

COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh -run TestMSC4311FullEventsOnStrippedStateFederation
COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh -run TestMSC4311StrippedStateClientApi

Todo

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. 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 is correct (run the linters)

@MadLittleMods MadLittleMods changed the title Client side API's like /sync should still use stripped events with MSC4311 Remove flawed MSC4311 partial implementation: Client side API's like /sync should still use stripped events Apr 23, 2026
@MadLittleMods MadLittleMods changed the title Remove flawed MSC4311 partial implementation: Client side API's like /sync should still use stripped events Remove flawed MSC4311 partial implementation: Client-side API's like /sync should still use stripped events Apr 23, 2026
Comment thread synapse/events/utils.py
and event.get_state_key() == ""
):
return event.get_pdu_json()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the flawed MSC4311 partial implementation


return [strip_event(e) for e in state_to_include.values()]

async def get_stripped_room_state_ids_from_event_context(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split some logic out of get_stripped_room_state_from_event_context(...) into get_stripped_room_state_ids_from_event_context(...)

This way we can use the same event selection logic but fetch/format them however we see fit.

Comment on lines -515 to -516
# TODO(paul): assert that room_id/event_id parsed from path actually
# match those given in content
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as we actually do this now in FederationServer.on_invite_request(...)

@MadLittleMods MadLittleMods changed the title Remove flawed MSC4311 partial implementation: Client-side API's like /sync should still use stripped events MSC4311: Use full PDU's in stripped state (like invite_room_state) over federation and always include m.room.create event May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant