Skip to content

Specify basic validation for federation membership endpoints - #2284

Merged
richvdh merged 9 commits into
mainfrom
tulir/federation-membership-validation
Feb 24, 2026
Merged

Specify basic validation for federation membership endpoints#2284
richvdh merged 9 commits into
mainfrom
tulir/federation-membership-validation

Conversation

@tulir

@tulir tulir commented Dec 21, 2025

Copy link
Copy Markdown
Member

Signed-off-by: Tulir Asokan <tulir@maunium.net>
@tulir
tulir requested a review from a team as a code owner December 21, 2025 13:32
Comment thread data/api/server-server/invites-v1.yaml Outdated
}
"400":
description: |-
The `M_INVALID_PARAM` error code is used to indicate one or more of the following:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This error code is made up. Synapse seems to use M_UNKNOWN for most of the checks, but writing that into the spec wouldn't be very nice. It can be reworded to not use any specific error code if necessary

@timedoutuk timedoutuk Dec 24, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't M_BAD_JSON make sense? Hammerhead uses this

Request contained valid JSON, but it was malformed in some way, e.g. missing required keys, invalid values for keys.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, we do tend to use M_BAD_JSON for other things like this, for better or worse.

@richvdh richvdh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks very much for taking this on. It's certainly a valuable improvement.

I'm a bit concerned that putting the validation requirements way down in the "error codes" section buries the lede a bit, and that people aren't going to notice it. I'd be more inclined to put it in the endpoint description.

Similarly, I'd phrase it as "Servers MUST validate the following: ..." rather than "[error code] is used in the following situations: ...".

Comment thread data/api/server-server/invites-v1.yaml Outdated
@tulir

tulir commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

I'm a bit concerned that putting the validation requirements way down in the "error codes" section buries the lede a bit, and that people aren't going to notice it. I'd be more inclined to put it in the endpoint description.

Similarly, I'd phrase it as "Servers MUST validate the following: ..." rather than "[error code] is used in the following situations: ...".

The main reason for both points was that invites already had invite_room_state validation in the response spec rather than the endpoint description. Should I move that stuff as well?

@richvdh

richvdh commented Jan 13, 2026

Copy link
Copy Markdown
Member

I'm a bit concerned that putting the validation requirements way down in the "error codes" section buries the lede a bit, and that people aren't going to notice it. I'd be more inclined to put it in the endpoint description.
Similarly, I'd phrase it as "Servers MUST validate the following: ..." rather than "[error code] is used in the following situations: ...".

The main reason for both points was that invites already had invite_room_state validation in the response spec rather than the endpoint description. Should I move that stuff as well?

Ideally, I think so, yes, though at least in the case of invite_room_state we have a note on the request param that there is validation that must be done.

@tulir

tulir commented Feb 7, 2026

Copy link
Copy Markdown
Member Author

Added the validation for GHSA-m5p2-vccg-8c9v, moved all of it from the response schemas to the request description and switched to use M_MISSING_PARAM for all errors

@tulir
tulir requested a review from richvdh February 10, 2026 11:22
Comment thread changelogs/server_server/newsfragments/2284.clarification Outdated
Comment on lines +44 to +63
Servers MUST apply certain validation to ensure they don't accidentally sign non-invite
events from a malicious server. The `M_MISSING_PARAM` error code is used to indicate one
or more of the following:

* The invite event fails a [signature check](/server-server-api/#validating-hashes-and-signatures-on-received-events).
* The event type is not `m.room.member`.
* The `membership` field inside the event content is not `invite`.
* The event sender is not a user ID on the origin server.
* The `state_key` is not a user ID on the receiving server.

The `M_MISSING_PARAM` error code is also used to indicate one or more of the following
problems in the `invite_room_state` field:

* The `m.room.create` event is missing from `invite_room_state`.
* One or more entries in `invite_room_state` are not formatted according
to the room's version.
* One or more events fails a [signature check](/server-server-api/#validating-hashes-and-signatures-on-received-events).
* One or more events does not reside in the same room as the invite.
Note: Some room versions may require calculating the room ID for an
event rather than relying on the presence of `room_id`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like we've gone in the wrong direction here in terms of the error code. M_MISSING_PARAM seems like a terrible choice for param that isn't missing.

Can we update both halves to use something more sensible like M_INVALID_PARAM? Or just leave the precise error code unspecified here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we want it to match implementations, probably just need to leave it unspecified. I guess it might be fine to specify something even if implementations don't match right now? Servers shouldn't be trying to catch and handle these errors anyway

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Servers shouldn't be trying to catch and handle these errors anyway

Except that, in the section about response codes, the spec does mandate trying to catch these errors and handle them differently, at least in the case of /v2/invite/{roomId}/{eventId}: it says that errors should be passed through to the client, except for M_MISSING_PARAM which should be turned into a 500 error.

Ugh, I don't really know how best to proceed here. Certainly the best solution would be an MSC to clarify things, but that's a bunch of time and effort.

Maybe we can just get away with saying something like "errors which indicate a faulty request such as M_MISSING_PARAM and M_INVALID_PARAM should be turned into 500 errors", and then leaving the exact error code to be returned under specific circumstances unspecified for now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(or, leave the "response codes" section just talking about M_MISSING_PARAM, and if we decide we need better error handling, MSC the response codes later?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I made that case say both M_MISSING_PARAM and M_INVALID_PARAM should be hidden from clients, I guess the wording could be even more relaxed rather than specifying just 2 error codes

Comment thread data/api/server-server/joins-v2.yaml Outdated
The error should be passed through to clients so that they
may give better feedback to users.

If `M_MISSING_PARAM` is returned and the request is associated with a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The description for this endpoint specifies M_INVALID_PARAM for validation failures. Let's make sure they are consistent.

@richvdh richvdh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm. thanks.

@richvdh
richvdh merged commit 6b6d351 into main Feb 24, 2026
13 checks passed
@richvdh
richvdh deleted the tulir/federation-membership-validation branch February 24, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants