diff options
| author | tv <tv@krebsco.de> | 2026-11-19 14:13:39 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 15:18:52 +0100 |
| commit | 841897b79838f97a809356471baf2f41e186cdfa (patch) | |
| tree | 6fb5e0ac21b69986c87e8d87e87806ff514b451f /src/federation/client.rs | |
| parent | 27b76d5748f23a879d9fc82c725a58b514020ef9 (diff) | |
continuum-party: which places a proposal gives another writer
Rules go by first match, and `{party}` matches only the names of the
version's parties: admitting a party named as a segment of a place, or
changing the rules or their order, moves who writes the places below
it, and what their writer wrote there counts no more once the version
passes. Nothing said so: a proposal showed only its fields' changes.
`client::writers` names, of the places holding a value, those whose
writer a version changes, as `place: before -> after` (`nobody` where no
rule gives it one). `continuum-party proposals` prints them under each
proposal's changes (`who writes …`), and a fork's check does for the
fork's version (`writers` in POST /events/fork). The guides and
federation.md say so; row 72 is tested (`federation_attack_72`).
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] |
