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

Ouverte
#67,050 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python, shell, typescript
Domaine
backend, cli, security

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
TypeScript
Étoiles
230k
Forks
31.3k
Merge moyen
5 h 32 min
PR mergées (30 j)
453

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de anomalyco/opencode

Toutes les issues de anomalyco/opencode

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.