Require a visible matching UID for individual whisper recipients

This commit is contained in:
omar committed 2026-11-27 06:33:00 +03:00
1 parent 90c28eedbb
commit 8a98e3dcc6
4 files changed
+21 -3

No files matched your search

+15 -3
View File
@@ -509,7 +509,7 @@ pub fn resolve(spec: &TargetSpec, view: &View) -> Result<Route, ErrorObj> {
ENTRY_CHANNEL if e.uuid == view.server_uid => {
if let Some(channel) = view.find_channel_by_path(&e.name) {
ids.channel(channel);
for c in view.clients.iter().filter(|c| c.channel == channel) {
for c in view.clients.iter().filter(|c| c.channel == channel && c.uid.is_some_and(|uid| !uid.is_empty())) {
ids.client(c.id);
}
}
@@ -541,8 +541,8 @@ pub fn resolve(spec: &TargetSpec, view: &View) -> Result<Route, ErrorObj> {
TargetSpec::Ids { clients, channel_ids } => {
let mut ids = IdsBuilder::new();
for r in clients {
let expected = r.uid.as_deref().map(uid_bytes);
if view.client(r.id).is_some_and(|c| c.uid == expected.as_deref()) {
let Some(uid) = r.uid.as_deref().filter(|uid| !uid.is_empty()) else { continue };
if view.client(r.id).and_then(|c| c.uid).is_some_and(|current| current == uid_bytes(uid)) {
ids.client(r.id);
}
}
@@ -821,6 +821,18 @@ mod tests {
assert_eq!(resolve(&empty, &v).unwrap_err().detail, Some(json!({ "whisper": "no_targets" })));
}
#[test]
fn unidentified_clients_are_not_individual_whisper_targets() {
let mut v = view();
v.clients[2].uid = None; // Bob is the only occupant of Games.
v.clients[3].uid = Some(b"");
let clients = vec![ClientRef { id: 3, uid: None }, ClientRef { id: 4, uid: Some(String::new()) }];
let direct = TargetSpec::Ids { clients, channel_ids: vec![] };
assert_eq!(resolve(&direct, &v).unwrap_err(), no_targets());
let list = TargetSpec::List { entries: vec![Entry { kind: ENTRY_CHANNEL, uuid: SERVER.into(), name: "Games".into() }] };
assert_eq!(ids(&resolve(&list, &v).unwrap()), (vec![2], vec![]));
}
#[test]
fn too_many_resolved_targets_are_refused() {
let names: Vec<String> = (0..300).map(|i| format!("c{i}")).collect();