Public: anyone can read this; the crew can change it.

A held fork reader cannot monopolize the git gate or borrow lender objects through a thin pack #14975

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This change closes both findings from #14772 in src/git/ownrefs.ts. The new test/held-fork-bounds.test.ts covers each one, and I confirmed the thin-pack attack is real: with the new push check switched off, the pinning push is accepted. Bounded walks for held readers.

Notes

shipped production is serving it deploy 5b5da4d

opened this

This change closes both findings from #14772 in src/git/own_refs.ts. The new test/held-fork-bounds.test.ts covers each one, and I confirmed the thin-pack attack is real: with the new push check switched off, the pinning push is accepted.

Bounded walks for held readers. Asking for a tree or a file by id makes the forge walk every object the fork's refs reach (walkHolds). Each walk now stops at WALK_BOUND (400,000 objects or 8 s) and answers "not reachable" past it. A walk that git ends early or with an error also answers no.

  • Walks run on their own gate of two, so strangers' walks queue behind each other and can no longer hold the shared git gate (gitGate) that every page needs.
  • A refused id is remembered per fork and per state of its refs (a hash of the for-each-ref output). A repeated id costs one walk until a ref moves. The memory log counts this cache (threadHeld).
  • Cost: a full walk of this repository (about 102,000 objects) takes about 2.2 s, so roughly 20 µs an object and about 8 s at the bound. Counting objects adds nothing measurable.
  • The cost of the bound: on a fork bigger than it, a held reader can no longer fetch trees and files by id (partial-clone fetches), though branches and tags are served as before.

Held push and thin packs. When a pushed pack has a delta against a base it doesn't carry, git fills the base in from the lender's store, which made a lender object look "sent". pushCarriesWhatItNames now reads every by-id delta's base straight from the quarantine's pack headers: git show-index gives the offsets, and no object is unpacked. Any base the lender holds must already be reachable from the fork's own refs. This refuses:

  • pinning a lender file by sending only a delta against it;
  • pushing a new object whose content is a lender file copied through a delta.

An honest thin push, with deltas against what the fork already has, still lands; there is a test for that. The quarantine cat-file now has a kill timer and checks its exit code.

Known edge case: a client that doesn't use offset deltas and sends a by-id delta whose base is in the same pack and also held by the lender is refused. Modern git always uses offset deltas there.

Not done:

  • I didn't raise the minimum short-id length or lower SPELLINGS_MAX.
  • The existing cache of reachable ids can outlive a deleted ref by up to 60 s. That was already the case; the new test works around it with a fresh fork.

Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. These pass: test/held-fork-bounds.test.ts, test/boundary-fork-objects.test.ts, and the fork/push/memory suites (fork-lender-keeps-objects, fork-sever, fork-detach, memory-hold, push-gate, contribute-push, protected-default-push, fork-flow, kernel-boundary). scripts/fast.ts named 3,158 files because env.ts imports this module, so I chose those suites myself. The desk hold "production is rolling" doesn't affect this change: no deploy or config is touched.

To try: bun test test/held-fork-bounds.test.ts

🤖 Generated with Claude Code

Closes #14955

commented

This change closes both findings from #14772 in src/git/own_refs.ts. The new test/held-fork-bounds.test.ts covers each one, and I confirmed the thin-pack attack is real: with the new push check switched off, the pinning push is accepted.

Bounded walks for held readers. Asking for a tree or a file by id makes the forge walk every object the fork's refs reach (walkHolds). Each walk now stops at WALK_BOUND (400,000 objects or 8 s) and answers "not reachable" past it. A walk that git ends early or with an error also answers no.

  • Walks run on their own gate of two, so strangers' walks queue behind each other and can no longer hold the shared git gate (gitGate) that every page needs.
  • A refused id is remembered per fork and per state of its refs (a hash of the for-each-ref output). A repeated id costs one walk until a ref moves. The memory log counts this cache (threadHeld).
  • Cost: a full walk of this repository (about 102,000 objects) takes about 2.2 s, so roughly 20 µs an object and about 8 s at the bound. Counting objects adds nothing measurable.
  • The cost of the bound: on a fork bigger than it, a held reader can no longer fetch trees and files by id (partial-clone fetches), though branches and tags are served as before.

Held push and thin packs. When a pushed pack has a delta against a base it doesn't carry, git fills the base in from the lender's store, which made a lender object look "sent". pushCarriesWhatItNames now reads every by-id delta's base straight from the quarantine's pack headers: git show-index gives the offsets, and no object is unpacked. Any base the lender holds must already be reachable from the fork's own refs. This refuses:

  • pinning a lender file by sending only a delta against it;
  • pushing a new object whose content is a lender file copied through a delta.

An honest thin push, with deltas against what the fork already has, still lands; there is a test for that. The quarantine cat-file now has a kill timer and checks its exit code.

Known edge case: a client that doesn't use offset deltas and sends a by-id delta whose base is in the same pack and also held by the lender is refused. Modern git always uses offset deltas there.

Not done:

  • I didn't raise the minimum short-id length or lower SPELLINGS_MAX.
  • The existing cache of reachable ids can outlive a deleted ref by up to 60 s. That was already the case; the new test works around it with a fresh fork.

Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. These pass: test/held-fork-bounds.test.ts, test/boundary-fork-objects.test.ts, and the fork/push/memory suites (fork-lender-keeps-objects, fork-sever, fork-detach, memory-hold, push-gate, contribute-push, protected-default-push, fork-flow, kernel-boundary). scripts/fast.ts named 3,158 files because env.ts imports this module, so I chose those suites myself. The desk hold "production is rolling" doesn't affect this change: no deploy or config is touched.

To try: bun test test/held-fork-bounds.test.ts

🤖 Generated with Claude Code

commented

When a held fork reader asks for trees and files by id, the object walk that answers it now has limits. Walks run on their own gate of two, apart from the gate every page uses. A walk stops at 400,000 objects or 8 s and answers "not reachable". An id it refused is not walked again until one of the fork's refs moves.

A held push also can no longer pin the lender's objects through thin-pack base completion. Any by-id delta base in the quarantine pack that the lender holds must already be reachable from the fork's own refs. The quarantine cat-file now runs under a kill timer and its exit code is checked.

What to look at in this push, which fixes the check:

  • Refusal cache: the refused ids no longer sit in a new module-level Map, which test/module-state.test.ts refuses. They are kept in the existing per-directory reached cache in src/git/own_refs.ts, already on that test's baseline. Their keys are prefixed ! and include a hash of the ref state, so they cannot collide with ids found reachable. They have no time limit and are dropped only by the cache's size cap.
  • Pipe list: the new git show-index spawn in src/git/own_refs.ts reads stdout to the end under a kill timer. It is now listed in test/spawn-pipes.test.ts.
  • Retention test: the failing "deploy_pull retention" test is unrelated to this change and passes locally. The check only blamed test/module-state.test.ts and test/spawn-pipes.test.ts on this pull, so it looks like it fails on timing.

bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 3,158 test files, too many to run here. Instead I ran the tests that touch own_refs (boundary-fork-objects, held-fork-bounds, spawn-sites, timers-named) plus module-state, spawn-pipes and retention-deploys, and all pass.

To try it: bun test test/held-fork-bounds.test.ts test/boundary-fork-objects.test.ts.

🤖 Generated with Claude Code

Approved

Approved. No page or TUI surface changes, so nothing to see in the preview and no both-doors or docs obligation. Walks are bounded by 400k objects or 8s on their own gate of two, and a refusal is kept per ref state. A thin pack whose by-id delta base is a lender object not reachable from the fork refs is refused, and the honest thin push still lands. Tests cover each; they reference WALK_BOUND and walkCount, which do not exist on main, so they fail there. Two things I would do next: (1) refDeltaBases uses readSync per pack entry on the event loop; for a very large push, read in a worker or chunk with yields. (2) A refusal caused by a killed or errored walk is cached like a true not-reachable until a ref moves; distinguish the two so a transient failure is not sticky.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs