Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
fix(core): clean and cap the names other devices report
Bee617c5a58ff9a
diff --git a/core/nectarlink-core/src/pairing.rs b/core/nectarlink-core/src/pairing.rsindex f721af3..9a79a2d 100644--- a/core/nectarlink-core/src/pairing.rs+++ b/core/nectarlink-core/src/pairing.rs@@ -246,7 +246,7 @@ pub(crate) async fn join_qr(shared: &Arc<Shared>, uri: &PairingUri) -> Result<()send_env(&mut send, Envelope::new(types::PAIR_REQUEST, &PairRequest { device, proof })?).await?;let accept: PairAccept = recv_env(&mut recv, STEP_TIMEOUT).await?.expect_body(types::PAIR_ACCEPT)?;finish_initiator(&conn, send).await?;- Ok(accept.device)+ Ok(accept.device.sanitized())}.await;settle_initiator(shared, &conn, uri.id, result).await@@ -276,7 +276,7 @@ pub(crate) async fn start_nearby(shared: &Arc<Shared>, peer: DeviceId) -> Resultlet code = proto::sas_code(&n_a, &nonce.n_b, &shared.id, &peer);exchange_decisions(shared, peer, code, &mut send, &mut recv, Role::Initiator).await?;finish_initiator(&conn, send).await?;- Ok(nonce.device)+ Ok(nonce.device.sanitized())}.await;drop(nearby);@@ -400,7 +400,7 @@ async fn accept_qr(}shared.pairing.end_host();send_env(send, Envelope::new(types::PAIR_ACCEPT, &PairAccept { device: local_device(shared) })?).await?;- Ok(request.device)+ Ok(request.device.sanitized())}async fn accept_nearby(diff --git a/core/nectarlink-protocol/src/messages.rs b/core/nectarlink-protocol/src/messages.rsindex 02e6c06..6a81925 100644--- a/core/nectarlink-protocol/src/messages.rs+++ b/core/nectarlink-protocol/src/messages.rs@@ -344,8 +344,29 @@ pub struct DeviceInfo {pub install_id: Option<String>,}+/// A device's name or model, at most, in characters.+pub const MAX_DEVICE_NAME_CHARS: usize = 64;+/// A device's OS name or version, at most, in characters.+pub const MAX_DEVICE_OS_CHARS: usize = 32;++/// `text` without control characters or the invisible marks that reorder+/// text (a name could otherwise show reversed or disguised), cut to+/// `max_chars` and trimmed.+fn clean_device_text(text: &str, max_chars: usize) -> String {+ let is_direction_mark = |c: char| matches!(c, '\u{061C}' | '\u{200E}' | '\u{200F}' | '\u{202A}'..='\u{202E}' | '\u{2066}'..='\u{2069}');+ let clean: String =+ text.chars().filter(|c| !c.is_control() && !is_direction_mark(*c)).take(max_chars).collect();+ clean.trim().to_owned()+}+impl DeviceInfo {+ /// What another device says about itself, made safe to store and show.pub fn sanitized(mut self) -> Self {+ self.name = clean_device_text(&self.name, MAX_DEVICE_NAME_CHARS);+ self.os = clean_device_text(&self.os, MAX_DEVICE_OS_CHARS);+ self.os_ver = clean_device_text(&self.os_ver, MAX_DEVICE_OS_CHARS);+ self.model =+ self.model.map(|m| clean_device_text(&m, MAX_DEVICE_NAME_CHARS)).filter(|m| !m.is_empty());self.screen = self.screen.and_then(ScreenShape::sanitized);self.install_id = self.install_id.filter(|id| is_valid_install_id(id));self@@ -4160,6 +4181,24 @@ mod tests {}}+ #[test]+ fn device_names_are_cleaned_and_capped() {+ assert_eq!(info().sanitized(), info(), "ordinary info is unchanged");++ let mut dev = info();+ // A right-to-left override would show "Pixel\u{202E}gnp.exe" as "Pixelexe.png".+ dev.name = " Pixel\u{202E}gnp.exe\u{0007}\n ".into();+ dev.os_ver = "1".repeat(100);+ dev.model = Some("\u{2066}\u{2069}".into());+ let clean = dev.sanitized();+ assert_eq!(clean.name, "Pixelgnp.exe");+ assert_eq!(clean.os_ver.chars().count(), MAX_DEVICE_OS_CHARS);+ assert_eq!(clean.model, None);++ let long = DeviceInfo { name: "é".repeat(200), ..info() }.sanitized();+ assert_eq!(long.name.chars().count(), MAX_DEVICE_NAME_CHARS);+ }+#[test]fn screen_shape_and_battery_full_in_round_trip_and_sanitize() {let screen = ScreenShape {diff --git a/docs/protocol/v0.md b/docs/protocol/v0.mdindex 9f00c10..4d3ce9a 100644--- a/docs/protocol/v0.md+++ b/docs/protocol/v0.md@@ -125,11 +125,11 @@ b = {}DeviceInfo = {- name: text, // user-visible name, e.g. "Pixel 9"+ name: text, // user-visible name, e.g. "Pixel 9" (receivers keep 64 chars)kind: text, // "phone" | "tablet" | "desktop" | "laptop"- os: text, // "android" | "windows" | "macos"- os_ver: text, // "16" / "10.0.26200"- model: text?, // e.g. "Google Pixel 9"+ os: text, // "android" | "windows" | "macos" (32 chars)+ os_ver: text, // "16" / "10.0.26200" (32 chars)+ model: text?, // e.g. "Google Pixel 9" (64 chars)accent: uint?, // optional ARGB seed color (Material You sync)screen: ScreenShape?, // optional measured front-screen geometry (phones/tablets)}