Skip to content

Commit

Permalink
fix: Hide sensitive information from fmt::Debug for:
Browse files Browse the repository at this point in the history
- AuthRequest::LoginWithToken.token
- AuthResponse.key
- TraktInfo::access_token

Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Jan 25, 2024
1 parent 014572e commit cd437f6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/types/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl fmt::Debug for AuthRequest {
.finish(),
Self::LoginWithToken { token } => f
.debug_struct("LoginWithToken")
.field("token", token)
.field("token", &"<SENSITIVE>")
.finish(),
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/types/api/response.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt;

use crate::types::{
addon::Descriptor,
library::LibraryItem,
Expand Down Expand Up @@ -31,13 +33,22 @@ pub struct CollectionResponse {
pub last_modified: DateTime<Utc>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
pub struct AuthResponse {
#[serde(rename = "authKey")]
pub key: AuthKey,
pub user: User,
}

impl fmt::Debug for AuthResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AuthResponse")
.field("key", &"<SENSITIVE>")
.field("user", &self.user)
.finish()
}
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DataExportResponse {
Expand Down
13 changes: 12 additions & 1 deletion src/types/profile/user.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt;

#[cfg(test)]
use chrono::offset::TimeZone;
use chrono::serde::ts_seconds;
Expand All @@ -8,7 +10,7 @@ use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DefaultOnError, DefaultOnNull, DurationSeconds, NoneAsEmptyString};

#[serde_as]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(test, derive(Derivative))]
#[cfg_attr(test, derivative(Default))]
pub struct TraktInfo {
Expand All @@ -21,6 +23,15 @@ pub struct TraktInfo {
#[cfg_attr(test, derivative(Default(value = r#"String::from("token")"#)))]
pub access_token: String,
}
impl fmt::Debug for TraktInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TraktInfo")
.field("created_at", &self.created_at)
.field("expires_in", &self.expires_in)
.field("access_token", &"<SENSITIVE>")
.finish()
}
}

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[cfg_attr(test, derive(Default))]
Expand Down

0 comments on commit cd437f6

Please sign in to comment.