Repository navigation
fix(identity): probe volume case sensitivity instead of trusting the platform (#109) - #250
Conversation
…platform (#109) normalizeDirPath folded path case on every darwin/win32 host, so two directories differing only in case on a case-SENSITIVE APFS volume (or an NTFS dir with per-directory sensitivity) hashed to one repo= key and read each other's rows. Replace the platform check with a probe: flip one cased character of the deepest existing component; the volume folds names itself only when the flipped spelling still names the same dev+inode. Undecided paths (nothing exists, no cased characters) keep the old platform rule. No re-stamp migration: rows written under the old fold carry repoPath (true spelling) and isVisibleTo already matches on it, so they stay visible to their own repo while the cross-case leak closes for them too. Tests pin the probe against an independent filesystem oracle and cover both volume types (verified on an insensitive boot volume and a case-sensitive APFS disk image).
6ec489d to
e079003
Compare
abogartz
left a comment
There was a problem hiding this comment.
Reviewed head e079003c87b29c4c55156a389c7069ea933d922d (diff key 96abfafe…0e0c).
Verdict: APPROVE — posted as a comment review because GitHub refuses an approve event on a PR authored by the same account (422 "Can not approve your own pull request", GraphQL and REST alike). No behavior defect found; a human can merge on this review.
Commands run (measured)
bun run typecheck— cleanbun run lint— 498 warnings, identical to the main baselinebun run test— 872 tests: 860 pass, 12 skip, 0 failbun run test:e2e— 30 pass, 0 fail (src/ changed)- CI: lint / test / test-windows / smoke all pass
Verification of the body's claims against the tree
- The compat story holds:
isVisibleTo(src/store/model/visibility.ts:73) already matchesm.repoPath === reader.scope.path, andappendMemorystampsrepoPathfromtarget.scope.path(src/store/files/append.ts:135). Old rows written under the platform fold therefore stay visible throughrepoPath, and on a case-sensitive volumerepoPathdistinguishes/x/Foofrom/x/foo, closing the leak for old rows too. - The compat test is non-trivial on every platform: the forged
oldKeydiffers from the new key on macOS (realpath adds/private) and on Linux (the fold lowercasedCompatProj), so the assertion genuinely exercises therepoPathpath, not a key collision. - Probe fails in the safe direction: folding happens only on a positive same-
dev+inoconfirmation; any stat error yields "no fold" — a key split, never a cross-project leak. - Parent walk terminates on POSIX, Windows drive, and UNC forms; index 0 is protected so a
C:drive letter never flips. - The oracle (
osi-case-oraclewrite + uppercaseexistsSync) is independent of the probe under test.
Findings
No P0/P1.
- nit — test/repokey-path.test.ts:214: the comment says
oldKeyis "exactly what the pre-fix normalizer stamped for this path on ANY platform", but the pre-fix normalizer applied realpath first, so on macOS the real pre-fix stamp carried the/privateprefix. The test's purpose (visibility viarepoPathwhen keys differ) is unaffected; the comment overstates. - nit — src/identity/repokey.ts:86:
flipLastCasedscans the whole path, so when the deepest existing component carries no case the probe answers for an ancestor's volume. If that case-free component were itself a mount point of a volume with different case semantics, the answer would be wrong. Contrived; the fallback direction stays safe.
Approving: the fix probes the filesystem instead of trusting the platform, the compat story is verified in the tree, and every check is green here and in CI.
WhollyMindless
left a comment
There was a problem hiding this comment.
Review findings at e079003c87b29c4c55156a389c7069ea933d922d, against main 8dd43e6edaf80381b3a06789142ac5f1645900d1. Recommendation: request changes for two reproduced repository-isolation gaps. Posting as a comment review; merge and scope decisions remain yours.
F1 — new regression: a case-variant symlink is mistaken for filesystem case folding
Location: src/identity/repokey.ts:115–117 (alternate spelling + statSync inode comparison), followed by whole-path lowercasing in normalizeDirPath.
On a real case-sensitive filesystem, create distinct directories Foo and foo, then a symlink FoO -> Foo. The last-character flip of Foo is FoO. Because statSync follows the link, it sees the same inode and returns true, even though Foo and foo are distinct repositories. Under an all-lowercase ancestor path, both resolve to the same key. A memory written for Foo is then retrieved by relevantKnowledge() from foo.
Differential: the same actual-write/retrieval probe passes on main (separate keys, no foreign content) and fails on this head (same keys, foreign content returned). No filesystem mocks. This also contradicts the existing review's statement that the probe can only fail toward a safe key split: same-inode lookup through a symlink is a false positive.
Suggested acceptance: the alternate spelling must not establish case-insensitivity merely by following an alias. Pin two distinct real directories plus a case-variant symlink, and verify the foreign row is excluded. More broadly, one component's result should not justify folding case-sensitive ancestor components. I have not independently exercised mixed-volume or per-directory NTFS configurations here.
F2 — pre-existing gap left open: legacy folded keys still authorize the lowercase sibling
Location: new compatibility test in test/repokey-path.test.ts and unchanged isVisibleTo / evidenceVisibleTo in src/store/model/visibility.ts.
For /tmp/<all-lowercase-parent>/Foo, an old win32/darwin-style stamp is sha1(lowercase(realpath(Foo))), with repoPath retaining Foo. That old key equals the new path key of the distinct lowercase sibling foo. The predicate is:
m.repo === reader.scope.key || (!!m.repoPath && m.repoPath === reader.scope.path)So the matching key grants access before the conflicting repoPath can distinguish the repositories. I seeded that exact legacy stamp, verified that the owner still retrieved it, then switched to foo: actual relevantKnowledge() returned the private row there too. evidenceVisibleTo accepts the equivalent evidence stamp as well.
This is pre-existing, not a new regression: the negative isolation assertion fails on both base and head. But it means the PR body's claim that the cross-case leak closes for old rows is not yet true. The new compat test proves continued owner access only; it needs the negative sibling check too. A safe compatibility policy must distinguish legacy path-derived identities without breaking intentional shared-origin identity; simply rejecting all differing repoPath values would be too broad.
Reproducer and validation
The essential filesystem setup is below. The all-lowercase ancestor matters: use a lowercase UUID, not an unconstrained mkdtemp suffix whose uppercase letters can mask these collisions.
// Run on a case-sensitive filesystem, from the repository root with Bun.
import { mkdirSync, symlinkSync } from "node:fs";
import { createHash } from "node:crypto";
import { resolveRepo } from "./src/identity/repokey.ts";
import { isVisibleTo } from "./src/store/model/visibility.ts";
const root = `/tmp/osi250-${crypto.randomUUID()}`;
mkdirSync(root);
mkdirSync(`${root}/Foo`);
mkdirSync(`${root}/foo`);
const lower = resolveRepo(`${root}/foo`);
const oldKey = createHash("sha1")
.update(`${root}/Foo`.toLowerCase()).digest("hex").slice(0, 12);
console.log("F2: foreign legacy row visible", isVisibleTo(
{ repo: oldKey, repoPath: `${root}/Foo` },
{ kind: "repo", scope: lower },
)); // true, should be false
// Resolve Foo only AFTER creating the alias: otherwise the probe cache masks F1.
symlinkSync(`${root}/Foo`, `${root}/FoO`);
const upper = resolveRepo(`${root}/Foo`);
console.log("F1: distinct repositories collide", upper.key === lower.key);
// true on this head, false on baseValidation: Bun 1.4.4; existing repokey-path.test.ts passes all nine tests on both Windows and WSL Linux. The stronger external probes use appendMemory() plus relevantKnowledge() against throwaway stores: both isolation assertions fail at the PR head; only the legacy assertion fails on base. Those probes and logs are preserved locally. Hosted checks remain green. I did not rerun the full suite/E2E or test a live macOS APFS volume; the old-platform stamp was synthesized on real case-sensitive WSL Linux. No production changes made.
|
Offered an F1-only companion PR: #251, based directly on this branch at e079003 and targeting It checks the exact case-flipped component with lstat, rejecting a symlink there, including when an uncased numeric child follows it. Genuine input aliases still canonicalize to their targets. Both new regressions fail on your current head and pass with the fix on case-sensitive WSL Linux; the full Windows merge gate also passes, including all 30 E2E tests. Validation details and platform limits are in #251. F2 is unchanged and remains a separate compatibility-policy finding. Please feel free to merge, cherry-pick, adapt, defer, or reject the companion PR — it is an optional contribution, not a request to surrender ownership of this work. |
There was a problem hiding this comment.
Head reviewed: e079003c87b29c4c55156a389c7069ea933d922d
Contract: closingIssuesReferences is empty — this PR does not formally close #109 (title references it; body never says Closes). Per reviewer policy that means a merits review posted as a comment; no approval from me. #109 is human-authored (abogartz), so the blocker is the missing Closes #109 footer, not bot provenance.
Contract as stated by #109 (quoted): "A case-sensitive APFS volume is a legitimate macOS choice. There, Foo and foo really are two directories, but they now hash to one repo= key … Silent cross-project visibility."
Verdict: the fix works, measured on a real case-sensitive volume
I built the differential rather than trusting the PR body:
hdiutil create -fs "Case-sensitive APFS" -volname OSI109CS— confirmed sensitive (probecreated,PROBE→No such file or directory).- Fixed side (this head),
TMPDIR=/Volumes/OSI109CS bun test test/repokey-path.test.ts→ 9 pass / 0 fail. - Broken side (same head, one line reverted to the pre-fix platform rule
const fold = process.platform === "win32" || process.platform === "darwin") → 2 fail for exactly the stated reason:normalizeDirPathlowercased on a case-sensitive volume:Expected to contain: "MixedCase" / Received: "/volumes/osi109cs/…/mixedcase"(test/repokey-path.test.ts:174)- two real dirs differing only by case shared one key:
Expected: not "9a5f0c64acad"(test/repokey-path.test.ts:195) — the leak #109 describes, reproduced and closed.
Commands run (measured)
| command | result |
|---|---|
bun run typecheck |
clean |
bun run lint |
498 warnings = baseline, no new |
bun run test |
872 tests, 860 pass, 12 skip, 0 fail |
bun run test:e2e |
30 pass, 0 fail (src/ changed) |
gh pr checks 250 |
lint / test / test-windows / smoke all pass |
| case-sensitive volume, this head | 9/9 pass |
| case-sensitive volume, fold reverted | 2 fail (above) |
Test-quality audit
No deleted assertions, no .skip, no widened tolerance. The oracle (volumeFoldsCase, test/repokey-path.test.ts:39) is independent of the probe: it writes osi-case-oracle and checks OSI-CASE-ORACLE via existsSync, never calling isCaseInsensitivePath. The pre-fix tautological assertion from #109's smaller items is already fixed on main (visible as unchanged context: expect(n.endsWith("/")).toBe(false)). Compat claim verified end-to-end: the forged-old-key row stays visible through repoPath on both volume types (compat test passed under TMPDIR=/Volumes/OSI109CS).
Probe logic review (src/identity/repokey.ts)
- dev+inode comparison (not string compare) is the right ground truth; a flipped spelling that exists as a different dir correctly yields
falsevia differingino. flipLastCasedskipping index 0 protects the Windows drive letter (C:); a component with no case walks up to the nearest ancestor that has one, so mixed-volume paths (/Volumes/X/123) probe the volume that actually holds the deepest component.statOrNullswallowing errors is correct for a probe:realpathSyncalready resolved the true spelling, and on a folding volume the flipped path resolves to the same inode, so a transient stat failure cannot flip the answer.- FIFO cache capped at 64, keyed on the normalized path; probe cost is 1–2
statSyncper uncached path, called fromresolveRepo, not a hot loop.
Findings
- P0: none.
- P1: none.
- nit (src/identity/repokey.ts:71): the probe answer for a not-yet-existing path is cached from the nearest existing ancestor. If that exact path is later created as a mount point of a different-sensitivity volume, the cached answer is stale until process restart. Vanishingly rare; not worth code.
To get an approve: add Closes #109 to the PR body so the contract is machine-visible. The code itself is clean on every axis I could measure.
fix(identity): reject case-variant symlink probes (#250 F1)
There was a problem hiding this comment.
Reviewed at head 5613d5e58c834d7e7cb9509522af8e7dc4a4086a (diff key f6ca866f5a9a5531a7afb705ea860104369744d2084725fffacdf38eed798c6d).
What moved since the last reviewed head e079003
The branch merged main (4caef0f) and absorbed stacked PR #251 (4a4a9c5, merged 2026-11-02T17:48:51Z). The PR diff against main is now the union of the two previously-reviewed changesets:
src/identity/repokey.tsandtest/repokey-path.test.tsat this head are byte-identical todf90d5f(head of #251,git diff df90d5f..5613d5eshows onlyREADME.md +12from main).- The merge introduced no content of its own beyond main's README.
Contract
closingIssuesReferences is still empty. The title and body reference #109 but the body carries no Closes #109 keyword, so GitHub registers no closing issue. Per policy I cannot approve with no machine-readable contract to verify against. Action for author: add Closes #109 to the PR body. Everything else on this list was already green at the component heads.
Verification at this head
| Check | Result |
|---|---|
gh pr checks 250 |
lint / test / test-windows / smoke — 4/4 pass |
bun run typecheck |
0 errors (223 files) |
bun run lint |
498 warnings = baseline |
bun run test |
860 pass / 14 skip / 0 fail, 11980 expects |
bun run test:e2e |
30 pass / 0 fail |
Skip audit: the two skips beyond the prior 12 are describe.skipIf(aliasVolumeFolds) around the #250 F1 symlink fixtures — creating Foo and foo as distinct directories is impossible on a case-folding volume, so the fixture cannot exist there. Both suites ran green on a real case-sensitive APFS volume (hdiutil create -fs "Case-sensitive APFS") at df90d5f in the #251 review (11/11), with the differential failing at base e079003 for the stated alias-following reason. No assertions deleted, no unconditional .skip, no tolerance widened in the test diff.
Findings
- P0: none.
- P1: none.
- Nit (carried from the
e079003review, non-blocking):isCaseInsensitivePathcaches per path; if a cached path later becomes a mount point with different case sensitivity, the cached answer goes stale. Acceptable as-is; noting for the record.
Verdict: COMMENTED — not because of any defect, solely because the contract is empty. Add Closes #109 and the next run can approve against #109's criteria.
|
🎉 This PR is included in version 0.15.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Problem
normalizeDirPathfolded path case on everywin32/darwinhost:A case-sensitive APFS volume is a legitimate macOS choice (and NTFS has per-directory case sensitivity). There,
Fooandfooare two directories, but both hashed to onerepo=key, andisVisibleTomatched on the key alone — silent cross-project visibility for path-derived keys (repos without a git origin).Fix
Probe the filesystem instead of trusting the platform.
isCaseInsensitivePath(dir)flips one cased character of the deepest existing component and stats both spellings: the volume folds names itself exactly when the flipped spelling still names the samedev+inode. A missing path is decided from the nearest existing component; answers cache per path (FIFO-capped, like the session map). Truly undecided — nothing of the path exists, or no component carries case — falls back to the old platform rule, which is also a no-op whenever the path has no cased characters.Compat story (no re-stamp migration)
Rows written under the old fold carry
repoPath(the true spelling) andisVisibleToalready matches on it, so:repoPathdistinguishes/x/Foofrom/x/fooon a case-sensitive volume.Known, intended behavior change: on a case-sensitive volume, renaming a directory's case now yields a different key (as on Linux); rows stamped under the old spelling stay visible only while the raw path is unchanged.
Tests
isCaseInsensitivePathpinned against an independent filesystem oracle (writeosi-case-oracle, look forOSI-CASE-ORACLE) — never against itself.normalizeDirPathfolds exactly when the volume folds (fixture with guaranteed cased characters).mkdiris the oracle).repoPath.process.platform.Verified locally on both volume types: full suite (872 tests) and e2e (30) green on the insensitive boot volume and on a case-sensitive APFS disk image (
hdiutil create -fs "Case-sensitive APFS"); the compat and two-dirs tests run their sensitive branches there.tscandbiome lintclean.Smaller items from the ticket body: the tautological assertion in
test/repokey-path.test.tswas already fixed on main; #101's "unmatchable-by-hash across machines" wording is corrected on the issue.