{"record":{"id":"ffd69900cefe47a6","repo":"Hmbown/CodeWhale","slug":"reviewed-plugin-mcp-path-escaped-its-staged-root","errorCode":null,"errorMessage":"reviewed plugin MCP path escaped its staged root","messagePattern":"reviewed plugin MCP path escaped its staged root","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":5596,"sourceCode":"                anyhow::bail!(\"reviewed plugin MCP argument path escaped its staged root\");\n            }\n            *argument = frozen.display().to_string();\n        }\n    }\n    Ok(())\n}\n\nfn resolve_plugin_mcp_cwd(plugin_path: &Path, cwd: Option<&Path>) -> Result<PathBuf> {\n    let cwd = match cwd {\n        Some(cwd) if cwd.is_relative() => normalize_path_components(&plugin_path.join(cwd)),\n        Some(cwd) => normalize_path_components(cwd),\n        None => plugin_path.to_path_buf(),\n    };\n    let resolved = cwd\n        .canonicalize()\n        .unwrap_or_else(|_| normalize_path_components(&cwd));\n    if !resolved.starts_with(plugin_path) {\n        anyhow::bail!(\"reviewed plugin MCP path escaped its staged root\");\n    }\n    Ok(resolved)\n}\n\nfn workspace_allows_project_mcp_config(workspace: &Path) -> bool {\n    crate::config::is_workspace_trusted(workspace)\n}\n\nfn checked_workspace_mcp_config_path(workspace: &Path) -> Result<PathBuf> {\n    Ok(checked_workspace_path(workspace)?\n        .join(\".codewhale\")\n        .join(\"mcp.json\"))\n}\n\nfn checked_workspace_path(workspace: &Path) -> Result<PathBuf> {\n    if workspace.as_os_str().is_empty() {\n        anyhow::bail!(\"workspace path cannot be empty\");\n    }","sourceCodeStart":5578,"sourceCodeEnd":5614,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L5578-L5614","documentation":"This error is thrown when a reviewed plugin's MCP server working directory, after canonicalization, no longer sits under the plugin's staged root directory. The library validates that the resolved path starts with the staged plugin path to prevent a reviewed plugin from executing its MCP server from outside the approved staging location (e.g. via a symlink). It is a security guard against path escape during plugin review.","triggerScenarios":"Calling the plugin MCP path resolution function (around crates/tui/src/mcp.rs:5596) when the canonicalized `cwd` of the plugin's staged MCP server resolves outside `plugin_path` — typically because the staged path contains a symlink pointing elsewhere, or a `..` component escapes the root.","commonSituations":"A plugin developer symlinks their MCP server binary or directory into the staging area instead of copying it; CI copies plugins with symlinks preserved; a user hand-edits the staged plugin layout; macOS temp-dir symlinks (/var -> /private/var) making canonicalization diverge from the staged prefix.","solutions":["Copy the MCP server files physically into the staged plugin directory instead of symlinking them","Make sure the staged `plugin_path` is itself canonicalized before the comparison, so prefix matching is consistent","If using temp dirs on macOS, stage plugins under the canonical path (e.g. /private/var/...) or canonicalize the root before staging","Re-package the plugin so its cwd genuinely lives inside the reviewed staging root"],"exampleFix":"// before\nlet plugin_path = std::env::temp_dir().join(\"plugins\").join(\"reviewed\"); // non-canonical, symlinked root\n// after\nlet plugin_path = std::env::temp_dir().join(\"plugins\").join(\"reviewed\").canonicalize()?; // canonical root so starts_with holds","handlingStrategy":"validation","validationCode":"fn plugin_cwd_within_root(cwd: &Path, plugin_path: &Path) -> bool {\n    let resolved = cwd.canonicalize().unwrap_or_else(|_| cwd.to_path_buf());\n    resolved.starts_with(plugin_path)\n}\nassert!(plugin_cwd_within_root(&staged_cwd, &plugin_root), \"staged cwd escaped plugin root\");","typeGuard":"fn is_within(child: &Path, parent: &Path) -> bool {\n    child.canonicalize().map(|c| c.starts_with(parent)).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Copy (don't symlink) plugin files into the staged root","Canonicalize both sides of prefix checks before comparing","Avoid staging plugins under macOS /var symlinked temp dirs"],"tags":["mcp","path-validation","security","plugin"],"backgroundTag":"path-traversal-blocked","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}