feat: Improve inbound federated membership handling #1952

Merged
ginger merged 16 commits from nex/fix/incoming-federated-invites into main 2026-07-12 02:11:51 +00:00
Owner

This pull request:

  • Begins strictly enforcing the additional validation specified on invites as part of spec v1.16
  • Persists create events received during invites to allow the re-introduction of the previously broken out-of-band membership handling (#1939)
  • Fixes a bug where stale room state could incorrectly prevent a valid invite being received due to ACLs
  • Extends the banned room server check to support v12+ rooms by using the create event sender instead of room ID server name when receiving an invite
  • Unified recv PDU validation into a few functions, rather than having a bunch of raw JSON operations scattered around everywhere

Depends on: #1944

Backwards incompatibility

The additional validation introduced by this PR will break receiving invites from any continuwuity version prior to this PRs' merge. This is because there is a bug in prior code that causes us to send absolute garbage in the invite and knock states, which wouldn't even pass more relaxed validation.

Pull request checklist:

  • This pull request targets the main branch, and the branch is named something other than
    main.
  • I have written an appropriate pull request title and my description is clear.
  • I understand I am responsible for the contents of this pull request.
  • I have followed the contributing guidelines:
This pull request: - Begins strictly enforcing the [additional validation specified on invites as part of spec v1.16](https://spec.matrix.org/v1.19/server-server-api/#put_matrixfederationv2inviteroomideventid) - Persists create events received during invites to allow the re-introduction of the previously broken out-of-band membership handling (#1939) - Fixes a bug where stale room state could incorrectly prevent a valid invite being received due to ACLs - Extends the banned room server check to support v12+ rooms by using the create event sender instead of room ID server name when receiving an invite - Unified recv PDU validation into a few functions, rather than having a bunch of raw JSON operations scattered around everywhere ~~Depends on: #1944~~ ## Backwards incompatibility The additional validation introduced by this PR will break receiving invites from any continuwuity version prior to this PRs' merge. This is because there is a bug in prior code that causes us to send absolute garbage in the invite and knock states, which wouldn't even pass more relaxed validation. **Pull request checklist:** <!-- You need to complete these before your PR can be considered. If you aren't sure about some, feel free to ask for clarification in #dev:continuwuity.org. --> - [x] This pull request targets the `main` branch, and the branch is named something other than `main`. - [x] I have written an appropriate pull request title and my description is clear. - [x] I understand I am responsible for the contents of this pull request. - I have followed the [contributing guidelines][c1]: - [x] My contribution follows the [code style][c2], if applicable. - [x] I ran [pre-commit checks][c1pc] before opening/drafting this pull request. - [x] I have [tested my contribution][c1t] (or proof-read it for documentation-only changes) myself, if applicable. This includes ensuring code compiles. - [x] My commit messages follow the [commit message format][c1cm] and are descriptive. <!-- Notes on these requirements: - While not required, we encourage you to sign your commits with GPG or SSH to attest the authenticity of your changes. - While we allow LLM-assisted contributions, we do not appreciate contributions that are low quality, which is typical of machine-generated contributions that have not had a lot of love and care from a human. Please do not open a PR if all you have done is asked ChatGPT to tidy up the codebase with a +-100,000 diff. - In the case of code style violations, reviewers may leave review comments/change requests indicating what the ideal change would look like. For example, a reviewer may suggest you lower a log level, or use `match` instead of `if/else` etc. - In the case of code style violations, pre-commit check failures, minor things like typos/spelling errors, and in some cases commit format violations, reviewers may modify your branch directly, typically by making changes and adding a commit. Particularly in the latter case, a reviewer may rebase your commits to squash "spammy" ones (like "fix", "fix", "actually fix"), and reword commit messages that don't satisfy the format. - Pull requests MUST pass the `Checks` CI workflows to be capable of being merged. This can only be bypassed in exceptional circumstances. If your CI flakes, let us know in matrix:r/dev:continuwuity.org. - Pull requests have to be based on the latest `main` commit before being merged. If the main branch changes while you're making your changes, you should make sure you rebase on main before opening a PR. Your branch will be rebased on main before it is merged if it has fallen behind. - We typically only do fast-forward merges, so your entire commit log will be included. Once in main, it's difficult to get out cleanly, so put on your best dress, smile for the cameras! --> [c1]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md [c2]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/docs/development/code_style.mdx [c1pc]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#pre-commit-checks [c1t]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#running-tests-locally [c1cm]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#commit-messages
nex added 19 commits 2026-07-11 06:44:11 +00:00
* Ignores any events pushed without a room ID
* Removes needless clones for PDU size checking
* Removes incorrect ACL check in incoming handler
* Fast-path handling already handled outlier events
* Remove redundant same-room checks, replace with useful ones
* Combine event rejection and persistence in a single function
* Additional safety assertions in upgrade task
* Split upgrade task into multiple subroutines for reduced cognitive complexity
* Only mutate current state and forward extremities in tandem
* Improve code documentation to better explain the logic flow
perf: Change signature of build_local_dag to remove refmap hacks
All checks were successful
Auto Labeler / Apply labels based on changed files (pull_request_target) Successful in 5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m24s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m11s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 11m7s
beed83855f
Tracking down weird soft-fails
fix: Invert boolean returned by policy server check
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m3s
Checks / Prek / Check changed files (pull_request) Successful in 4s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 54s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m54s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 5s
8688a66df7
fix: Address review feedback
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m21s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 2m10s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m52s
eb9a478f00
style: Accept event id reference in pdu_format_check_1
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m1s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m18s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m46s
4f7436a58f
These were introduced in spec v1.16 however we didn't implement them until now for compatibility.
fix: Only run ACL checks when we know we have live state
All checks were successful
Auto Labeler / Apply labels based on changed files (pull_request_target) Successful in 2s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m9s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 5s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 11m49s
c47db5952c
Prevents a potential bug where we might inadvertently reject valid invites because we have a stale state cache that blocks the sender or even ourselves

Also fixes the banned remote server room check by using the create event instead of room ID
fix: Remove redundant banned room server checks
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 5s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m8s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m59s
c901caa2c0
These don't make sense here anyway
nex changed title from feat: Improve inbound federated invite handling to feat: Improve inbound federated membership handling 2026-07-11 07:43:15 +00:00
nex requested review from Owners 2026-07-11 07:46:15 +00:00
Author
Owner

Needs testing

Needs testing
nex force-pushed nex/fix/incoming-federated-invites from c901caa2c0
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 5s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m8s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m59s
to 86e05ee627
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m0s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m55s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m9s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m33s
2026-07-11 16:29:17 +00:00
Compare
fix: Check correct field name when determining event type
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m5s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m13s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m3s
a0da5389e9
fix: Convert room summary to federation format when sending invites
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m4s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m10s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m44s
5cd68ee5b4
fix: Opportunistically re-use room format rules when parsing incoming PDUs
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 52s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m4s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
c22ef698b4
ginger added this to the 26.6.1 milestone 2026-07-11 19:21:08 +00:00
nex force-pushed nex/fix/incoming-federated-invites from c22ef698b4
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 52s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m4s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
to 7f104097d5
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m3s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m12s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m48s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 8s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
2026-07-11 19:23:43 +00:00
Compare
chore: Add newsfrag
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m1s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 1m6s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
7c1096746c
style: Fix EOL
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 9s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 54s
Documentation / Build and Deploy Documentation (pull_request) Successful in 54s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m57s
8225ed68ef
ginger requested changes 2026-07-11 19:39:29 +00:00
Dismissed
@ -24,3 +23,3 @@
use crate::Ruma;
use crate::{Ruma, server::utils::validate_any_membership_event};
/// helper method for /send_join v1 and v2
Owner

unhelpful docstring

unhelpful docstring
nex marked this conversation as resolved
@ -122,0 +109,4 @@
.await
.unwrap_or(RoomVersionId::V1)
.rules()
.unwrap(),
Owner

this will panic with no error message if the room ID doesn't exist

this will panic with no error message if the room ID doesn't exist
Author
Owner

It'll panic if the room version isn't recognised, although that should probably be an expect instead of an unwrap anyway

It'll panic if the room *version* isn't recognised, although that should probably be an expect instead of an unwrap anyway
nex marked this conversation as resolved
style: Make send_join's docstring more useful
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
Checks / Prek / Pre-commit & Formatting (pull_request) Has been cancelled
Documentation / Build and Deploy Documentation (pull_request) Has been cancelled
cee0482b67
nex force-pushed nex/fix/incoming-federated-invites from cee0482b67
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
Checks / Prek / Pre-commit & Formatting (pull_request) Has been cancelled
Documentation / Build and Deploy Documentation (pull_request) Has been cancelled
to b4a09a0ad0
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m4s
Checks / Prek / Check changed files (pull_request) Successful in 4s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m15s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m5s
2026-07-11 20:13:18 +00:00
Compare
nex force-pushed nex/fix/incoming-federated-invites from b4a09a0ad0
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m4s
Checks / Prek / Check changed files (pull_request) Successful in 4s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m15s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m5s
to 235a063338 2026-07-11 20:14:08 +00:00
Compare
ginger approved these changes 2026-07-12 02:04:01 +00:00
ginger merged commit 4001b99261 into main 2026-07-12 02:11:51 +00:00
ginger deleted branch nex/fix/incoming-federated-invites 2026-07-12 02:11:51 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Depends on
#1944 feat: PDU handler refresh
continuwuation/continuwuity
Reference
continuwuation/continuwuity!1952
No description provided.