Fix invalid room ID check & prevent room IDs being prefixed with !
This commit is contained in:
parent
d3022b4112
commit
41581c9ae8
1 changed files with 13 additions and 5 deletions
|
@ -107,7 +107,6 @@ pub(crate) async fn create_room_route(
|
|||
|
||||
return Err!(Request(Forbidden("Publishing rooms to the room directory is not allowed")));
|
||||
}
|
||||
|
||||
let _short_id = services
|
||||
.rooms
|
||||
.short
|
||||
|
@ -615,17 +614,26 @@ fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<Own
|
|||
"Custom room ID contains an unexpected `:` which is not allowed.",
|
||||
));
|
||||
}
|
||||
} else if custom_room_id.starts_with('!'){
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Room ID is prefixed with !, but is not fully qualified. You likely did not want this."));
|
||||
} else {
|
||||
room_id = format!("!{custom_room_id}:{server_name}");
|
||||
}
|
||||
|
||||
OwnedRoomId::parse(room_id)
|
||||
.map_err(Into::into)
|
||||
.and_then(
|
||||
|full_room_id| {
|
||||
if full_room_id.server_name().expect("failed to extract server name from room ID") != server_name {
|
||||
Err(Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID must be on this server."))
|
||||
} else {
|
||||
Ok(full_room_id)
|
||||
}
|
||||
}
|
||||
)
|
||||
.inspect(|full_room_id| {
|
||||
debug_info!(?full_room_id, "Full custom room ID");
|
||||
if full_room_id.server_name().expect("failed to extract server name from room ID") != server_name {
|
||||
error!("Custom room ID does not match server name");
|
||||
}
|
||||
})
|
||||
.inspect_err(|e| warn!(?e, ?custom_room_id, "Failed to create room with custom room ID",))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue