fix(tool): 相对路径文件写入失败 — PathValidator 先基于 workspace 解析
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
当 file_write 收到相对路径如 test_tool.txt 时,PathValidator 的 resolve_and_validate 尝试对空父目录 canonicalize 导致失败。 修复:相对路径先基于 workspace_root 解析为绝对路径,再进行安全校验。
This commit is contained in:
@@ -230,7 +230,14 @@ impl PathValidator {
|
|||||||
fn resolve_and_validate(&self, path: &str) -> Result<PathBuf> {
|
fn resolve_and_validate(&self, path: &str) -> Result<PathBuf> {
|
||||||
// Expand tilde
|
// Expand tilde
|
||||||
let expanded = expand_tilde(path);
|
let expanded = expand_tilde(path);
|
||||||
let path_buf = PathBuf::from(&expanded);
|
let mut path_buf = PathBuf::from(&expanded);
|
||||||
|
|
||||||
|
// If relative path and workspace is configured, resolve against workspace
|
||||||
|
if path_buf.is_relative() {
|
||||||
|
if let Some(ref workspace) = self.workspace_root {
|
||||||
|
path_buf = workspace.join(&path_buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for path traversal
|
// Check for path traversal
|
||||||
self.check_path_traversal(&path_buf)?;
|
self.check_path_traversal(&path_buf)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user