{"record":{"id":"1f9a74dd950e76a1","repo":"jdx/mise","slug":"workspace-path-path-escapes-the-workspace-root","errorCode":null,"errorMessage":"workspace path {path:?} escapes the workspace root","messagePattern":"workspace path (.+?) escapes the workspace root","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/workspace.rs","lineNumber":1232,"sourceCode":"    if normalized.as_os_str().is_empty() {\n        normalized.push(\".\");\n    }\n    Ok(normalized)\n}\n\nfn normalize_workspace_path(path: &Path) -> Result<PathBuf> {\n    if path.is_absolute() {\n        bail!(\"workspace path {path:?} is absolute; paths must be workspace-relative\");\n    }\n\n    let mut normalized = PathBuf::new();\n    for component in path.components() {\n        match component {\n            Component::CurDir => {}\n            Component::Normal(component) => normalized.push(component),\n            Component::ParentDir => {\n                if !normalized.pop() {\n                    bail!(\"workspace path {path:?} escapes the workspace root\");\n                }\n            }\n            Component::RootDir | Component::Prefix(_) => {\n                bail!(\"workspace path {path:?} is absolute; paths must be workspace-relative\");\n            }\n        }\n    }\n    if normalized.as_os_str().is_empty() {\n        normalized.push(\".\");\n    }\n    Ok(normalized)\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[derive(Debug)]","sourceCodeStart":1214,"sourceCodeEnd":1250,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/workspace.rs#L1214-L1250","documentation":"During workspace path normalization, a ParentDir (\"..\") component that pops past the top of the relative path means the path escapes the workspace root. mise rejects it so resolved paths can never point outside the workspace directory.","triggerScenarios":"A workspace path like \"../outside\" or \"a/../../b\" where the ParentDir components exceed the Normal components, hitting the bail in the component loop.","commonSituations":"Glob or file patterns referencing directories outside the workspace; path joins that accidentally accumulate \"..\" segments.","solutions":["Remove or rebalance the \"..\" components so the path stays under the workspace root","Move the referenced file/directory into the workspace","Normalize/resolve the path before writing it into config to drop redundant \"..\" segments"],"exampleFix":"// before\nlet p = Path::new(\"../shared/config.toml\");\n// after\nlet p = Path::new(\"shared/config.toml\");","handlingStrategy":"validation","validationCode":"fn path_stays_in_workspace(p: &std::path::Path) -> bool {\n    let mut depth = 0usize;\n    for c in p.components() {\n        match c {\n            std::path::Component::ParentDir => {\n                if depth == 0 { return false; }\n                depth -= 1;\n            }\n            std::path::Component::Normal(_) => depth += 1,\n            _ => {}\n        }\n    }\n    true\n}","typeGuard":"let contained = |p: &std::path::Path| path_stays_in_workspace(p);","tryCatchPattern":"if let Err(e) = normalize_workspace_path(&p) {\n    if e.to_string().contains(\"escapes the workspace root\") {\n        eprintln!(\"path must remain under the workspace root\");\n    }\n}","preventionTips":["Canonicalize/normalize paths before storing them to drop redundant \"..\" segments","Reject any config path whose \"..\" count exceeds its leading normal components","Keep referenced files inside the workspace; use workspace-level config for outside paths"],"tags":["workspace","path-traversal","security"],"backgroundTag":"path-traversal-blocked","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}