read/edit rules and managed file policies are skipped by the shell, MCP/plugin tools and --file

未关闭
#67,050 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend, cli, security

调研方向

Start with packages/core/src/shell/permissions.ts, packages/core/src/tool/mcp.ts, and packages/cli/src/run/run.ts to trace how paths bypass read, edit, .env, and external-directory policies. Identify where shell commands, MCP/plugin tools, Code Mode, and --file need the same path checks as the built-in file tools. Done means each route consistently honors the applicable rules or the documentation explicitly states a supported limitation.

由索引模型根据 Issue 内容生成。

描述

area/core type/feature version/v2
Description

Tested on 2.4.2 with opencode run --standalone. read/edit rules, external_directory rules, the built-in .env ask and managed tool.use policies such as read:secret/* are checked by the read, write and edit tools. Other routes reach the same files with no check. Related:

  1. Shell: cat, a background shell or python3 -c read a file the read tool refuses, printf > file writes past an edit deny or ask, and cat .env.d/a.txt gets past the .env ask. The shell only checks shell and external_directory. The docs do say shell has the host user's authority, but the policy docs list read:*/.ssh/* as blocking "Reading SSH material", and a cat gets around that. grep has the same gap (#64059). packages/core/src/shell/permissions.ts:44-59
  2. MCP tools, plugin tools and Code Mode: an MCP tool is checked only as <server>_<tool> with resource *, so files_read(path) returns a file under a read deny, the managed policy or external_directory: deny, and files_write writes into a denied folder. The same through execute and through a plugin tool that uses fs. The docs say MCP tools match * and plugin tools enforce what they assert, but the file-rule docs don't warn that file rules don't cover tools that take a path. packages/core/src/tool/mcp.ts:63-69
  3. opencode run --file puts the file into the first model request under a read deny, the .env ask, external_directory: deny and the managed policy: the CLI reads the file itself. Low impact, since the user names the file. packages/cli/src/run/run.ts:171-199

Expected: apply the file rules to the paths these routes use, or say next to the file rules and tool.use file policies that they only cover the built-in file tools.

Plugins

No response

OpenCode version

2.4.2

Steps to reproduce

Project /work (git repo) with secret/a.txt (dummy text) and an empty canary/; /outside/a.txt. Global ~/.config/opencode/opencode.json with a provider and model, plus the permissions given per step. MCP server where used: "mcp": {"servers": {"files": {"type": "local", "command": ["python3", "/home/me/files_server.py"], "codemode": false}}} (any stdio server with read(path) and write(path, content) tools).

  1. Shell:
    • [{"action": "read", "resource": "*", "effect": "allow"}, {"action": "read", "resource": "secret/*", "effect": "deny"}]. "Read /work/secret/a.txt with the read tool" -> "Permission denied: read". "Run cat /work/secret/a.txt" -> content returned.
    • [{"action": "edit", "resource": "canary/*", "effect": "ask"}]. "Run printf hi > /work/canary/a.txt" -> written.
    • No permissions; /etc/opencode/opencode.json with {"policies": [{"action": "tool.use", "resource": "read:secret/*", "effect": "deny"}]}. Read tool -> "Blocked by configuration policy"; cat /work/secret/a.txt -> content returned.
  2. MCP and Code Mode:
    • [{"action": "read", "resource": "secret/a.txt", "effect": "deny"}] and the MCP server. Read tool -> "Permission denied: read". "Call files_read with path /work/secret/a.txt" -> content returned. Same under the managed policy from step 1 instead.
    • [{"action": "external_directory", "resource": "*", "effect": "deny"}]. Read tool on /outside/a.txt -> "Permission denied: external_directory". "Call files_read with path /outside/a.txt" -> content returned.
    • [{"action": "edit", "resource": "*", "effect": "allow"}, {"action": "edit", "resource": "canary/*", "effect": "deny"}], MCP server without codemode: false. "Use execute to call tools.files.write({path: '/work/canary/b.txt', content: 'x'})" -> written.
  3. The rules from the first case of step 1. opencode run --standalone --file /work/secret/a.txt "summarize" -> the file text is in the request sent to the model.
Screenshot

No response

Operating System

No response

Terminal

No response

主要语言
TypeScript
星标
230k
派生
31.3k
平均合并
5 小时 32 分钟
30 天内合并 PR
453

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anomalyco/opencode 的其他 Issue

查看 anomalyco/opencode 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。