Skip to content

[Discussion] 插件文件权限:隔离边界与设计方向 / Plugin file permission boundaries #168

Description

@Tioit-Wang

Summary / 摘要

插件已有文件能力,但没有一套能同时回答「用户看见什么、插件实际能碰什么、离 OS 隔离还差多少」的模型。
本 issue 只对齐设计方向,不排实现;具体来源导入见 #134,会话写入契约见 #169


现状 / Current state

能力 现状
插件私有数据 pi.plugin.getDataPath()plugins/data/<pluginId>
外部目录 pi.fs.requestDirectory():用户选目录,内存 grant,随插件进程结束
越界访问 Native consent:Deny / Allow once / Allow this session
路径范围 manifest.fsworkspace / userSelected + scope)
安全闸门 权限 ∩ containment ∩ deny-list ∩ scope(04-plugin-security.md §6)
未完成 capability sandbox:插件进程仍可 require("node:fs") / node:sqlite"(ADR 0008 D009)

pi.* 权限管的是 API,不是 进程。这是下面所有困局的根。


困局 / Dilemma

  1. 授权 ≠ 隔离
    对恶意插件,requestAccess / Always allow 可被 raw Node 绕过。若 UI 不说明,就是在误导用户。

  2. 「目录」答不好「文件型资源」
    用户真正要同意的是「读这个 SQLite 库」「读这个 PDF」,不是「读整个 ~/.zcode/cli/db」。目录 grant 过宽,单文件 grant 又撑不起解析器。

  3. 持久授权与 ADR 0088 冲突
    ADR 0088 §4:consent never more durable than the session,nothing is persisted。
    Always allow 必须显式取代该条,并配套查看 / 撤销 UI。

  4. 连续弹窗伤害体验
    批量操作会连环确认。需要单飞队列、同 target 合并、拒绝冷却,而不是简单多弹几次。

  5. 用户心智只有两类
    「插件自己的数据」和「其他文件」。现有 workspace / userSelected 是实现细节,不应作为第三种资源展示。


需要讨论收敛的点 / Open questions

  1. 信任分级
    bundled / 受信插件与 marketplace 第三方,能力是否相同?sandbox 前对外表述应是「用户同意 + 审计」还是别的?

  2. 资源分类
    是否确认用户可见只有 pluginData / otherworkspace / userSelected 降为路径解析细节。

  3. 结构化只读 API
    是否引入 pi.db.*(SQLite)、pi.document.*(PDF);还是受信插件继续用原生 Node([Feature] 支持从 ZCode 导入本地会话 / Add ZCode session import support #134 现行方案)。

  4. 授权生命周期
    once / process / persistent;persistent 是否本期做;撤销 UI 最小形态。

  5. 连续审批 UX
    单飞队列、同 target 合并、拒绝冷却;错误码是否引入 USER_DENIED(与 PERMISSION_DENIED 区分)。

  6. 不可绕过清单
    deny-list 与 host-reserved 必须继承现行规范,且 grant 不得绕过——是否有人反对。


非目标 / Non-goals

  • 不实现 ZCode 或任何具体来源插件。
  • 不开放 host SQLite、通用 SQL、任意 host RPC。
  • capability sandbox(D009)仍是独立长期项,本 issue 不替代它。

关联 / Related


English summary

Plugin file access exists today (requestDirectory, consent, manifest.fs, deny-list) but cannot honestly state what a grant means while raw Node remains reachable in the plugin process. This issue collects direction only: trust tiers, two user-visible resource kinds (pluginData / other), structured read-only APIs (pi.db.* / pi.document.*) vs native Node for trusted plugins, grant lifetimes (and whether to supersede ADR 0088 §4), consent UX for consecutive prompts, and a non-bypassable deny-list. Discussion first; no implementation here. Source importers (#134) and the session write contract (#169) are tracked separately.

Activity

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

    area: pluginsPlugin platform, MCP, and plugin APIsarea: securitySecrets, credentials, permissions, and security boundariesenhancementNew feature or requestquestionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions