{"record":{"id":"3241d0e5ed6b0e57","repo":"Hmbown/CodeWhale","slug":"reviewed-plugin-stdio-cwd-escaped-its-staged-root","errorCode":null,"errorMessage":"reviewed plugin stdio cwd escaped its staged root","messagePattern":"reviewed plugin stdio cwd escaped its staged root","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":742,"sourceCode":"            let path = Path::new(argument);\n            if path.is_absolute() && path.starts_with(staged_root) && path.is_file() {\n                let bound = launch.bind_file(staged_root, path, &validated.file_hashes)?;\n                #[cfg(target_os = \"macos\")]\n                if node_entry_keeps_path && node_entry_index == Some(index) {\n                    continue;\n                }\n                launch.args[index] = bound;\n            }\n        }\n        #[cfg(target_os = \"macos\")]\n        if let Some(entry_index) = node_entry_index\n            && !node_entry_keeps_path\n        {\n            launch.args = node_esm_descriptor_args(&launch.args, entry_index);\n        }\n        if let Some(cwd) = cwd {\n            if !cwd.starts_with(staged_root) {\n                anyhow::bail!(\"reviewed plugin stdio cwd escaped its staged root\");\n            }\n            launch.bind_cwd(cwd)?;\n        }\n        // A final authority pass detects source/stage and capability drift\n        // while handles were opened. Retained Node entry paths and imports\n        // are reopened after this check; their owner-only, read-only stage is\n        // not an atomic handle binding or an OS sandbox.\n        self.validate_before_stdio_spawn(server_name)?;\n        Ok(launch)\n    }\n\n    fn required_capability(&self) -> crate::plugins::activation::PluginActivationCapability {\n        if self.approved_remote_endpoint.is_some() {\n            crate::plugins::activation::PluginActivationCapability::McpRemote\n        } else {\n            crate::plugins::activation::PluginActivationCapability::McpStdio\n        }\n    }","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L724-L760","documentation":"Reviewed stdio plugins must run with a working directory inside their staged (owner-only) root. prepare_stdio_launch checks that the configured cwd starts with the staged root and bails otherwise, preventing a reviewed plugin from being launched with elevated filesystem positioning outside its sandbox.","triggerScenarios":"A plugin manifest or resolved launch plan specifying a cwd outside the stage directory (e.g. an absolute path elsewhere, or a `..`-relative cwd that escapes the stage root) passed to prepare_stdio_launch.","commonSituations":"Plugin manifest authored with the developer's own project directory as cwd; a packaging bug emitting the wrong cwd; symlinked stage paths where the literal prefix no longer matches the staged_root string prefix.","solutions":["Set the plugin's configured cwd to a directory inside the staged root (or omit cwd to inherit the stage root)","Fix the manifest/launch descriptor so cwd resolves under the stage directory","Check for symlinks or relative-path construction that makes cwd lexically escape the staged root"],"exampleFix":"// before (manifest)\n\"cwd\": \"/home/user/shared-tools\"\n// after\n\"cwd\": \"<staged-root>/workdir\"","handlingStrategy":"validation","validationCode":"const resolved = require(\"path\").resolve(cwd);\nif (!resolved.startsWith(require(\"path\").resolve(stagedRoot) + require(\"path\").sep) && resolved !== require(\"path\").resolve(stagedRoot)) {\n  throw new Error(\"plugin cwd must stay inside the staged root\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  launchStdioPlugin(plugin);\n} catch (e) {\n  if (String(e).includes(\"cwd escaped its staged root\")) {\n    // reject manifest, require repackaging with an in-stage cwd\n  }\n  throw e;\n}","preventionTips":["Validate plugin manifests at packaging time: cwd must be inside the stage","Avoid absolute paths to developer machines in plugin manifests","Beware symlinked stage paths that make string-prefix checks fail"],"tags":["mcp","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"}