Skip to content

Commit 4ee88e7

Browse files
committed
fix(cli): allow system symlinks above absolute badge output paths
macOS temp paths live under /var, a symlink to /private/var, so the guard rejected every absolute temp directory. Relative paths still check every component inside the checkout.
1 parent 659a1e3 commit 4ee88e7

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎crates/git-credit/src/badge.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,20 @@ fn import(source: &str) -> anyhow::Result<Report> {
190190
}
191191

192192
/// Refuse symlinked output components to avoid following an author-controlled path.
193+
///
194+
/// A relative path is resolved inside the checkout, where a committed symlink could
195+
/// redirect writes, so every component is checked. An absolute path was chosen by
196+
/// the caller, and system symlinks above it (for example macOS `/var` pointing to
197+
/// `/private/var`) are legitimate, so only the path itself is checked.
193198
fn check_path(path: &Path) -> anyhow::Result<()> {
194-
for ancestor in path.ancestors() {
199+
let checked: Vec<&Path> = if path.is_absolute() {
200+
vec![path]
201+
} else {
202+
path.ancestors()
203+
.filter(|ancestor| !ancestor.as_os_str().is_empty())
204+
.collect()
205+
};
206+
for ancestor in checked {
195207
match fs::symlink_metadata(ancestor) {
196208
Ok(meta) if meta.file_type().is_symlink() => {
197209
bail!("refusing symlinked badge output {}", ancestor.display())

‎crates/git-credit/tests/badge.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,15 @@ fn refuses_symlinked_output() {
284284
assert_eq!(result.status.code(), Some(1));
285285
assert_eq!(files(outside.path()), std::collections::BTreeMap::new());
286286
}
287+
288+
/// A symlinked directory inside the checkout must not redirect a relative output path.
289+
#[cfg(unix)]
290+
#[test]
291+
fn refuses_relative_output_through_symlinked_component() {
292+
let repo = fixture();
293+
let outside = tempfile::tempdir().unwrap();
294+
std::os::unix::fs::symlink(outside.path(), repo.path().join("docs")).unwrap();
295+
let result = cli(repo.path(), &["badge", "--out-dir", "docs/badges"]);
296+
assert_eq!(result.status.code(), Some(1));
297+
assert_eq!(files(outside.path()), std::collections::BTreeMap::new());
298+
}

0 commit comments

Comments
 (0)