Repository navigation
fix(serve): refuse rewinds, kind flips and dangling tips in pushed ref updates - #366
Merged
Merged
Conversation
UpdateRef checked only compare-and-swap; the fast-forward check lived in the pushing client, so any writer could rewind or sideways-move a served branch or point it at an absent object or a blob. LocalTransport and BucketTransport (so `sc serve --store` too) now refuse, under their own lock, a target that is not a held snapshot or manifest, and a move whose current tip is not an ancestor of the new one. A walk that hits an absent object fails closed.
Review of the server-side fast-forward check found it too weak. - A manifest's `base` counted as a parent, so a writer could move a public branch to a private manifest (and a snapshot could name a manifest as a parent). The ancestry rule is now per kind: snapshot parents must be snapshots, a manifest's ancestors are its `prev` chain only, and the new tip must have the same kind as the current one. - The walk stopped at the first parent equal to the current tip, so a commit with an absent second parent, root tree, nested blob or manifest closure entry landed and broke clone and fetch for the branch. New `ref_guard` module: a connectivity check like receive-pack's, covering only what the push added (it stops at existing ref tips and descends only into subtrees that differ from a parent's). - Local: the check runs before the repo-wide lock, from `expected_old`; under the lock only `current == expected_old` and the stopped-op guard remain. It reads a fresh store view, so an object `sc gc` pruned while a served session still cached it is not trusted. - Bucket: `PutPack` and `PutObject` refuse a record that decodes but is not in canonical encoding (the upload re-encodes, which stored it under an id it does not hash to). Pending objects keep decoded trees, snapshots and manifests so the check can walk what a push just uploaded. - THREAT-MODEL: drop the overclaims, describe the rules, and record that a keyless writer can still roll a private branch back under a new `prev`.
…nd check entry kinds Second review round on the server-side ref rule. - Local: the walk uses the session's store again (no per-push pack index reload) and records every object the verdict relied on. Under the repo lock, which gc also takes, each is confirmed to still be on disk (new `Store::contains_on_disk`: a loose-file stat, or an indexed pack that still exists; a miss rescans the pack directory once). A gc prune between the walk and the lock, or of an object a long-lived session still caches, now refuses the move instead of leaving a dangling ref. - A file entry's id was memoized in the same set as subtrees, so an id named as both a file and a directory skipped the subtree walk. Trees and leaves are memoized apart, a file entry must name a blob (or sealed object), and a tree entry must name a tree. - `LocalTransport::list_refs` goes through `refs::list_heads`, which skips a ref's in-flight temp file and tolerates a ref that vanishes while the directory is read.
…iles Third review round on the server-side ref rule. - A manifest closure entry or a snapshot secret was only checked for presence. A closure entry naming the public base made reachability mark it seen without walking it, so clone and gc could omit its tree. Closure entries must now be sealed objects and registry entries secrets. Entries a parent snapshot or the previous manifest already lists are inside its verified closure and are not read again. - The local walk now asks for an object's kind through `Store::peek_kind`, which reads the first encoded byte (loose or packed) instead of streaming the whole blob; `Object::kind_name_of_tag` maps the byte. Unchanged file entries in a changed directory were already skipped against the parent's tree; a counting test now pins that for files, secrets and closure entries. The bucket still decodes an on-chain object to learn its kind (its index has no kind), only for what the push changed. - `list_heads` hid any branch whose name contained ".tmp". Ref writes now use a dot-prefixed temp file (no branch name can start with a dot) and the listing skips only dot-prefixed entries.
…lock The unlocked walk stops at other branches' tips as already connected. If such a branch was removed or rewritten before the lock was taken and gc pruned its closure, the locked check (which only re-confirmed objects the walk read) could publish a dangling ref. `check_ref_move` now returns the tips the walk actually stopped at, and `commit_ref_move` requires each to still be the tip of some local branch (one `refs::list_heads` read under the lock) or refuses with the usual "retry the push" error. Bucket remotes: the manifest CAS the check read from is what the commit lands against, so those tips are still tips, and compaction never deletes what the chain names. The check skipped on a CAS retry is now reused only while the tips it trusted are still in the refreshed view.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
tonibergholm
approved these changes
Nov 20, 2026
tonibergholm
left a comment
Member
There was a problem hiding this comment.
Reviewed: sol-loop (5 rounds), Mythos security review of the final version (no blockers; its one finding applied), required checks green, Codex review has no findings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sc servetrusted the pushing client to enforce fast-forward.UpdateRefonly compared the old tip, so anyone with a read-write token, or on an open writable listener, could:The server's next
sc gcthen pruned the abandoned history. A served bucket (sc serve --store) had the same gap.The server now decides a ref move itself, through the new
ref_guard, on both the local and bucket paths:prevchain only.release.tmp-fix.Declined in review, with reasons:
Still open, recorded in the threat model: a keyless writer can roll a private branch back to an older manifest's content under a new
prev, because the index associated data does not bindprev.Proof:
ref_rules_holdruns on both transports and covers rewind, sideways move, kind flips, absent and wrong-kind targets, parents, roots, nested blobs, closure and secret entries. Every case failed with the check disabled. Further tests cover:an_object_pruned_between_the_walk_and_the_lock_refuses_the_move)a_trusted_tip_that_stops_being_a_tip_refuses_the_move)unchanged_content_is_not_read)cargo test -p scl-repo -p scl-clipasses (1228).Reviewed with sol-loop: 5 rounds with gpt-6.2-sol. Sol's last round found one should-fix, the boundary tips under the lock, which the last commit adds. A Mythos security review found the kind-flip and dangling-tip holes in round 1.
Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.