REVIEW of #775 (4c1a37d70) and #779 (2710fe4f8, branch msch128/audit-wp4-media-merge) -- s
From mnema-talk v3.3.13, rendered on this site.
Status: COMPLETE (see the last line). Read-only; nothing edited, committed or pushed.
VERDICT SO FAR: #779 must not merge as it is (finding B1, liveness regression measured against #775). No confidentiality regression found. #775 on its own: clean (Part A below).
Evidence: the first reviewer's scratch tests survived in audit-run/review-779-scratch/ (zz*.test.ts, written against the real MediaGroup). I read them, re-ran them on 2710fe4f8 and on 4c1a37d70 in scratch worktrees and added two of my own (audit-run/review-779b-scratch/zzmine.test.ts, outputs *.txt next to it). Numbers below are from MY runs. node_modules: symlinked from the main checkout (web/package-lock.json is identical between main and 2710fe4f8), no npm ci.
FINDINGS
B1. BLOCKER (availability; no key is exposed) -- web/src/lib/media/groupMerge.ts:24-27 (lead), :45-58 (mergeOffer),
with group.ts:117-128 (receiveReturningMember) and groupSync.ts:40-56 (reachable)
1b offers to "the room's lowest reachable id" whenever my tree lacks it. Nothing requires that this id holds a group,
answers, or ever spoke MLS correctly. "Reachable" is: listed by the roster and either in my tree, or EVER sent one
handshake that parses (heard, never cleared), or first listed less than 8 s ago. And the offer is a key package from
a member INSIDE a group, which that group's own committer reads as a reload: it swaps the leaf (remove+add) in a
commit the offering member cannot follow (it refuses the welcome: not a rival, group larger than one). The member
is out of step with its own group until the next commit makes it start over; then it is welcomed back with a new
package, which it offers again on the next tick.
Scenario 1, no malice: the lowest id's tab hangs but stays listed (the case the absence limit and the hung-tab skip
exist for). Room of 3 formed normally, production timing (30 s tick, 20 min absence), engine start-over modelled:
#775: present members without a common key for 0 s of the following hour; 4 commits, 0 key packages.
#779: 1542 s of 3600 s; 83 commits, 171 key packages, 82 welcomes.
(First reviewer's larger runs on the same head: room of 12: 2314 s of 3600 s, 446 commits, 873 key packages.)
Scenario 2, one listed member: members 2..4 hold a group; id 1 is listed, sends ONE key package that is not even its
own (every receiver drops it) and stays silent. Production timing:
#775: 0 s of the following 30 min without a common key; 3 commits.
#779: 1599 s of 1800 s; 87 commits, 194 key packages. (Room of 8, first reviewer: 1781 s of 1800 s, five of seven
members end with no group.)
Trace (scenario 2, t in s): 90 m2 offers; 93 m3 offers -> m2 (its committer) commits remove+add for m3; 96 m4 offers
-> swap; m3 sees a commit ahead, starts over, is welcomed; m4 the same; ... repeats every tick for good.
So ANY listed id below the group (a hung tab, an old or broken client, a member who wants to) keeps the whole Talk
regrouping, without being in the group and without signing anything. At main/#775 such an id can do nothing: it must
be let in first, and only then can it misuse the committer role. This also makes SECURITY.md:707-712 false ("a
handshake that merely parses, a key package ... from an id outside the group never does [discard a group]").
Even with an honest newcomer there is a small window: a lower id is listed, and a member's tick falls before that
id's add commit: the member offers, is swapped out by its own committer and starts over at the add (one restart).
Suggested fix (all three, they are independent):
(a) The committer must not treat a merge offer as a reload. Cheapest: a member in a group does not broadcast a
package its own group would swap. E.g. the receiver ignores a non-identical package from a member of its tree
while the room lists a lower id outside the tree (it is a merge offer by construction), or the offer is marked.
(b) Offer only to an id that has shown it holds a group and commits in it, not to a merely listed one: e.g. only
after a welcome-capable sign from it (its own key package announcement is not one; a commit or welcome seen
from it under that id, or its group-of-one announcement, is closer). At the very least not within TAKEOVER_MS
of its first listing and not on heard alone.
(c) Give up: after k unanswered offers stop asking that id (doubling wait like rivals), so a dead lead costs a
bounded number of handshakes instead of one swap per member per tick forever.
Add both scenarios as tests (first reviewer's zzhung.test.ts / zzsilent.test.ts are ready to adapt).
B2. SHOULD-FIX -- web/src/lib/media/group.ts:137 (rivals.allow before the welcome is opened), groupMerge.ts:49
The once-per-minute allowance for a rival welcome is spent on ANY welcome from the lead, also one built on someone
else's package (the welcome goes to the whole room). In a split room the lead answers one offer, and that welcome
locks every other member of the higher group out for 60 s (they do not even ask: mergeOffer checks waitMs); the next
one doubles the wait for the rest (120, 240, 480, 600 s).
Measured (first reviewer's zzmerge.test.ts, production timing, honest relay; trace re-read by me, not re-run):
2+2 members: one group after 87 s; 2+4: 447 s (members merge at 36, 99, 222, 447 s); 6+6: 1527 s (25 min).
The PR text says "1b within one maintenance interval (30 s) plus the welcome"; that holds for the first member only.
Fix: check rivals.waitMs(from) > 0 before, and call rivals.allow(from) only after joinGroup succeeded and the
committer rule passed (the welcome was built on MY package and I am about to discard my group). The limit exists to
bound how often I drop a group, and a welcome that does not open drops nothing.
B3. SHOULD-FIX -- web/src/lib/media/group.ts:365-371 (beatNow), groupBase.ts:245 (discard clears beats),
groupMerge.ts:77-88; SECURITY.md:724-736
1c's replay guard is beats, which (i) records only heartbeats for MY epoch, never the two that made me start
over, and (ii) is emptied by discard() and is empty for a newcomer. So any two genuine heartbeats of the lowest id
signed with its current leaf key (the signature key does not change while its tab lives), for epochs other than
mine, can be sent again by the server:
- to a member that never took them (they were held back): first reviewer's R1, re-run: Carol starts over, is let in
again, and the same two wires make her start over again, three rounds out of three;
- to a NEWCOMER, with nothing ever held back (my N1): Alice sent h1 (t=6 s) and h2 (t=20 s) to Bob in the normal
way; Carol joins later; h1, then h2 8 s later -> Carol starts over ("none", offers a package), is let in again,
and the same two wires work again in every round (3 of 3). In a long call the server holds dozens of them.
Bound: the reset backoff only (10 s doubling to 60 s; back to 10 s whenever frames open). Server-only: a member
cannot send under the lowest id's name. The server can force a start-over at main as well (a commit for a later
epoch under the committer's id is taken unverified, same backoff), so this is no new capability and I rate it
should-fix, not blocker. But SECURITY.md's "a copy, an older one ... count for nothing; by holding back the commit
between two genuine ones it can make me start over" understates it: it needs to hold back nothing.
The PR's test "keeps its group when heartbeats it took in an earlier epoch are sent again" covers only the case
where beats still holds them.
Fix: keep the newest heartbeat time per signer key in a map that survives discard() (pruned when the id leaves the
room), raise it for other-epoch heartbeats too (both the first and the second), and refuse at <= it. For a
newcomer nothing local helps; either accept and document it, or refuse other-epoch heartbeats until one for my own
epoch from that leaf was taken (then "newer than" has a baseline).
B4. NOTE (the PR says it is closed; it is narrowed) -- groupSync.ts:255-262 (renewOwn is called only from joinFromWelcome), :177-185 (announceGroupOfOne) The init key is wiped after a JOIN. A member that founded keeps the package it founded with for as long as that group lives, and announces it. First reviewer's W1, re-run on the head: Carol answers Bob's announcement with a welcome that never arrives; Bob's group grows (Eve) and shrinks; an hour later Bob is alone and the hour-old welcome is delivered: Bob takes it and is at e2{2,3,4}, an epoch whose key the departed Dave held. Needs the server (or the welcome's sender, who gains nothing it could not do with a new welcome). Same as at main, so no regression, and Bob's next sync removes Dave. "A lone member re-founds before announcing" (task text) is not what the code does. Fix if wanted: a group that shrank to one re-founds with a new package before it announces again.
B5. NOTE -- groupMerge.ts:77-88
elsewhere (the first heartbeat) has no upper age: "two heartbeats at least 8 s apart", not "two in a row". A first
one that raced a renewal (lead signs for e, another member's renewal to e+1 reaches me first) stays armed for as
long as my state object stays the same. I found no honest ordering that delivers a second one without a real
split, so liveness only; an expiry of, say, 3 heartbeat periods would make the rule say what the text says.
ANSWERS
Q1. Confidentiality and acceptance: clean. Availability: finding B1.
- (Re)admission: the extra commit of #775 is
commit([])(group.ts:290-293): no add, nobody re-admitted, and its path secret is sealed to the current tree only. A1 re-run on both heads: the removed Carol gets nothing from the removal or the extra commit. 1b adds a member only through the lead's ordinary add of a listed id whose package the relay delivered; a removed member that is no longer listed failsroom.includes(from)(group.ts:136) as before. - Accepting a welcome or commit it would have refused: no. isRivalWelcome is strictly narrower (from < my committer instead of from < me, groupVet.ts:133-137; my committer <= me). Commit vetting is untouched. Single-use packages remove acceptances. conflictNow/switchConflictState (X5, X6) accept one thing more: after going back for a lower id's renewal the saved state is kept until CONFLICT_MS, so a still lower renewal or the committer's commit for that epoch can win once more; both are commits that verify against a state the member held less than 10 s ago and pass the same validator, so no new sender and no new content.
- Learning a key of an epoch it is not in: no path found. leafKeys are wiped in discard() and on the next renewOwn. Stale-lead case checked by reading: a lead that swaps me into an old tree removes everyone the roster no longer lists in the same commit (groupEpoch.ts:384-397), so a departed member's leaf does not survive into the epoch I join.
- Discard or replace its group: NEW, see B1 (any listed lower id, without doing anything authenticated, makes members lose their group again and again) and B3 (server, replay).
- What a malicious low-id MEMBER gains by 1b over main: (i) it receives my current package without having been in the Talk when I joined, and can welcome me into a group whose tree it built alone; at main it had to offer, be let in and then use the committer role (commit ahead) to get the same end state, so I agree with the PR that the end state is not new; (ii) NEW: it no longer has to be let in, or to answer at all, to disturb the room (B1). At main an id outside the group can do nothing to it.
- What a malicious SERVER gains by listing an id: at main it lists an id, offers a package under it and is added by the committer, or forces a start-over with a commit ahead. With 1b, listing an id below everyone (plus one parseable handshake under it, or simply for the first 8 s) makes every member publish a package and get swapped by its own committer; with 1c it can replay heartbeats (B3). Same end states as before (server can stall the call and can pull members into a group of its own making, visible in the member list), so the documented line "active server out of scope" does not move for confidentiality. It gets cheaper and quieter for availability.
- Does 1b/1c move the line for the SERVER: no. For a MEMBER/any listed id: yes, B1.
Q2. 1c forgeability and replay.
- Forgery: no. Ed25519 under the leaf key in my tree over domain, group id, sender id, epoch, time (heartbeat.ts:17-25,
47-59);
frommust be the lowest reachable id below me (groupMerge.ts:79). - Replay: yes, see B3 (old ones never taken; any old ones to a newcomer; again after every start-over). Same wire twice, wrong order, two within 8 s of signed time or of my clock: refused (PR tests, read; R1/N1 use >= 8 s).
- From a previous call / another Talk: no. The signed bytes hold the group id (derived from the channel id), and a MediaGroup makes a new leaf key per open, so a heartbeat from another Talk or from before the lead's reload does not verify. From a previous EPOCH of the same lead tab: yes, that is B3 (the leaf signature key is stable).
- "Increasing time" is the SENDER's claimed time (lastBeatAt, groupEpoch.ts:216-218), never compared with my clock; my clock only enforces the 8 s between first and second. An honest lead with a wrong or jumping clock cannot trigger 1c by that alone (the epoch must differ). A malicious lead can sign for any epoch: first reviewer's R2, re-run: one wrong-epoch heartbeat every 9 s for 600 s -> Carol starts over 11 times (29, 47, 74, 119, 182, then every 63 s). Bound: resets backoff. It is the committer and can do the same with a commit ahead at main; no gain.
Q3. 1b flapping, the per-sender limit, package freshness.
- Two honest groups pulling members back and forth: no. A welcome replaces a group only from an id below my group's committer and outside my tree, so members move downwards only, and the lead's group never offers (lead() is null for the lowest id; PR test "the lowest id itself offers nobody anything", read). What does flap is a member and its OWN group (B1), which is not bounded by anything but the swap and reset backoffs.
- Once per minute per sender across restarts:
rivalsis a field of the MediaGroup and is not reset by discard(), so it holds across start-overs of the group; it does not hold across a page reload (a new MediaGroup), as before. It is spent on welcomes that were not built on my package (B2), which hurts the honest case, not safety. - Freshness: after a join the package is replaced (renewOwn), after a start-over too (rekey), and an offer that brought no welcome for 60 s is replaced (groupMerge.ts:52-55). A second copy of a welcome that was taken opens nothing (K1 re-run: "the first welcome again at bob" changes nothing; PR test in group.welcomes.test.ts, read). Not fresh: the package of a member that FOUNDED and never joined (B4); its merge offer and its group-of-one announcement are that founding package, and a welcome built on it that was never taken stays valid.
Q4. SECURITY.md. Touched sentences that do not match the code:
- :724-736 "a copy, an older one or two in the wrong order count for nothing; by holding back the commit between two genuine ones it can make me start over": an older pair does count for a newcomer and after every start-over, and nothing has to be held back (B3).
- :716-722 "Two groups in one Talk become one in the group of the room's lowest id: a member whose group lacks that id offers it a key package on its maintenance tick, as a newcomer would": not as a newcomer would. Its own committer swaps its leaf on that offer, and the id need not hold a group at all (B1). The cost is not stated.
- :713-716 "A key package is good for one join ... a second copy of that welcome opens nothing": true as worded; it does not say that a welcome never taken, built on the package a member founded with, stays good (B4). Untouched sentence now false:
- :707-712 "Only authenticated input discards a group: a handshake that merely parses, a key package, or a public message from an id outside the group never does". With 1b one parseable handshake from a listed lower id (or just being listed, for 8 s) makes members offer, be swapped and start over (B1). Touched and correct (checked against the code): the welcome rule "lower than the member who commits in my group" (groupVet.ts:133-137, group.ts:133); the 1c conditions (signed time AND my clock, 8 s, unchanged group, reset limit: groupMerge.ts:77-88); "is no sign of life" (group.ts:371 returns before alive.set); "and once more if a still better one follows" (group.ts:296-316); #775's sentences on the late rival renewal and the extra commit (group.ts:265-293), and the group-of-one clause (review note 7).
Q5. Liveness and load.
- Split room of 12 (6+6), production timing, honest relay: one member merges per round and the rounds double (B2): about 25 min until one group (first reviewer's run, 1527 s; 6 key packages, 6 welcomes, 6 commits). Per member the offer rate is at most one key package per tick (30 s) and none while the rival wait runs, so the handshake rate of an HONEST split is low; it is slow, not loud.
- With a lead that does not answer the rate is not bounded by 1b itself (B1): room of 12, one hour: 873 key packages, 445 welcomes, 446 commits (first reviewer's run on this head); my room of 3: 171 / 82 / 83; my room of 4 with a silent listed id, 30 min: 194 / 87 / 87. #775 in the same runs: 0 key packages, 3 to 14 commits.
- Timers: 1b and 1c add no timer; the offer rides tickNow (tickTimer, cleared in discard and close),
askedandelsewhereare plain fields.elsewhereis not cleared by discard(); harmless, it compares the state object. - Reset backoff: 1c honours it (waitMs check, then recoverNow -> allow). When the backoff blocks, the first heartbeat stays armed and the next one after the wait fires. Swap backoff: is what throttles B1's swaps (3 s doubling to 60 s per member), and is the reason B1 settles at "one swap per member per minute" instead of per tick.
- Mixed rooms: an old lowest id adds whoever offers (fine). An OLD committer of the higher group treats a new client's merge offer as a reload and swaps it, like a new one does (B1 mechanics, by reading; the code path receiveReturningMember is unchanged from main). Old members of a group without the lead stay behind as the PR says. Not run as a mixed simulation.
Q6. Tests.
- #779 head,
vitest run src/lib/media --maxWorkers=2: 33 files passed; 354 passed, 8 expected failures, 49 skipped. - Moved gate seeds on #775's protocol files (group.ts, groupBase.ts, groupParams.ts, groupSync.ts, groupVet.ts from 4c1a37d70, groupMerge.ts removed, #779's tests): all eight fail (honest 37, 58, 357, 263; hostile 48, 59, 179, 182).
- Seeds 1..100: see the line appended below. The PR's skipped table lists for 1..100 hostile 18, 20, 31, 42, 64, 71, 73, 80, 82, 84, 97 and no honest seed; the first reviewer's run gave exactly that, all invariant 1.
- Not covered by any test or seed in the PR: a listed lower id that never joins (B1), a split of more than 1+1 members
on production timing (B2), replay to a member whose
beatsis empty (B3).
PART A: #775 at 4c1a37d70 since the first review
1 (should-fix) FIXED with option (ii), group.ts:272-293 (#779 numbering; same code at 4c1a37d70). Re-run on both heads, identical results:
- reviewer's ordering with the removed member as the renewer (A1): Alice removes Carol on Carol's renewal; Bob, on his own renewal, ignores Carol's (higher id) and cannot follow the removal: he stays at e3{1,2,3}. Bob's late renewal reaches Alice -> one empty commit@4; Bob sees a commit ahead, starts over at once, is let in: both e6{1,2}. Carol gets nothing from either commit.
- an add instead of a removal (A2): Bob and Carol on the rival branch both start over on the extra commit and are let in one after the other; Dave (added) follows the extra commit; all four end on one key.
- three renewals for one epoch (A3): ONE extra commit; the further late renewals (also sent twice) change nothing, because overtaken() drops the saved state. "Within seconds" holds unless the member on the rival branch started over in the last 10 to 60 s (recoverNow is silent while the reset backoff runs; the engine's 5 s rule or the next commit then does it). Unbounded extra commits: no. One per saved state, and a saved state exists only after the committer took a renewal, which each member may send twice per rotation period (mayUpdate) and which must be followed by a commit of the committer within 10 s and by a rival from a DIFFERENT, lower member. Worst case about 2 per member per 30 min, each an empty commit. A lone malicious member cannot be its own rival (from !== saved.sender). Re-admission or a revealed key: no; the extra commit is commit([]) on the committer's current tree. 2 (should-fix) FIXED: groupSimChecks.fixture.ts checkStep: a commit must lead one epoch on (or, for the one rollback case, from epoch-1 to the same epoch), and every member new after it must be added by it. A rollback that re-admits anyone fails on the second rule whoever sent the renewal. The committer's own extra commit is exempted only for "same members, one epoch on" (answeredLate). Strict enough for the question asked. By reading; the PR's groupSimChecks.test.ts passes in the suite run. 3 (should-fix) FIXED: keyPackage() marks "restarting" only for a package whose signature key differs from the leaf. 4 (note) FIXED: joinFromWelcome and processCommit drop the saved state when another commit or a welcome is adopted. 6 (note) FIXED: foundingWait starts the wait at the offer that goes out now (resend or changed room). 7 (note) FIXED: SECURITY.md names the group-of-one exception, roster change or tick. 8 (note) FIXED: the stray blank line is gone. #775 alone: nothing new found.
NOT DONE: mixed old/new rooms were not simulated; the 1..400 table and the 900 s / 150 s variants in the PR text were not re-run; first reviewer's 6+6 and room-of-12 runs were read, not repeated (I repeated the small rooms).
Seeds 1..100 on 2710fe4f8, MY run: SUMMARY hostile 1..100: failing 11 [18, 20, 31, 42, 64, 71, 73, 80, 82, 84, 97] non-invariant-1: [] SUMMARY honest 1..100: failing 0 [] non-invariant-1: [] Status: COMPLETE.