From 50bc7cc00537e8fc486c3264147e6d9ee3b39bf5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 26 May 2024 16:39:51 -0400 Subject: [PATCH] check state_key matches sender user at /send_leave Signed-off-by: strawberry --- src/api/server_server.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/api/server_server.rs b/src/api/server_server.rs index a6325d60..73b51c8c 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -1540,6 +1540,22 @@ async fn create_leave_event(origin: &ServerName, room_id: &RoomId, pdu: &RawJson )); } + let state_key: OwnedUserId = serde_json::from_value( + value + .get("state_key") + .ok_or_else(|| Error::BadRequest(ErrorKind::InvalidParam, "PDU does not a state key"))? + .clone() + .into(), + ) + .map_err(|_| Error::BadRequest(ErrorKind::BadJson, "State key is invalid or not a user ID"))?; + + if state_key != sender { + return Err(Error::BadRequest( + ErrorKind::InvalidParam, + "State key does not match sender user", + )); + } + let origin: OwnedServerName = serde_json::from_value( serde_json::to_value( value