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

A child's clone is refused when it carries objects/info/alternates pointing outside it #14930

Merged opened this

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

Merged

A child's own-code start is now refused before git clone runs if its forge repository borrows objects from a store outside the child's directory. Until now a local clone followed a child-written objects/info/alternates file, so it could copy a parent repository's objects into the child's cell.

Notes

shipped production is serving it deploy 5b5da4d

opened this

A child's own-code start is now refused before git clone runs if its forge repository borrows objects from a store outside the child's directory. Until now a local clone followed a child-written objects/info/alternates file, so it could copy a parent repository's objects into the child's cell. Closes the #14914 finding from #14770.

What changed (src/spawn/own_code.ts)

  • A new alternatesInside(repo, bound) check reads the repository's objects/info/alternates. Each entry must resolve, by realpath, inside the child's directory (<childDir>, three levels above repos/<org>/forge.git, the path ownRepoOf finds), and that store must contain no symbolic link.
  • It follows alternates of alternates up to five levels deep, as git does, and applies the same rules at each level.
  • Any entry in http-alternates is refused: it names stores by URL, which a realpath cannot place.
  • A quoted entry is refused rather than unquoted the way git would.
  • checkout runs the check after the size and symlink walk and before git clone. A refusal is recorded as the new rollback reason "its repository borrows objects from outside its forge", which is added to ROLLBACK_WORDS.

Tests (test/own-code.test.ts)

  • An alternates file naming a sibling repository in the parent's data is refused, the commit is marked failed, and no checkout is made. Without the change in src/ this test fails (received undefined).
  • Unit cases for alternatesInside that pass: an absolute or relative entry inside the child's directory, and comments.
  • Unit cases that are refused: a relative path that climbs out, a store inside the child's directory that itself borrows from outside, a symlink inside the child's directory pointing outside, a quoted entry, and http-alternates.

Not done

  • No --no-local fallback: the exact check made it unnecessary, and a non-local clone would still serve objects from the source's alternates anyway.
  • If the child rewrote its alternates between the check and the clone, it would slip through. That only matters if a child's files can change while its start is being prepared; I did not check whether they can.

Checks run: bun scripts/gate.ts --fix (its comment rewrap is included in the commit), bun x tsc --noEmit, and four suites covering own-code (own-code, spawn-cell-stays, boundary-tenancy-files, forge-code-own-source), all passing. scripts/fast.ts named 2,184 test files, too many to run here, so I picked those four myself. The full check runs on the push. This issue's keep_plan and estimate tools were not available in this run, so no plan was kept on the issue, and the #14770 box still needs ticking.

To try: bun test test/own-code.test.ts

🤖 Generated with Claude Code

Closes #14914

commented

A child's own-code start is now refused before git clone runs if its forge repository borrows objects from a store outside the child's directory. Until now a local clone followed a child-written objects/info/alternates file, so it could copy a parent repository's objects into the child's cell. Closes the #14914 finding from #14770.

What changed (src/spawn/own_code.ts)

  • A new alternatesInside(repo, bound) check reads the repository's objects/info/alternates. Each entry must resolve, by realpath, inside the child's directory (<childDir>, three levels above repos/<org>/forge.git, the path ownRepoOf finds), and that store must contain no symbolic link.
  • It follows alternates of alternates up to five levels deep, as git does, and applies the same rules at each level.
  • Any entry in http-alternates is refused: it names stores by URL, which a realpath cannot place.
  • A quoted entry is refused rather than unquoted the way git would.
  • checkout runs the check after the size and symlink walk and before git clone. A refusal is recorded as the new rollback reason "its repository borrows objects from outside its forge", which is added to ROLLBACK_WORDS.

Tests (test/own-code.test.ts)

  • An alternates file naming a sibling repository in the parent's data is refused, the commit is marked failed, and no checkout is made. Without the change in src/ this test fails (received undefined).
  • Unit cases for alternatesInside that pass: an absolute or relative entry inside the child's directory, and comments.
  • Unit cases that are refused: a relative path that climbs out, a store inside the child's directory that itself borrows from outside, a symlink inside the child's directory pointing outside, a quoted entry, and http-alternates.

Not done

  • No --no-local fallback: the exact check made it unnecessary, and a non-local clone would still serve objects from the source's alternates anyway.
  • If the child rewrote its alternates between the check and the clone, it would slip through. That only matters if a child's files can change while its start is being prepared; I did not check whether they can.

Checks run: bun scripts/gate.ts --fix (its comment rewrap is included in the commit), bun x tsc --noEmit, and four suites covering own-code (own-code, spawn-cell-stays, boundary-tenancy-files, forge-code-own-source), all passing. scripts/fast.ts named 2,184 test files, too many to run here, so I picked those four myself. The full check runs on the push. This issue's keep_plan and estimate tools were not available in this run, so no plan was kept on the issue, and the #14770 box still needs ticking.

To try: bun test test/own-code.test.ts

🤖 Generated with Claude Code

Approved

Approved. The check runs before git clone, follows nested alternates, refuses http-alternates and quoted entries, resolves symlinks by realpath, and records a worded rollback reason. The tests cover the sibling-repository case end to end and the unit edge cases. No web or TUI surface changes, so nothing to look at in the preview. Two things I would do next: (1) close the check-to-clone window, either by cloning from a snapshot the check read or by re-running alternatesInside immediately before the clone, and say whether child files can change during start; (2) add a one-line note to docs/features for own-code about the new rollback reason.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs