Browse Source

fix: some edge-cases causing panics

- if servers don't send signatures, it could cause a panic
- clients sending invalid or non-canonical json could cause a panic
merge-requests/688/merge
Matthias Ahouansou 8 months ago
parent
commit
a7513cef7f
No known key found for this signature in database
  1. 20
      src/service/rooms/helpers/mod.rs
  2. 5
      src/service/rooms/timeline/mod.rs

20
src/service/rooms/helpers/mod.rs

@ -141,17 +141,17 @@ impl Service {
)); ));
} }
match signed_value["signatures"] match signed_value
.as_object() .get("signatures")
.ok_or(Error::BadRequest( .ok_or("server did not return any signatures")
ErrorKind::InvalidParam, .and_then(|signatures| {
"Server sent invalid signatures type", signatures
)) .as_object()
.ok_or("Server sent invalid signatures type")
})
.and_then(|e| { .and_then(|e| {
e.get(remote_server.as_str()).ok_or(Error::BadRequest( e.get(remote_server.as_str())
ErrorKind::InvalidParam, .ok_or("Server did not send its signature")
"Server did not send its signature",
))
}) { }) {
Ok(signature) => { Ok(signature) => {
join_event join_event

5
src/service/rooms/timeline/mod.rs

@ -783,8 +783,9 @@ impl Service {
} }
// Hash and sign // Hash and sign
let mut pdu_json = let mut pdu_json = utils::to_canonical_object(&pdu).map_err(|_| {
utils::to_canonical_object(&pdu).expect("event is valid, we just created it"); Error::BadRequest(ErrorKind::InvalidParam, "Event content provided is invalid")
})?;
pdu_json.remove("event_id"); pdu_json.remove("event_id");

Loading…
Cancel
Save