Skip to content

Commit 3c196c1

Browse files
committed
added more guardrails
1 parent afa0631 commit 3c196c1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/core/src/project.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,22 @@ fn verify_base_dir(folder: &Path) -> Result<PathBuf> {
123123
path = dunce::canonicalize(&path)
124124
.with_context(|| format!("Could not canonicalize {path:?}"))?;
125125

126+
//check whether it still stars with cwd
127+
if !path.starts_with(&cwd) {
128+
anyhow::bail!("Provided path escapes the current working directory: {path:?}");
129+
}
130+
126131
if path.is_file() {
127132
anyhow::bail!("Provided path is a file, expected a directory: {path:?}");
128133
}
134+
} else if let Some(parent) = path.parent() {
135+
let canonical_parent = dunce::canonicalize(parent)
136+
.with_context(|| format!("Could not canonicalize parent directory {parent:?}"))?;
137+
if !canonical_parent.starts_with(&cwd) {
138+
anyhow::bail!("Provided path resolves outside the current working directory: {path:?}");
139+
}
140+
} else {
141+
anyhow::bail!("Provided path has no valid parent directory: {path:?}");
129142
}
130143

131144
Ok(path)

0 commit comments

Comments
 (0)