From 5158dbf2eb5881ae7d866fdc88759ec51b50f488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 6 Nov 2022 14:05:50 +0100 Subject: [PATCH] events: Don't include sensitive data in Debug-format of to-device events --- crates/ruma-common/CHANGELOG.md | 2 ++ .../ruma-common/src/events/key/verification/start.rs | 10 ++++++++-- crates/ruma-common/src/events/secret/send.rs | 12 +++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index de8fcbb8..ff9edb11 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -4,6 +4,8 @@ Bug fixes: * HTML-relevant characters (`<`, `>`, etc) in plaintext replies are now escaped during creation of the rich reply +* Don't include sensitive information in `Debug`-format of types from the `events::key` + and `events::secret` modules Breaking changes: diff --git a/crates/ruma-common/src/events/key/verification/start.rs b/crates/ruma-common/src/events/key/verification/start.rs index 97c66e0b..a711619f 100644 --- a/crates/ruma-common/src/events/key/verification/start.rs +++ b/crates/ruma-common/src/events/key/verification/start.rs @@ -2,7 +2,7 @@ //! //! [`m.key.verification.start`]: https://spec.matrix.org/v1.4/client-server-api/#mkeyverificationstart -use std::collections::BTreeMap; +use std::{collections::BTreeMap, fmt}; use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; @@ -109,7 +109,7 @@ pub struct _CustomContent { } /// The payload of an `m.key.verification.start` event using the `m.sas.v1` method. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(rename = "m.reciprocate.v1", tag = "method")] pub struct ReciprocateV1Content { @@ -126,6 +126,12 @@ impl ReciprocateV1Content { } } +impl fmt::Debug for ReciprocateV1Content { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ReciprocateV1Content").finish_non_exhaustive() + } +} + /// The payload of an `m.key.verification.start` event using the `m.sas.v1` method. /// /// To create an instance of this type, first create a `SasV1ContentInit` and convert it via diff --git a/crates/ruma-common/src/events/secret/send.rs b/crates/ruma-common/src/events/secret/send.rs index 3573562e..6d2d9037 100644 --- a/crates/ruma-common/src/events/secret/send.rs +++ b/crates/ruma-common/src/events/secret/send.rs @@ -2,6 +2,8 @@ //! //! [`m.secret.send`]: https://spec.matrix.org/v1.4/client-server-api/#msecretsend +use std::fmt; + use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; @@ -13,7 +15,7 @@ use crate::OwnedTransactionId; /// `m.secret.request` event. /// /// It must be encrypted as an `m.room.encrypted` event, then sent as a to-device event. -#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +#[derive(Clone, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[ruma_event(type = "m.secret.send", kind = ToDevice)] pub struct ToDeviceSecretSendEventContent { @@ -30,3 +32,11 @@ impl ToDeviceSecretSendEventContent { Self { request_id, secret } } } + +impl fmt::Debug for ToDeviceSecretSendEventContent { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ToDeviceSecretSendEventContent") + .field("request_id", &self.request_id) + .finish_non_exhaustive() + } +}