Validate linked worktrees before inheriting project trust (#39616)

## Why

A checkout could point its `.git` file at a trusted repository's worktree
directory without proving that the repository had registered that checkout.
This could cause project configuration from an unrelated checkout to be treated
as trusted.

## What changed

- Verify the linked worktree's `gitdir` backlink, `commondir`, registered
  checkout, and main checkout ownership before resolving the main repository's
  trust key.
- Reject missing, oversized, symlinked, mismatched, or swapped Git metadata.
- Preserve valid linked worktrees that use path aliases, separate Git
  directories, or non-UTF-8 POSIX paths.

## Testing

Add resolver and config-loading coverage for forged worktrees, metadata races,
case-sensitive paths, moved worktrees, and host MCP startup from project config.

GitOrigin-RevId: 6052a7d10ad2d613436f20175c356abdef8c758e
This commit is contained in:
Jeremy Rose authored and copyberry committed 2026-08-20 06:29:32 +00:00
1 parent 250b5ea2bf
commit bc3545b805
12 files changed
+859 -80

No files matched your search

+26
View File
@@ -8,6 +8,32 @@ use std::os::unix::ffi::OsStringExt;
use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;
#[test]
fn native_byte_joins_preserve_foreign_posix_filenames() {
let base = PathUri::parse("file:///root/%FE/admin").unwrap();
for (path, expected) in [
(
b"../\xff/%2e?#\\".as_slice(),
"file:///root/%FE/%FF/%252e%3F%23%5C",
),
(
b"//other/./x/../\xff/.git".as_slice(),
"file:///other/%FF/.git",
),
(b"../../../../\xff".as_slice(), "file:///%FF"),
(b"../plain".as_slice(), "file:///root/%FE/plain"),
] {
assert_eq!(base.join_native_bytes(path).unwrap().to_string(), expected);
}
assert!(base.join_native_bytes(b"bad\0\xff").is_err());
assert!(
PathUri::parse("file:///C:/repo")
.unwrap()
.join_native_bytes(b"\xff")
.is_err()
);
}
#[test]
fn file_uri_round_trips_an_absolute_path() {
let path = AbsolutePathBuf::current_dir()