From 602eedc029e79ead1b9176cfa72c5ed5c4aed85c Mon Sep 17 00:00:00 2001 From: Edison Jwa Date: Thu, 11 Jun 2026 21:44:03 +0900 Subject: [PATCH] fix(protocol,bridge): wire nickname validation to connect (TODO-045) Add validate_nickname() to ProtocolClient::connect() and bridge connect(). Trim whitespace, reject empty, truncate to 30 chars. Re-export validate_nickname from protocol and core. --- core/chanora_core/src/lib.rs | 4 ++-- crates/chanora_bridge/src/api.rs | 2 ++ crates/chanora_protocol/src/adapter.rs | 11 ++++++----- crates/chanora_protocol/src/lib.rs | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/chanora_core/src/lib.rs b/core/chanora_core/src/lib.rs index f9d7eb3..8dbf4c8 100644 --- a/core/chanora_core/src/lib.rs +++ b/core/chanora_core/src/lib.rs @@ -68,8 +68,8 @@ pub use chanora_diagnostics::{ RedactingLogLayer, Redactor, DEFAULT_LOG_CAPACITY, }; pub use chanora_protocol::{ - ChannelInfo, ChatMessage, ClientInfo, ClientProfile, ConnectConfig, DisconnectReason, - MessageTarget, PokeStrength, ProtocolError, ServerActivity, ServerSnapshot, + validate_nickname, ChannelInfo, ChatMessage, ClientInfo, ClientProfile, ConnectConfig, + DisconnectReason, MessageTarget, PokeStrength, ProtocolError, ServerActivity, ServerSnapshot, }; pub use chanora_storage::{Bookmark, BookmarkRepository, IdentityFileStore}; pub use events::{ diff --git a/crates/chanora_bridge/src/api.rs b/crates/chanora_bridge/src/api.rs index fe0dae6..6668279 100644 --- a/crates/chanora_bridge/src/api.rs +++ b/crates/chanora_bridge/src/api.rs @@ -603,6 +603,8 @@ pub async fn connect( nickname: String, password: String, ) -> Result { + let nickname = chanora_core::validate_nickname(&nickname) + .map_err(|e| BridgeError::InvalidCommand(e.to_string()))?; let cfg = chanora_core::ConnectConfig { address: host, nickname, diff --git a/crates/chanora_protocol/src/adapter.rs b/crates/chanora_protocol/src/adapter.rs index d4c9b74..31b5087 100644 --- a/crates/chanora_protocol/src/adapter.rs +++ b/crates/chanora_protocol/src/adapter.rs @@ -40,8 +40,8 @@ use tsproto_packets::packets::{Direction, Flags, InAudioBuf, OutCommand, OutPack use tsproto_types::ClientType; use crate::dto::{ - ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile, MessageTarget, - ProtocolDelta, ServerActivity, ServerSnapshot, + validate_nickname, ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile, + MessageTarget, ProtocolDelta, ServerActivity, ServerSnapshot, }; use crate::poke_limiter::PokeLimiter; use crate::ProtocolError; @@ -324,9 +324,10 @@ impl ProtocolClient { if cfg.address.trim().is_empty() { return Err(ProtocolError::Invalid("address is empty".to_string())); } - if cfg.nickname.trim().is_empty() { - return Err(ProtocolError::Invalid("nickname is empty".to_string())); - } + let validated_nick = validate_nickname(&cfg.nickname) + .map_err(|e| ProtocolError::Invalid(e.to_string()))?; + let mut cfg = cfg; + cfg.nickname = validated_nick; let (tx, rx) = mpsc::channel::(8); let (voice_out_tx, voice_out_rx) = mpsc::channel::(64); diff --git a/crates/chanora_protocol/src/lib.rs b/crates/chanora_protocol/src/lib.rs index b150b76..cec56cb 100644 --- a/crates/chanora_protocol/src/lib.rs +++ b/crates/chanora_protocol/src/lib.rs @@ -40,8 +40,8 @@ pub mod poke_limiter; pub use adapter::{ConnectConfig, DisconnectReason, InboundVoice, ProtocolClient, SnapshotProbe}; pub use dto::{ - ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile, MessageTarget, - PokeStrength, ProtocolDelta, ServerActivity, ServerSnapshot, + validate_nickname, ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile, + MessageTarget, PokeStrength, ProtocolDelta, ServerActivity, ServerSnapshot, }; pub use poke_limiter::PokeLimiter;