History

fix(gix): normalize safe-directory paths before trust checks

<!-- agent --> Windows canonicalization can produce verbatim paths with a `\\?\` prefix while included configuration metadata uses an ordinary drive path. Comparing those representations directly prevents an explicitly safe config file from being promoted to full trust, including after repository reloads. Canonicalize both the path under test and configured safe-directory paths through the filesystem before exact or wildcard comparison. Retain the existing lexical realpath fallback for missing paths.

Sebastian Thiel committed 2 months ago

Commit c48fe1e1 parent 913f6311 file · +7 −5Browse files

Unified · Split

gix/src/open/repository.rs+7−5
@@ -609,10 +609,12 @@ fn check_safe_directories( · 608 unmodified lines
609609 safe_dirs: &[BString],
610610 ) -> Result<(), Error> {
611611 let mut is_safe = false;
612− let path_to_test = match gix_path::realpath_opts(path_to_test, current_dir, gix_path::realpath::MAX_SYMLINKS) {
613− Ok(p) => p,
614− Err(_) => path_to_test.to_owned(),
612+ let realpath_or_original = |path: &std::path::Path| {
613+ std::fs::canonicalize(path)
614+ .or_else(|_| gix_path::realpath_opts(path, current_dir, gix_path::realpath::MAX_SYMLINKS))
615+ .unwrap_or_else(|_| path.to_owned())
615616 };
617+ let path_to_test = realpath_or_original(path_to_test);
616618 for safe_dir in safe_dirs {
617619 let safe_dir = safe_dir.as_bstr();
618620 if safe_dir == "*" {
@@ -638,10 +640,10 @@ fn check_safe_directories( · 19 unmodified lines
638640 }
639641 if safe_dir.ends_with("*") {
640642 let safe_dir = safe_dir.parent().expect("* is last component");
641− if path_to_test.strip_prefix(safe_dir).is_ok() {
643+ if path_to_test.strip_prefix(realpath_or_original(safe_dir)).is_ok() {
642644 is_safe = true;
643645 }
644− } else if safe_dir == path_to_test {
646+ } else if realpath_or_original(&safe_dir) == path_to_test {
645647 is_safe = true;
646648 }
647649 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t