Specify basic validation for federation membership endpoints - #2284
Conversation
Signed-off-by: Tulir Asokan <tulir@maunium.net>
| } | ||
| "400": | ||
| description: |- | ||
| The `M_INVALID_PARAM` error code is used to indicate one or more of the following: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
yeah, we do tend to use M_BAD_JSON for other things like this, for better or worse.
richvdh
left a comment
There was a problem hiding this comment.
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: ...".
The main reason for both points was that invites already had |
Ideally, I think so, yes, though at least in the case of |
|
Added the validation for GHSA-m5p2-vccg-8c9v, moved all of it from the response schemas to the request description and switched to use |
| 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`. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
(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?)
There was a problem hiding this comment.
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
| 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 |
There was a problem hiding this comment.
The description for this endpoint specifies M_INVALID_PARAM for validation failures. Let's make sure they are consistent.
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Preview: https://pr2284--matrix-spec-previews.netlify.app