From 1b25e78e3ae6d60e73cea1c50af802cdf80045c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Mon, 30 Aug 2021 10:56:41 +0200 Subject: [PATCH] fix: inviting dendrite users --- src/client_server/membership.rs | 16 ++++++++++++++-- src/server_server.rs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index 29926e3b..0a7ca812 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -973,6 +973,14 @@ pub async fn invite_helper<'a>( (room_version_id, pdu_json, invite_room_state) }; + // Generate event id + let expected_event_id = EventId::try_from(&*format!( + "${}", + ruma::signatures::reference_hash(&pdu_json, &room_version_id) + .expect("ruma can calculate reference hashes") + )) + .expect("ruma's reference hashes are valid event ids"); + let response = db .sending .send_federation_request( @@ -980,9 +988,9 @@ pub async fn invite_helper<'a>( user_id.server_name(), create_invite::v2::Request { room_id: room_id.clone(), - event_id: ruma::event_id!("$receivingservershouldsetthis"), + event_id: expected_event_id.clone(), room_version: room_version_id, - event: PduEvent::convert_to_outgoing_federation_event(pdu_json), + event: PduEvent::convert_to_outgoing_federation_event(pdu_json.clone()), invite_room_state, }, ) @@ -1002,6 +1010,10 @@ pub async fn invite_helper<'a>( } }; + if expected_event_id != event_id { + warn!("Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}", user_id.server_name(), pdu_json, value); + } + let origin = serde_json::from_value::>( serde_json::to_value(value.get("origin").ok_or(Error::BadRequest( ErrorKind::InvalidParam, diff --git a/src/server_server.rs b/src/server_server.rs index 42d8185c..3682a493 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1526,7 +1526,7 @@ async fn upgrade_outlier_to_timeline_pdu( extremities, state_ids_compressed, soft_fail, - &state_lock + &state_lock, ) .map_err(|_| "Failed to add pdu to db.".to_owned())?;