Public: anyone can read this; the crew can change it.
A hosted forge's snapshot never follows a symlink swapped for a repository's parent directory #14978
Check · Review · Land · Live done — Landed and live in production.
A hosted forge can no longer get its host's snapshot to bundle a repository from outside the forge by swapping a parent directory for a symlink. Closes the deepsec finding in #14958. The gap: before this change, copyHosted checked only the last part of a repository's path.
shipped production is serving it deploy 15342fb
A hosted forge can no longer get its host's snapshot to bundle a repository from outside the forge by swapping a parent directory for a symlink. Closes the deepsec finding in #14958.
The gap: before this change, copyHosted checked only the last part of a repository's path. Directory listing used lstat and Dirent.isDirectory(), and the check after bundling ran lstat on repos/<owner>/<name>.git alone. A forge that was still running could swap repos/<owner> for a symlink to a directory outside itself after the listing. Git, which runs by path on the host outside the forge's cell, would then follow the link, and the result would be accepted as the forge's own repository.
The fix: a new notOwnDir(root, parts) in src/snapshot/hosted.ts runs lstat on each directory from the forge's root down to repos/<owner>/<name>.git; a link, or anything missing, fails. Because Bun has no openat, it then resolves the full path with realpath and requires it to equal the expected path inside the forge's root. That catches a directory swapped between the two looks.
It runs twice for each repository:
- Before bundling: a failure leaves the repository out with the reason
<path> is not a directory of its own inside its forge. - After bundling: a failure leaves it out with
it changed into something else while it was read: <path> …, so the manifest names the directory that moved.
Tests (in test/snapshot-hosted-inside.test.ts):
- An end-to-end snapshot whose
hostedGithook movesrepos/parentoutside the forge and leaves a symlink in its place as git starts. The manifest leavesparent/movedout, namesrepos/parent, and holds no bundle for it. This test fails against main'shosted.ts. - A unit test of
notOwnDir: a real path passes; a link or a missing directory higher on the path is named.
bun x tsc --noEmit passes, and the hosted snapshot and drill suites pass (62 tests, 0 failures). scripts/fast.ts named 2259 test files, too broad to run here, so I ran those suites myself. The gate script changed nothing.
Left out: the same pattern elsewhere in the copy (ssh/, history directories, app data). Those files are already opened with openInside, which checks the real path of the open file, so this change stays with the repository path named in the finding.
🤖 Generated with Claude Code
Each directory on repos/<owner>/<name>.git is lstat-ed from the forge root (itself realpathed), then the full realpath must equal the path; run before bundling and again after, naming the moved directory. The end-to-end test swaps repos/parent for a link and asserts the named refusal; the unit test covers a link and a missing directory. No UI, no dependency, nothing in README. Two things next: (1) apply the same per-directory check to the ssh/, history and apps/*/production/data walks, where only the opened file is checked today; (2) the realpath comparison is race-narrowing, not race-free (no openat in Bun): note that in docs, and consider running git with a cwd fd path if Bun ever allows.
A hosted forge can no longer get its host's snapshot to bundle a repository from outside the forge by swapping a parent directory for a symlink. Closes the deepsec finding in #14958.
The gap: before this change,
copyHostedchecked only the last part of a repository's path. Directory listing usedlstatandDirent.isDirectory(), and the check after bundling ranlstatonrepos/<owner>/<name>.gitalone. A forge that was still running could swaprepos/<owner>for a symlink to a directory outside itself after the listing. Git, which runs by path on the host outside the forge's cell, would then follow the link, and the result would be accepted as the forge's own repository.The fix: a new
notOwnDir(root, parts)insrc/snapshot/hosted.tsrunslstaton each directory from the forge's root down torepos/<owner>/<name>.git; a link, or anything missing, fails. Because Bun has noopenat, it then resolves the full path withrealpathand requires it to equal the expected path inside the forge's root. That catches a directory swapped between the two looks.It runs twice for each repository:
<path> is not a directory of its own inside its forge.it changed into something else while it was read: <path> …, so the manifest names the directory that moved.Tests (in
test/snapshot-hosted-inside.test.ts):hostedGithook movesrepos/parentoutside the forge and leaves a symlink in its place as git starts. The manifest leavesparent/movedout, namesrepos/parent, and holds no bundle for it. This test fails against main'shosted.ts.notOwnDir: a real path passes; a link or a missing directory higher on the path is named.bun x tsc --noEmitpasses, and the hosted snapshot and drill suites pass (62 tests, 0 failures).scripts/fast.tsnamed 2259 test files, too broad to run here, so I ran those suites myself. The gate script changed nothing.Left out: the same pattern elsewhere in the copy (
ssh/, history directories, app data). Those files are already opened withopenInside, which checks the real path of the open file, so this change stays with the repository path named in the finding.🤖 Generated with Claude Code
Closes #14958