From 3fbea00fd44f6496ee4afe2b8b2897c3c95d63e9 Mon Sep 17 00:00:00 2001 From: Sandiyo Christan <55909152+sandiyochristan@users.noreply.github.com> Date: Mon, 28 Sep 2026 11:08:29 +0000 Subject: [PATCH] fix(security): remediate GHSA-6mg9-3cvh-9939 (#12537) --- .../goose-cli/src/commands/review/handler.rs | 6 +- crates/goose/tests/git_command_security.rs | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/crates/goose-cli/src/commands/review/handler.rs b/crates/goose-cli/src/commands/review/handler.rs index b2ad4c87a..2572602a2 100644 --- a/crates/goose-cli/src/commands/review/handler.rs +++ b/crates/goose-cli/src/commands/review/handler.rs @@ -366,7 +366,7 @@ fn review_git_command(repo_root: &Path) -> Command { fn touched_files(repo_root: &Path, range: Option<&str>, files: &[String]) -> Result> { let mut cmd = review_git_command(repo_root); - cmd.arg("diff").arg("--name-only"); + cmd.arg("diff").arg("--no-ext-diff").arg("--name-only"); match range { Some(r) => { cmd.arg(r); @@ -397,7 +397,7 @@ fn touched_files(repo_root: &Path, range: Option<&str>, files: &[String]) -> Res fn collect_diff(repo_root: &Path, range: Option<&str>, files: &[String]) -> Result { let mut cmd = review_git_command(repo_root); - cmd.arg("diff"); + cmd.arg("diff").arg("--no-ext-diff"); match range { Some(r) => { cmd.arg(r); @@ -421,7 +421,7 @@ fn collect_diff(repo_root: &Path, range: Option<&str>, files: &[String]) -> Resu fn collect_diff_stat(repo_root: &Path, range: Option<&str>, files: &[String]) -> Result { let mut cmd = review_git_command(repo_root); - cmd.arg("diff").arg("--stat"); + cmd.arg("diff").arg("--no-ext-diff").arg("--stat"); match range { Some(r) => { cmd.arg(r); diff --git a/crates/goose/tests/git_command_security.rs b/crates/goose/tests/git_command_security.rs index fe509b75d..265c1a577 100644 --- a/crates/goose/tests/git_command_security.rs +++ b/crates/goose/tests/git_command_security.rs @@ -83,3 +83,60 @@ fn does_not_execute_repository_fsmonitor_hook() { assert_git_succeeded(&output); assert!(!marker_path.exists(), "repository fsmonitor hook ran"); } + +#[cfg(unix)] +#[test] +fn does_not_execute_repository_diff_external() { + use std::os::unix::fs::PermissionsExt; + + let temp_dir = tempfile::tempdir().unwrap(); + let repo_dir = temp_dir.path().join("repo"); + fs::create_dir(&repo_dir).unwrap(); + assert_git_succeeded(&run_git(&repo_dir, &["init"])); + + fs::write(repo_dir.join("tracked.txt"), "initial\n").unwrap(); + assert_git_succeeded(&run_git(&repo_dir, &["add", "tracked.txt"])); + assert_git_succeeded(&run_git( + &repo_dir, + &[ + "-c", + "user.name=test", + "-c", + "user.email=test@example.com", + "commit", + "-m", + "initial", + ], + )); + + fs::write(repo_dir.join("tracked.txt"), "modified\n").unwrap(); + + let marker_path = temp_dir.path().join("diff-external-ran"); + let hook_path = temp_dir.path().join("diff-external-hook"); + fs::write( + &hook_path, + format!("#!/bin/sh\n: > '{}'\n", marker_path.display()), + ) + .unwrap(); + fs::set_permissions(&hook_path, fs::Permissions::from_mode(0o755)).unwrap(); + assert_git_succeeded(&run_git( + &repo_dir, + &["config", "diff.external", hook_path.to_str().unwrap()], + )); + + assert_git_succeeded(&run_git(&repo_dir, &["diff"])); + assert!( + marker_path.exists(), + "diff.external hook fixture did not run" + ); + fs::remove_file(&marker_path).unwrap(); + + let output = git_command() + .args(["diff", "--no-ext-diff"]) + .current_dir(&repo_dir) + .output() + .unwrap(); + + assert_git_succeeded(&output); + assert!(!marker_path.exists(), "repository diff.external hook ran"); +}