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

当 file_write 收到相对路径如 test_tool.txt 时,PathValidator 的
resolve_and_validate 尝试对空父目录 canonicalize 导致失败。

修复:相对路径先基于 workspace_root 解析为绝对路径,再进行安全校验。
This commit is contained in:
iven
2026-04-24 16:02:09 +08:00
parent 3eb098f020
commit 855c89e8fb

View File

@@ -230,7 +230,14 @@ impl PathValidator {
fn resolve_and_validate(&self, path: &str) -> Result<PathBuf> {
// Expand tilde
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
self.check_path_traversal(&path_buf)?;