Windows directory junctions bypass repository confinement (pathguard, guardSymlinkWithinRepo, batch destination guard)
Summary
Repository confinement treats Windows directory junctions as ordinary directories. Under Go ≥ 1.23 (winsymlink=1, the default) a junction reparse point (IO_REPARSE_TAG_MOUNT_POINT) is reported by os.Lstat with ModeIrregular, not ModeSymlink, and filepath.EvalSymlinks no longer evaluates mount points ($GOROOT/src/os/types_windows.go, "winsymlink" in internal/godebugs/table.go). Every confinement guard keys on one of those two primitives:
internal/pathguard—isSymlinkchecksModeSymlinkonly;linkTargetEscapesusesEvalSymlinks.internal/mcp/tools_fileops.go—guardSymlinkWithinRepo/resolveNearestExistingAncestoruseEvalSymlinks.internal/mcp/batch_transaction.go—guardBatchLifecycleDestinationwalks destination components and refuses onlyModeSymlink.
So a junction inside an indexed repository that points outside it (<repo>\link → C:\elsewhere) should pass all three guards on Windows: the lexical path is in-repo, EvalSymlinks returns it unchanged, and the component walk sees ModeIrregular. The consequences would be the same class the symlink guards exist for — indexing/serving out-of-repo bytes on the read side, and edit_file / write_file / batch_edit (move_file destination, delete_file source) landing outside the repository on the write side.
Status
Not reproduced — derived from the Go runtime source and the guard code while validating #544 (which explicitly asks for symlink and junction traversal to be refused). It needs a Windows host to confirm; CI's build-windows leg runs ./internal/pathguard, so a junction case there (cmd /c mklink /J) would settle it.
Suggested fix
Treat ModeIrregular reparse points as links in pathguard.isSymlink and in the batch destination walk, and resolve junction targets on Windows before the containment check (either os.Readlink on the reparse point, or opting the process into winsymlink=0 semantics for the resolution step). Add a junction test to internal/pathguard guarded by runtime.GOOS == "windows".
Confirmed on Windows 11 with Go 1.27.0, using internal/pathguard and resolveNearestExistingAncestor copied unchanged from 1003759, not a full daemon run. With <repo>\link created by mklink /J and pointing outside the repo:
os.Lstat(link)reportsModeIrregularandEvalSymlinks(link)returns it unchanged, as you predicted.EvalSymlinks(link\secret.txt)fails with "The system cannot find the path specified".guardSymlinkWithinRepothen falls back toresolveNearestExistingAncestor, which stops atlinkand keeps the lexical path, so the guard allows both an existing file and a new one. A plainos.WriteFilethrough that path lands outside the repo.- With
GODEBUG=winsymlink=0, the same logic refuses both and still allows a junction that stays inside the repo.
I'd like to take this. //go:debug winsymlink=0 would be one line, but it's process-wide and doesn't reach pkg/gortex users, so I'd suggest a small junction-aware resolver in pathguard that all three guards share, plus a mklink /J test on the build-windows leg. #1036 lists junctions as hardening to pull in only if the release gate fires, so is now a good time, or would you rather wait?