mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-18 06:34:26 +01:00
Run cargo fmt (#3135)
This commit is contained in:
@@ -178,7 +178,11 @@ pub fn get_path(id: Identifier) -> Result<PathBuf> {
|
||||
// Handle path validation with Windows-compatible logic
|
||||
let is_path_allowed = validate_path_within_session_dir(&path, &session_dir)?;
|
||||
if !is_path_allowed {
|
||||
tracing::warn!("Attempted access outside session directory: {:?} not within {:?}", path, session_dir);
|
||||
tracing::warn!(
|
||||
"Attempted access outside session directory: {:?} not within {:?}",
|
||||
path,
|
||||
session_dir
|
||||
);
|
||||
return Err(anyhow::anyhow!("Path not allowed"));
|
||||
}
|
||||
|
||||
@@ -205,7 +209,9 @@ pub fn get_path(id: Identifier) -> Result<PathBuf> {
|
||||
/// - Drive letter casing inconsistencies
|
||||
fn validate_path_within_session_dir(path: &Path, session_dir: &Path) -> Result<bool> {
|
||||
// First, try the simple case - if canonicalization works cleanly
|
||||
if let (Ok(canonical_path), Ok(canonical_session_dir)) = (path.canonicalize(), session_dir.canonicalize()) {
|
||||
if let (Ok(canonical_path), Ok(canonical_session_dir)) =
|
||||
(path.canonicalize(), session_dir.canonicalize())
|
||||
{
|
||||
if canonical_path.starts_with(&canonical_session_dir) {
|
||||
return Ok(true);
|
||||
}
|
||||
@@ -1700,16 +1706,25 @@ mod tests {
|
||||
|
||||
// Test case 2: Invalid path outside session directory
|
||||
let invalid_path = temp_dir.path().join("outside.jsonl");
|
||||
assert!(!validate_path_within_session_dir(&invalid_path, &session_dir)?);
|
||||
assert!(!validate_path_within_session_dir(
|
||||
&invalid_path,
|
||||
&session_dir
|
||||
)?);
|
||||
|
||||
// Test case 3: Path with different separators (simulate Windows issue)
|
||||
let mixed_sep_path = session_dir.join("subdir").join("test.jsonl");
|
||||
fs::create_dir_all(mixed_sep_path.parent().unwrap())?;
|
||||
assert!(validate_path_within_session_dir(&mixed_sep_path, &session_dir)?);
|
||||
assert!(validate_path_within_session_dir(
|
||||
&mixed_sep_path,
|
||||
&session_dir
|
||||
)?);
|
||||
|
||||
// Test case 4: Non-existent path within session directory
|
||||
let nonexistent_path = session_dir.join("nonexistent").join("test.jsonl");
|
||||
assert!(validate_path_within_session_dir(&nonexistent_path, &session_dir)?);
|
||||
assert!(validate_path_within_session_dir(
|
||||
&nonexistent_path,
|
||||
&session_dir
|
||||
)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user