Hmbown/CodeWhale · error

reviewed plugin stdio cwd escaped its staged root

Error message

reviewed plugin stdio cwd escaped its staged root

What it means

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.

Solutions

  1. Set the plugin's configured cwd to a directory inside the staged root (or omit cwd to inherit the stage root)
  2. Fix the manifest/launch descriptor so cwd resolves under the stage directory
  3. Check for symlinks or relative-path construction that makes cwd lexically escape the staged root

Example fix

// before (manifest)
"cwd": "/home/user/shared-tools"
// after
"cwd": "<staged-root>/workdir"
Defensive patterns

Strategy: validation

Validate before calling

const resolved = require("path").resolve(cwd);
if (!resolved.startsWith(require("path").resolve(stagedRoot) + require("path").sep) && resolved !== require("path").resolve(stagedRoot)) {
  throw new Error("plugin cwd must stay inside the staged root");
}

Try / catch

try {
  launchStdioPlugin(plugin);
} catch (e) {
  if (String(e).includes("cwd escaped its staged root")) {
    // reject manifest, require repackaging with an in-stage cwd
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/3241d0e5ed6b0e57. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp.rs:742

            let path = Path::new(argument);
            if path.is_absolute() && path.starts_with(staged_root) && path.is_file() {
                let bound = launch.bind_file(staged_root, path, &validated.file_hashes)?;
                #[cfg(target_os = "macos")]
                if node_entry_keeps_path && node_entry_index == Some(index) {
                    continue;
                }
                launch.args[index] = bound;
            }
        }
        #[cfg(target_os = "macos")]
        if let Some(entry_index) = node_entry_index
            && !node_entry_keeps_path
        {
            launch.args = node_esm_descriptor_args(&launch.args, entry_index);
        }
        if let Some(cwd) = cwd {
            if !cwd.starts_with(staged_root) {
                anyhow::bail!("reviewed plugin stdio cwd escaped its staged root");
            }
            launch.bind_cwd(cwd)?;
        }
        // A final authority pass detects source/stage and capability drift
        // while handles were opened. Retained Node entry paths and imports
        // are reopened after this check; their owner-only, read-only stage is
        // not an atomic handle binding or an OS sandbox.
        self.validate_before_stdio_spawn(server_name)?;
        Ok(launch)
    }

    fn required_capability(&self) -> crate::plugins::activation::PluginActivationCapability {
        if self.approved_remote_endpoint.is_some() {
            crate::plugins::activation::PluginActivationCapability::McpRemote
        } else {
            crate::plugins::activation::PluginActivationCapability::McpStdio
        }
    }

View on GitHub (pinned to 73e0f67d83)