fix(security): remediate GHSA-6mg9-3cvh-9939 (#12537)
This commit is contained in:
@@ -366,7 +366,7 @@ fn review_git_command(repo_root: &Path) -> Command {
|
||||
|
||||
fn touched_files(repo_root: &Path, range: Option<&str>, files: &[String]) -> Result<Vec<String>> {
|
||||
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<String> {
|
||||
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<String> {
|
||||
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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user