From e519ade32a87811f287bb851e3e1dfcde6b064c9 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Nov 2026 22:23:15 +0000 Subject: screen: refuse changes Automerge wouldn't have written Automerge 0.12.0 applies a change that lists an actor none of its operations names, or whose first operation is numbered below its dependencies' or near 2^32. It then gives back another change than the one it was given and saves a document that doesn't load, or panics at the next write. A member sending one stops the nodes that take it. Every change from elsewhere is looked at before Automerge sees it (`document::changes::Written`, from `access::screen::apply`, with or without a policy), and refused like one breaking a rule unless: * encoded again, it has the hash it came with; * its first operation is numbered one after the highest of its dependencies, 1 without any, as a transaction at the document's heads numbers it; * every operation it names (an object, a list's element, an operation replaced) is its own, or was made before it, in the document or by a change of the batch looked at before. --- src/access/screen.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/access') diff --git a/src/access/screen.rs b/src/access/screen.rs index 8fd2c61..becf3bc 100644 --- a/src/access/screen.rs +++ b/src/access/screen.rs @@ -415,6 +415,8 @@ pub(crate) fn apply( // The values their users sign, under a strict policy, as the document holds them: // read again once the document takes the accepted (`reaches_signed`). let mut signed: Option>>> = None; + // What those looked at so far made (`changes::Written`). + let mut written = crate::document::changes::Written::default(); for (index, change) in ready.into_iter().enumerate() { let hash = change.hash(); let committer = committers[index].as_deref(); @@ -442,6 +444,12 @@ pub(crate) fn apply( .push(refuse(format!("it builds on refused change {dep}"))); continue; } + // None that Automerge writes: refused before Automerge sees it. + if let Some(why) = written.check(doc, &change, &decoded[index]) { + refused.insert(hash, hash); + screened.refused.push(refuse(why)); + continue; + } // Made under an actor whose change at its seq the document holds: forged, by // whoever brought it, not by the node the actor is. if signatures -- cgit v1.3.1