Skip to content

Commit

Permalink
fix(base): Don't leak access and refresh tokens in Debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Oct 24, 2022
1 parent 6fd906d commit 85ec213
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 1 addition & 2 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ impl fmt::Debug for BaseClient {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Client")
.field("session_meta", &self.store.session_meta())
.field("session_tokens", &self.store.session_tokens)
.field("sync_token", &self.store.sync_token)
.finish()
.finish_non_exhaustive()
}
}

Expand Down
21 changes: 19 additions & 2 deletions crates/matrix-sdk-base/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

//! User sessions.
use std::fmt;

use ruma::{api::client::session::refresh_token, OwnedDeviceId, OwnedUserId};
use serde::{Deserialize, Serialize};

Expand All @@ -36,7 +38,7 @@ use serde::{Deserialize, Serialize};
///
/// assert_eq!(session.device_id.as_str(), "MYDEVICEID");
/// ```
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Session {
/// The access token used for this session.
pub access_token: String,
Expand Down Expand Up @@ -66,6 +68,15 @@ impl Session {
}
}

impl fmt::Debug for Session {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Session")
.field("user_id", &self.user_id)
.field("device_id", &self.device_id)
.finish_non_exhaustive()
}
}

impl From<ruma::api::client::session::login::v3::Response> for Session {
fn from(response: ruma::api::client::session::login::v3::Response) -> Self {
Self {
Expand All @@ -88,7 +99,7 @@ pub struct SessionMeta {

/// The mutable parts of the session: the access token and optional refresh
/// token.
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct SessionTokens {
/// The access token used for this session.
pub access_token: String,
Expand All @@ -107,3 +118,9 @@ impl SessionTokens {
}
}
}

impl fmt::Debug for SessionTokens {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SessionTokens").finish_non_exhaustive()
}
}

0 comments on commit 85ec213

Please sign in to comment.