Merge pull request #883 from agorevski/fix/cleartext-logging-sensitive-data
fix(security): prevent cleartext logging of sensitive data
This commit is contained in:
commit
52dc9fd9e9
12 changed files with 112 additions and 79 deletions
|
|
@ -24,7 +24,7 @@ pub struct MatrixChannel {
|
|||
access_token: String,
|
||||
room_id: String,
|
||||
allowed_users: Vec<String>,
|
||||
session_user_id_hint: Option<String>,
|
||||
session_owner_hint: Option<String>,
|
||||
session_device_id_hint: Option<String>,
|
||||
resolved_room_id_cache: Arc<RwLock<Option<String>>>,
|
||||
sdk_client: Arc<OnceCell<MatrixSdkClient>>,
|
||||
|
|
@ -108,7 +108,7 @@ impl MatrixChannel {
|
|||
access_token: String,
|
||||
room_id: String,
|
||||
allowed_users: Vec<String>,
|
||||
user_id_hint: Option<String>,
|
||||
owner_hint: Option<String>,
|
||||
device_id_hint: Option<String>,
|
||||
) -> Self {
|
||||
let homeserver = homeserver.trim_end_matches('/').to_string();
|
||||
|
|
@ -125,7 +125,7 @@ impl MatrixChannel {
|
|||
access_token,
|
||||
room_id,
|
||||
allowed_users,
|
||||
session_user_id_hint: Self::normalize_optional_field(user_id_hint),
|
||||
session_owner_hint: Self::normalize_optional_field(owner_hint),
|
||||
session_device_id_hint: Self::normalize_optional_field(device_id_hint),
|
||||
resolved_room_id_cache: Arc::new(RwLock::new(None)),
|
||||
sdk_client: Arc::new(OnceCell::new()),
|
||||
|
|
@ -245,7 +245,7 @@ impl MatrixChannel {
|
|||
let whoami = match identity {
|
||||
Ok(whoami) => Some(whoami),
|
||||
Err(error) => {
|
||||
if self.session_user_id_hint.is_some() && self.session_device_id_hint.is_some()
|
||||
if self.session_owner_hint.is_some() && self.session_device_id_hint.is_some()
|
||||
{
|
||||
tracing::warn!(
|
||||
"Matrix whoami failed; falling back to configured session hints for E2EE session restore: {error}"
|
||||
|
|
@ -258,7 +258,7 @@ impl MatrixChannel {
|
|||
};
|
||||
|
||||
let resolved_user_id = if let Some(whoami) = whoami.as_ref() {
|
||||
if let Some(hinted) = self.session_user_id_hint.as_ref() {
|
||||
if let Some(hinted) = self.session_owner_hint.as_ref() {
|
||||
if hinted != &whoami.user_id {
|
||||
tracing::warn!(
|
||||
"Matrix configured user_id '{}' does not match whoami '{}'; using whoami.",
|
||||
|
|
@ -269,7 +269,7 @@ impl MatrixChannel {
|
|||
}
|
||||
whoami.user_id.clone()
|
||||
} else {
|
||||
self.session_user_id_hint.clone().ok_or_else(|| {
|
||||
self.session_owner_hint.clone().ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
"Matrix session restore requires user_id when whoami is unavailable"
|
||||
)
|
||||
|
|
@ -513,7 +513,7 @@ impl Channel for MatrixChannel {
|
|||
let my_user_id: OwnedUserId = match self.get_my_user_id().await {
|
||||
Ok(user_id) => user_id.parse()?,
|
||||
Err(error) => {
|
||||
if let Some(hinted) = self.session_user_id_hint.as_ref() {
|
||||
if let Some(hinted) = self.session_owner_hint.as_ref() {
|
||||
tracing::warn!(
|
||||
"Matrix whoami failed while resolving listener user_id; using configured user_id hint: {error}"
|
||||
);
|
||||
|
|
@ -714,7 +714,7 @@ mod tests {
|
|||
Some(" DEVICE123 ".to_string()),
|
||||
);
|
||||
|
||||
assert_eq!(ch.session_user_id_hint.as_deref(), Some("@bot:matrix.org"));
|
||||
assert_eq!(ch.session_owner_hint.as_deref(), Some("@bot:matrix.org"));
|
||||
assert_eq!(ch.session_device_id_hint.as_deref(), Some("DEVICE123"));
|
||||
}
|
||||
|
||||
|
|
@ -729,7 +729,7 @@ mod tests {
|
|||
Some("".to_string()),
|
||||
);
|
||||
|
||||
assert!(ch.session_user_id_hint.is_none());
|
||||
assert!(ch.session_owner_hint.is_none());
|
||||
assert!(ch.session_device_id_hint.is_none());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -600,12 +600,12 @@ impl TelegramChannel {
|
|||
let username = username_opt.unwrap_or("unknown");
|
||||
let normalized_username = Self::normalize_identity(username);
|
||||
|
||||
let user_id = message
|
||||
let sender_id = message
|
||||
.get("from")
|
||||
.and_then(|from| from.get("id"))
|
||||
.and_then(serde_json::Value::as_i64);
|
||||
let user_id_str = user_id.map(|id| id.to_string());
|
||||
let normalized_user_id = user_id_str.as_deref().map(Self::normalize_identity);
|
||||
let sender_id_str = sender_id.map(|id| id.to_string());
|
||||
let normalized_sender_id = sender_id_str.as_deref().map(Self::normalize_identity);
|
||||
|
||||
let chat_id = message
|
||||
.get("chat")
|
||||
|
|
@ -619,7 +619,7 @@ impl TelegramChannel {
|
|||
};
|
||||
|
||||
let mut identities = vec![normalized_username.as_str()];
|
||||
if let Some(ref id) = normalized_user_id {
|
||||
if let Some(ref id) = normalized_sender_id {
|
||||
identities.push(id.as_str());
|
||||
}
|
||||
|
||||
|
|
@ -631,7 +631,7 @@ impl TelegramChannel {
|
|||
if let Some(pairing) = self.pairing.as_ref() {
|
||||
match pairing.try_pair(code) {
|
||||
Ok(Some(_token)) => {
|
||||
let bind_identity = normalized_user_id.clone().or_else(|| {
|
||||
let bind_identity = normalized_sender_id.clone().or_else(|| {
|
||||
if normalized_username.is_empty() || normalized_username == "unknown" {
|
||||
None
|
||||
} else {
|
||||
|
|
@ -703,12 +703,12 @@ impl TelegramChannel {
|
|||
}
|
||||
|
||||
tracing::warn!(
|
||||
"Telegram: ignoring message from unauthorized user: username={username}, user_id={}. \
|
||||
"Telegram: ignoring message from unauthorized user: username={username}, sender_id={}. \
|
||||
Allowlist Telegram username (without '@') or numeric user ID.",
|
||||
user_id_str.as_deref().unwrap_or("unknown")
|
||||
sender_id_str.as_deref().unwrap_or("unknown")
|
||||
);
|
||||
|
||||
let suggested_identity = normalized_user_id
|
||||
let suggested_identity = normalized_sender_id
|
||||
.clone()
|
||||
.or_else(|| {
|
||||
if normalized_username.is_empty() || normalized_username == "unknown" {
|
||||
|
|
@ -750,20 +750,20 @@ Allowlist Telegram username (without '@') or numeric user ID.",
|
|||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
|
||||
let user_id = message
|
||||
let sender_id = message
|
||||
.get("from")
|
||||
.and_then(|from| from.get("id"))
|
||||
.and_then(serde_json::Value::as_i64)
|
||||
.map(|id| id.to_string());
|
||||
|
||||
let sender_identity = if username == "unknown" {
|
||||
user_id.clone().unwrap_or_else(|| "unknown".to_string())
|
||||
sender_id.clone().unwrap_or_else(|| "unknown".to_string())
|
||||
} else {
|
||||
username.clone()
|
||||
};
|
||||
|
||||
let mut identities = vec![username.as_str()];
|
||||
if let Some(id) = user_id.as_deref() {
|
||||
if let Some(id) = sender_id.as_deref() {
|
||||
identities.push(id);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue