Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions packages/core/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,26 @@ fn verify_relative_to_cwd(path: &Path) -> anyhow::Result<PathBuf> {
if path.exists() {
path = dunce::canonicalize(&path)
.with_context(|| format!("Could not canonicalize {path:?}"))?;

//check whether it still stars with cwd
if !path.starts_with(&cwd) {
anyhow::bail!("Provided path escapes the current working directory: {path:?}");
}

if path.is_file() {
anyhow::bail!("Provided path is a file, expected a directory: {path:?}");
}
} else if let Some(parent) = path.parent() {
let canonical_parent = dunce::canonicalize(parent)
.with_context(|| format!("Could not canonicalize parent directory {parent:?}"))?;
if !canonical_parent.starts_with(&cwd) {
anyhow::bail!("Provided path resolves outside the current working directory: {path:?}");
}
let file_name = path
.file_name()
.ok_or_else(|| anyhow::anyhow!("Provided path has no valid file name: {path:?}"))?;
path = canonical_parent.join(file_name);
} else {
anyhow::bail!("Provided path has no valid parent directory: {path:?}");
}

// check whether it still starts with cwd
if !path.starts_with(&cwd) {
anyhow::bail!("Provided path escapes the current working directory: {path:?}");
}

if path.exists() && path.is_file() {
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
anyhow::bail!("Provided path is a file, expected a directory: {path:?}");
}

Ok(path)
}

Expand Down
Loading