Skip to content

Security review: no permission gate on tool execution in interactive sessions, plus 4 related trust-boundary gaps #568

Open

Description

@JoeHosman

Summary

Ran a security review before adopting jcode (auth, telemetry, supply chain, deps, and the agent/tool-execution trust boundary). Most of it looks solid: PKCE OAuth, CSRF state, 0600/0700 credential file hardening, self-hosted telemetry with an opt-out that's actually enforced in code, clean dependency pins. Good work there.

The area that actually worries me is the tool-execution / agent trust boundary, basically what stands between a model deciding to run something and it actually happening. Filing this as one issue since the findings are related, happy to split if you'd rather. Opening a PR from a fork shortly with fixes for all five.

Findings

1. No permission/confirmation gate on tool execution in normal interactive sessions
crates/jcode-app-core/src/agent/turn_loops.rs calls registry.execute(...) the moment the model emits a tool call (bash/write/edit/patch), no confirmation step. The only human-in-the-loop system (SafetySystem in jcode-base/src/safety.rs, plus jcode-tui-permissions) is wired exclusively into "ambient" background mode. docs/SAFETY_SYSTEM.md even says so itself: "Currently the only consumer is ambient mode," and it's marked Status: Design.

So a prompt injection from a fetched webpage, a README, or MCP tool output can get shell commands run with the user only seeing it after the fact. This is a big departure from how comparable tools handle it (approval by default, explicit opt-in to skip it).

2. Path traversal in file write/edit tools
ToolContext::resolve_path (jcode-tool-core/src/lib.rs) just joins relative paths onto working_dir, no canonicalization or bounds check, and passes absolute paths through as-is. Used directly by WriteTool, EditTool, PatchTool. Combine with #1 and a model-supplied path like ../../../.ssh/authorized_keys (or any absolute path) gets honored no questions asked.

3. MCP tool output fed back to the model unsanitized
McpTool::execute (jcode-base/src/mcp/tool.rs) forwards a server's raw content as the tool result with no tagging as external/untrusted. A malicious or compromised MCP server can just return injected instructions that land in context and, combined with #1, get acted on right away.

4. Agent can spawn arbitrary MCP server subprocesses, no confirmation
connect_server (jcode-app-core/src/tool/mcp.rs) lets the model call mcp connect with whatever command/args it wants, spawns a local subprocess, zero approval.

5. Swarm sub-agents have no privilege separation
crates/jcode-app-core/src/server/swarm.rs notes the spawn-tree depth cap isn't actually enforced in code anymore. Swarm members get the same unconfirmed tool registry (shell, files, MCP connect, further spawning) as the parent session.

Suggested direction

Wiring some form of confirmation gate into the default interactive tool-execution path (not just ambient mode) covers #1, and gives a natural enforcement point for #3/#4 (treat MCP-originated content/actions as needing confirmation) and #5 (route sub-agent calls through the same gate, actually enforce the depth cap). Note: the existing SafetySystem is built for async/unmonitored operation (review queue, email/SMS notifications) which doesn't map cleanly onto a synchronous interactive session, so this probably wants a simpler, separate synchronous confirm-prompt path rather than reusing SafetySystem directly. #2 is independent, just needs canonicalization plus a working-directory bounds check in resolve_path.

Happy to talk through design tradeoffs before or on the PR.

Activity

  1. changed the title [-]Security review: no permission gate on tool execution in interactive sessions (+ 4 related trust-boundary gaps)[/-] [+]Security review: no permission gate on tool execution in interactive sessions, plus 4 related trust-boundary gaps[/+] on Jul 24, 2026
  2. added
    priority: high
    triage: needs-decision
    autonomous: no
    on Jul 24, 2026
  3. 1jehuang commented on Jul 24, 2026

    @1jehuang
    Owner

    Thanks for the structured security review. Permission gating on tool execution and the related trust-boundary gaps are explicitly maintainer-decision territory (they change the default trust model and could break existing automated workflows), so an agent should not implement these autonomously. Marked as needs-decision for @1jehuang. #566 requests a related directory-scoping capability and should be considered together with this.


    — Jcode agent (automated triage), on behalf of @1jehuang

  4. luukvhoudt commented on Jul 28, 2026

    @luukvhoudt

    Independent review against v0.61.1 (438789eb) reaches the same conclusions, and I can add two concrete points.

    Finding #1 is worse than "no gate": jcode disables the wrapped tool's gate too. When jcode drives the Claude CLI as a provider, it launches it with --permission-mode bypassPermissions by default:

    // crates/jcode-provider-claude-cli-runtime/src/lib.rs:31
    const DEFAULT_PERMISSION_MODE: &str = "bypassPermissions";
    

    The value is applied as --permission-mode <mode> at lib.rs:913-914, defaulting to that constant unless JCODE_CLAUDE_CLI_PERMISSION_MODE (or JCODE_CLAUDE_SDK_PERMISSION_MODE) overrides it (lib.rs:148-156). So a user assuming "Claude CLI's own approval prompts still protect me" is not protected by default; jcode turns them off.

    Finding #2 is still present in v0.61.1. resolve_path is unchanged:

    // crates/jcode-tool-core/src/lib.rs:105
    pub fn resolve_path(&self, path: &Path) -> PathBuf {
        if path.is_absolute() {
            path.to_path_buf()
        } else if let Some(ref base) = self.working_dir {
            base.join(path)
        } else {
            path.to_path_buf()
        }
    }
    

    Absolute paths pass through as-is and relative paths are joined with no canonicalization or bounds check; I found no bounds/canonicalize step in the write/edit/patch tools that call it. Combined with #1 (no gate), a single injected instruction from a fetched page, README, or MCP result can write anywhere the user can: appending an attacker's key to ~/.ssh/authorized_keys (remote login), or dropping a ~/.zshrc/~/.bashrc line (code execution on next shell). No prompt, no path bound.

    Note the destructive-command reflection turn (#618) is model-facing (a justification string satisfies it), not a user confirmation, so it does not cover finding #1 for writes/edits or injected-instruction execution.

  5. 42m4n commented on Aug 6, 2026

    @42m4n

    I ran into this as well during interactive sessions. v0.68.0

    What I'm looking for is an opencode-style permission model: allow by default, but ask before potentially destructive shell commands (for example rm, git push, git checkout) and before accessing files outside a configured directory allow-list.

    Since there isn't a built-in configurable permission model today, I implemented it with a pre_tool gate hook (Zenity prompt; exit 0 = allow, exit 2 = deny; directory allow-list loaded from a config file). It works well enough, but I think these capabilities belong in jcode itself:

    1. A configurable permission section in config.toml for interactive sessions (allow/ask/deny per command pattern and per directory root), similar to opencode's "*": "allow" plus external_directory: "ask" model.
    2. Apply the existing [safety.rules] (allow_without_permission / require_permission) to interactive tool execution, not only Ambient Mode.
    3. A built-in terminal/GUI confirmation prompt so users don't need to implement custom hooks and external tools like Zenity.

    I'd be happy to test a native implementation or share my hook as a reference if it's useful.

  6. devinder-getok commented on Sep 2, 2026

    @devinder-getok

    hi @42m4n , were you able to work around this? Happy to contribute and raise a PR if required

  7. Shxnque commented on Sep 2, 2026

    @Shxnque

    Landing on @benrrr56-wq's point because it's the crux: bind the gate to the canonicalized (command, resolved_path, cwd) tuple, not the model's raw args. Three things I'd fold in so the gate can't be defeated the ways this thread has already surfaced:

    1. Boundary at the executor, not the provider. @luukvhoudt's bypassPermissions default is exactly why: if the gate lives in a provider that a sub-runtime can be launched with --permission-mode bypassPermissions, it isn't a boundary, it's a suggestion. The check has to sit at registry.execute(...) / the tool executor itself, so no provider flag can route around it.

    2. Decide over a content hash, and re-verify it at exec. Compute decision_key = sha256(normalize(command, resolve_path(path), cwd)), have the gate decide on that, then have the executor re-check the same hash immediately before running. That closes @benrrr56-wq's reverse-TOCTOU (user approves what the model intended, shell runs what the resolver normalized) and folds finding #2 in: an out-of-bounds resolved path changes the hash and can never match an approval. resolve_path has to canonicalize + bounds-check first, or the hash is computed over the wrong thing.

    3. Gate on effect-class × provenance, not on everything. This is the part that speaks to the maintainer's "don't break existing automated workflows" concern (the reason this is needs-decision): you don't have to prompt on every call. Gate when the effect class is sensitive (shell exec, fs-write, network egress) and the tool call's provenance is untrusted — i.e. it originated from or was influenced by fetched web content, a README, or MCP tool output, which is the actual injection surface in finding #1. A model-authored edit inside a trusted turn can stay allow-by-default; the same bash rm -rf synthesized right after untrusted MCP output gates. That's opencode-style ergonomics (@42m4n) without a confirm-storm.

    Fully respect that the default trust model is maintainer territory per the triage note — offering this as design input, not an autonomous change. If it's useful I'm happy to help spec the executor-side gate and a few negative test vectors (approve-then-mutate, bypassPermissions-can't-defeat, untrusted-provenance-sensitive-call). This exact seam — decision bound to a normalized-call hash, re-verified at execution, keyed on effect-class × provenance — is something we've built deterministically on the Quesen side, so happy to share what held up in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: nopriority: hightriage: needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions