diff options
Diffstat (limited to 'src/federation/client.rs')
| -rw-r--r-- | src/federation/client.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/federation/client.rs b/src/federation/client.rs index 45f5019..f0c196f 100644 --- a/src/federation/client.rs +++ b/src/federation/client.rs @@ -481,6 +481,32 @@ pub(crate) fn changes(current: &Json, proposed: &Json) -> Vec<String> { lines } +/// Of `places`, the places holding a value, those whose writer the version `proposed` +/// changes of `current`, a line each, `place: before -> after`, `nobody` where no rule +/// gives it one: admitting a party named as a place's segment is, or changing the rules or +/// their order, moves who writes there, and what its writer wrote there counts no more +/// once `proposed` passes. +pub(crate) fn writers<'a>( + current: &Version, + proposed: &Version, + places: impl IntoIterator<Item = &'a str>, +) -> Vec<String> { + places + .into_iter() + .filter_map(|place| { + let path = super::version::path(place)?; + let (before, after) = (current.writer(&path), proposed.writer(&path)); + (before != after).then(|| { + format!( + "{place}: {} -> {}", + before.unwrap_or("nobody"), + after.unwrap_or("nobody") + ) + }) + }) + .collect() +} + /// Of the parties' nodes, those not known to know `revision`, by what the node a client /// talks to heard each say it knows (`knows` in `counts`, from `GET /events/counts`): a /// line for each party with any, naming them and what each said. Once a version of @@ -945,6 +971,39 @@ mod tests { ); } + /// Row 72 (`docs/federation.md`): a party admitted under the name of a place's segment + /// moves who writes there, rules unchanged, and so does a change of the rules' order; + /// the places it moves are named, the others left out. + #[test] + fn federation_attack_72() { + let (tv, lass, wiki) = ( + Party::new("tv", 1), + Party::new("lass", 2), + Party::new("wiki", 3), + ); + let rules = [ + ("names/{party}/**", harness::str("{party}")), + ("names/**", harness::str("tv")), + ]; + let read = |spec: Spec| Version::read(&spec.json()).unwrap(); + let current = read(Spec::first(&[&tv, &lass], &rules)); + let places = ["names/wiki/a", "names/lass/b", "names/other", "home/tv/c"]; + let admitted = read(Spec::first(&[&tv, &lass, &wiki], &rules)); + assert_eq!( + writers(¤t, &admitted, places), + ["names/wiki/a: tv -> wiki"] + ); + let reordered = read(Spec::first( + &[&tv, &lass], + &[rules[1].clone(), rules[0].clone()], + )); + assert_eq!( + writers(¤t, &reordered, places), + ["names/lass/b: lass -> tv"] + ); + assert!(writers(¤t, ¤t, places).is_empty()); + } + /// Of the nodes `knows` names, those that didn't say they know a revision are named, /// with what each said; a party whose nodes all did, not. #[test] |
