Merge commit 'a69db7b619bf380327fc7369dd2b0fc98590314d' into codex/psec-4394-git-04c-include-config-authority

# Conflicts:
#	codex-rs/git-utils/src/apply.rs
#	codex-rs/git-utils/src/patch_paths.rs
This commit is contained in:
Chris Bookholt
2026-07-06 15:54:02 -07:00
15 changed files with 613 additions and 23 deletions
@@ -75,7 +75,28 @@ fn assert_worktree_rejection(error: io::Error) {
assert!(error.to_string().contains("worktree-controlled"), "{error}");
}
#[cfg(target_os = "linux")]
fn assert_process_relative_include_rejection(error: io::Error) {
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(
error
.to_string()
.contains("process-relative Git config include"),
"{error}"
);
}
fn run_isolated_source_test(test_name: &str, env: &[(&str, &OsStr)], removed: &[&str]) {
let cwd = std::env::current_dir().expect("current directory");
run_isolated_source_test_from(test_name, env, removed, &cwd);
}
fn run_isolated_source_test_from(
test_name: &str,
env: &[(&str, &OsStr)],
removed: &[&str],
cwd: &Path,
) {
let mut command = std::process::Command::new(std::env::current_exe().expect("test binary"));
crate::safe_git::isolate_git_command_environment(&mut command);
command
@@ -83,7 +104,8 @@ fn run_isolated_source_test(test_name: &str, env: &[(&str, &OsStr)], removed: &[
.arg("--exact")
.arg("--nocapture")
.env("CODEX_GIT_CONFIG_SOURCE_CHILD", "1")
.env("RUST_TEST_THREADS", "1");
.env("RUST_TEST_THREADS", "1")
.current_dir(cwd);
for (name, value) in env {
command.env(name, value);
}
@@ -99,6 +121,90 @@ fn run_isolated_source_test(test_name: &str, env: &[(&str, &OsStr)], removed: &[
);
}
#[cfg(target_os = "linux")]
#[test]
fn rejects_process_relative_primary_config_sources_before_git_changes_cwd() {
use std::os::unix::fs::symlink;
const TEST_NAME: &str = "git_config_sources::tests::rejects_process_relative_primary_config_sources_before_git_changes_cwd";
if std::env::var_os("CODEX_GIT_CONFIG_SOURCE_CHILD").is_none() {
let fixture = tempfile::tempdir().expect("fixture");
let root = fixture.path().join("repo");
let external = fixture.path().join("external");
let alias = fixture.path().join("config-alias");
let chained_alias = fixture.path().join("chained-alias");
init_repo_at(&root);
std::fs::create_dir(&external).expect("external directory");
std::fs::write(
external.join("decoy.gitconfig"),
"[safe]\nvalue = external\n",
)
.expect("external decoy");
std::fs::write(
external.join(".gitconfig"),
"[safe]\nvalue = external-home\n",
)
.expect("external HOME config");
for leaf in ["decoy.gitconfig", "missing-parent.gitconfig"] {
std::fs::write(root.join(leaf), "[unsafe]\nhelper = worktree\n")
.expect("worktree config");
}
symlink("/proc/self/cwd", &alias).expect("procfs alias");
symlink("config-alias", &chained_alias).expect("chained procfs alias");
let candidates = [
PathBuf::from("/proc/self/cwd/decoy.gitconfig"),
PathBuf::from("/proc/thread-self/cwd/decoy.gitconfig"),
PathBuf::from("/proc/self/cwd/missing-parent.gitconfig"),
alias.join("decoy.gitconfig"),
chained_alias.join("decoy.gitconfig"),
];
for candidate in &candidates {
run_isolated_source_test_from(
TEST_NAME,
&[
("CODEX_GIT_CONFIG_SOURCE_ROOT", root.as_os_str()),
("GIT_CONFIG_GLOBAL", candidate.as_os_str()),
("GIT_CONFIG_NOSYSTEM", OsStr::new("1")),
],
&["GIT_CONFIG_SYSTEM"],
&external,
);
}
run_isolated_source_test_from(
TEST_NAME,
&[
("CODEX_GIT_CONFIG_SOURCE_ROOT", root.as_os_str()),
("GIT_CONFIG_GLOBAL", OsStr::new("")),
(
"GIT_CONFIG_SYSTEM",
OsStr::new("/proc/self/cwd/decoy.gitconfig"),
),
],
&["GIT_CONFIG_NOSYSTEM"],
&external,
);
run_isolated_source_test_from(
TEST_NAME,
&[
("CODEX_GIT_CONFIG_SOURCE_ROOT", root.as_os_str()),
("HOME", OsStr::new("/proc/self/cwd")),
("GIT_CONFIG_NOSYSTEM", OsStr::new("1")),
],
&["GIT_CONFIG_GLOBAL", "GIT_CONFIG_SYSTEM", "XDG_CONFIG_HOME"],
&external,
);
return;
}
let root = PathBuf::from(
std::env::var_os("CODEX_GIT_CONFIG_SOURCE_ROOT").expect("fixture repository root"),
);
let error = guard(&root).expect_err("process-relative primary config source");
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "{error}");
assert!(error.to_string().contains("process-relative"), "{error}");
}
#[test]
fn allows_protected_metadata_and_external_config_sources() {
let repo = init_repo();
@@ -824,6 +930,73 @@ fn command_scoped_include_paths_follow_the_same_boundary() {
);
}
#[cfg(target_os = "linux")]
#[test]
fn rejects_process_relative_procfs_includes_across_the_include_graph() {
use std::os::unix::fs::symlink;
for (key, value, leaf) in [
(
"include.path",
"/proc/self/cwd/direct.gitconfig",
"direct.gitconfig",
),
(
"includeIf.gitdir:/definitely/not/this/repository/**.path",
"/proc/thread-self/cwd/conditional.gitconfig",
"conditional.gitconfig",
),
] {
let repo = init_repo();
let root = repo.path();
std::fs::write(root.join(leaf), "[unsafe]\nhelper = worktree\n")
.expect("write process-relative include target");
add_include(root, key, value);
assert_process_relative_include_rejection(
guard(root).expect_err("process-relative repository include"),
);
}
let repo = init_repo();
let root = repo.path();
std::fs::write(
root.join("command.gitconfig"),
"[unsafe]\nhelper = worktree\n",
)
.expect("write command include target");
let git = GitRunner::for_cwd_io(root).expect("Git runner");
let args = vec![
"-c".to_string(),
"include.path=/proc/self/cwd/command.gitconfig".to_string(),
];
assert_process_relative_include_rejection(
ensure_no_worktree_config_sources(&git, root, &args)
.expect_err("process-relative command-scoped include"),
);
let repo = init_repo();
let root = repo.path();
std::fs::write(
root.join("nested.gitconfig"),
"[unsafe]\nhelper = worktree\n",
)
.expect("write nested include target");
let external = tempfile::tempdir().expect("external include directory");
let parent = external.path().join("parent.gitconfig");
let alias = external.path().join("procfs-alias");
symlink("/proc/self/cwd", &alias).expect("create procfs alias");
std::fs::write(&parent, "[include]\npath = procfs-alias/nested.gitconfig\n")
.expect("write external parent config");
add_include(
root,
"include.path",
parent.to_str().expect("UTF-8 parent config path"),
);
assert_process_relative_include_rejection(
guard(root).expect_err("nested aliased process-relative include"),
);
}
#[test]
fn rejects_every_duplicate_and_nested_include_target() {
for unsafe_first in [true, false] {