fix(liveshare): give each refusal one identity across guard and tools
A path outside the granted workspace is FsError FS_SANDBOX_DENIED whether the guard or a confined tool refuses it, and a share that no longer allows writing is LiveshareForkDeniedError FORK_TOOL_NOT_PERMITTED like a lapsed fork permission. The module contract now describes the structured denial, and the refusal table follows the imports. Refs #7869
This commit is contained in:
1 parent
9b4b278b3e
commit
996ed36e07
14 files changed
+68
-43
No files matched your search
@@ -18,8 +18,8 @@
|
||||
en: 6b1346e73ab6eab9
|
||||
zh: 888cfc08c6bc8522
|
||||
/liveshare/constraining-a-shared-session:
|
||||
en: c336c48190726a6c
|
||||
zh: f4119a1156d75728
|
||||
en: 7fbb31bbc29817d6
|
||||
zh: 0a9542ab1d48a9e6
|
||||
/liveshare/viewer-states:
|
||||
en: b8bcb009e419fa25
|
||||
zh: 31c4662b52e99ea7
|
||||
@@ -38,7 +38,7 @@ Child tool guards recheck the share’s current mode, expiry, viewer admission,
|
||||
|
||||
Every share lets its viewer drive the *source* Session through the normal prompt path, and any share at either tier installs the bounded sandbox while it is active. `installSourceSessionAccess` registers a confined replacement for every view-surface tool the deployment ships in that Session's own scope, and bounded `edit` and `write` replacements whenever any share over the Session allows writing. The layer is mounted on the Session, but it confines only the turns a share viewer starts: `agent/pre-step` records, in Host memory, whether a turn's admitted input names a share viewer, and the guard and the replacements read that answer for every execution of that turn. A viewer-started turn runs those replacements and nothing else; a turn the owner starts keeps the Session's own tools, including `bash` and its unrestricted filesystem tools. The answer is decided when the turn is admitted and never written to the Session log; a restart recomputes it from the next admitted step. An owner's steering input inside a viewer's turn stays confined with it. Stopping every share over the Session disposes the layer, which restores the Session's own tools; narrowing the last write share to `view` re-installs the read-only layer.
|
||||
|
||||
The installation reports whether the source Session is actually confined. A deployment without the `read` tool, or a scope that refuses that replacement's registration, leaves the guard in place and reports the refusal; a tool whose own replacement failed stays refused while the rest of the surface runs, and the reader refuses the prompt with `source-write-unavailable`: no viewer-started turn of a shared Session is driven against the owner's own tools because a limit could not be installed. A guard refusal records `LiveshareForkDeniedError` with a `FORK_*` code on the failed call, and a confined file tool refuses a target outside the grant with `FsError` `FS_SANDBOX_DENIED`.
|
||||
The installation reports whether the source Session is actually confined. A deployment without the `read` tool, or a scope that refuses that replacement's registration, leaves the guard in place and reports the refusal; a tool whose own replacement failed stays refused while the rest of the surface runs, and the reader refuses the prompt with `source-write-unavailable`: no viewer-started turn of a shared Session is driven against the owner's own tools because a limit could not be installed. A refusal records the same identity whether the guard or a confined tool decides: a path outside the grant is `FsError` `FS_SANDBOX_DENIED`, and other grant refusals are `LiveshareForkDeniedError` with a `FORK_*` code.
|
||||
|
||||
Each operation re-reads the Relay grants of the shares that keep the Session drivable, and each reading is synchronous with the tool call it authorizes, so input queued past the grant that admitted it cannot act on that stale admission. The layer is per Session: several shares over one Session share the one installation, a share that carries several source Sessions installs one layer per source, and a share that narrows or ends changes what the layer permits — its bounded write is refused once no active share may write, and the layer is released once no share is left. The Host does not attribute a running turn to the viewer that admitted it, so ending one share's grant stops the Session's running turn rather than singling out that viewer's work; the in-memory viewer-start marker only decides which tool surface that turn runs.
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ fork 创建查看者拥有的新会话,源会话保持不变。Fork 授权检
|
||||
|
||||
每个分享都让它的 viewer 通过正常 prompt 路径驱动*源*会话,任一档位的分享在活跃期间都会安装有界沙箱。`installSourceSessionAccess` 在该会话自身作用域中为部署提供的每个读取与检索面工具注册受限替代,并在任一同会话分享允许写入时再注册有界 `edit` 与 `write` 替代。执行层挂在会话上,但只约束分享查看者发起的轮次:`agent/pre-step` 在 Host 内存中记录一个轮次的已准入输入是否带有 share-viewer principal,守卫与替代定义对该轮次的每次执行读取这一结论。查看者发起的轮次只能运行这些替代定义;所有者自己发起的轮次保留会话原生工具,包括 `bash` 与不受限的文件工具。该结论在轮次准入时确定,不写入会话日志;重启后从下一个准入步骤重新计算。所有者在查看者轮次中追加的输入仍留在该受限轮次内。该会话的所有分享停止后执行层被释放,会话恢复自己的工具;最后一个可写分享降为 `view` 时重装只读层。
|
||||
|
||||
安装结果报告源会话是否真正受到限制。没有 `read` 工具的部署或拒绝该替代注册的作用域会保留守卫并报告失败;某个工具自己的替代注册失败时,该工具保持拒绝,其余工具面照常运行。读取处理器以 `source-write-unavailable` 拒绝消息:限制未安装时,共享会话中查看者发起的轮次不会用所有者工具驱动。守卫拒绝会在失败调用上记录 `LiveshareForkDeniedError` 及 `FORK_*` code,受限文件工具以 `FsError` `FS_SANDBOX_DENIED` 拒绝授权范围外的目标。
|
||||
安装结果报告源会话是否真正受到限制。没有 `read` 工具的部署或拒绝该替代注册的作用域会保留守卫并报告失败;某个工具自己的替代注册失败时,该工具保持拒绝,其余工具面照常运行。读取处理器以 `source-write-unavailable` 拒绝消息:限制未安装时,共享会话中查看者发起的轮次不会用所有者工具驱动。无论由守卫还是受限工具判定,拒绝都记录同一标识:授权范围外的路径为 `FsError` `FS_SANDBOX_DENIED`,其他授权拒绝为 `LiveshareForkDeniedError` 及 `FORK_*` code。
|
||||
|
||||
每次操作都会重新读取维持该会话可驱动的分享的 Relay 授权,且读取与其授权的工具调用在同一同步步骤内完成,因此排队超过其准入授权的输入无法凭过期准入行动。执行层按会话安装:同一会话的多个分享共用一个安装,一条携带多个源会话的分享则为每个源会话各安装一层;分享收窄或结束时改变该层允许的操作——没有任何活跃分享可写时拒绝有界写入,会话不再有分享时释放执行层。Host 不把正在运行的轮次归属给准入它的查看者,因此结束某个分享的授权会停止该会话正在运行的轮次,而不是只挑出该查看者的工作;内存中的查看者轮次标记只决定该轮次运行哪套工具面。
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
en: 2052fd7c4e9c3f98
|
||||
zh: 5ef2ac5ad9ec7990
|
||||
/deepseek-ai-dsh-experimental-liveshare/understand-the-implementation:
|
||||
en: d0a82a564982ae39
|
||||
zh: 83ff49b7b0db4f20
|
||||
en: 37d649ff38fca348
|
||||
zh: c73e526eac1e3778
|
||||
/deepseek-ai-dsh-experimental-liveshare/further-exploration:
|
||||
en: 0570170704bbe5b6
|
||||
zh: 832f86024b26e5b3
|
||||
|
||||
@@ -109,7 +109,7 @@ The Owner Gateway decides each call on the Session and Workspace it names and re
|
||||
|
||||
The viewer page is the Owner's own Web shell. The Liveshare server fetches the Owner's rendered index document through an `asset` read and places the carrier script from [viewer-carrier.ts](../liveshare-protocol/src/viewer-carrier.ts) first in it. Shell assets, client plugin bundles, and the three exact top-level files the index references against the document base — `manifest.webmanifest`, `favicon.svg`, and `favicon-dark.svg` — arrive through the same read, from the Owner's frontend reader and client module registry, so the page runs every Owner plugin at the Owner's version. Source maps are refused on every asset path, and that check is the authoritative one: an `asset` read forwarded through the Liveshare server arrives here unread, so the Liveshare server's own same-named rule covers its page-resource route only. The served document also drops its manifest link, which a browser would otherwise fetch without credentials. The carrier converts Connection calls and Gateway streams into `POST {base}/__share/rpc` requests, and forwards the read-only page-origin owner routes the Liveshare server cannot answer — `/open-in-app/apps` and `/api/present.host` — through that channel instead of leaving them to the Liveshare server's tail. The Liveshare server supplies the authenticated actor outside the opaque body. The Owner's read handler dispatches each reader's calls and streams into its own Connection and Gateway as one Peer per share and reader, whose `share-viewer` principal carries the share and the server-asserted identity. The Gateway decides that Peer's calls, and the Session notifications it forwards to it, through [`dsh-api-remote-access`](../../api/remote-access/README.md) from the `share-viewer` policy this package registers: a served reader holds read roles on the shared Session, its own forks, and the Workspaces holding them, fork and write roles whose conditions apply the share's tier and its own fork switch, and nothing else; attachment upload rides the read roles. The read handler keeps the share-lifecycle refusals, Liveshare server authority refresh, cold Session preparation, and fork orchestration, reads the policy's write rules before it prepares or dispatches a prompt or stop, and disposes a reader's Peer when its grant ends, the share stops or expires, or a re-check refuses it. Preparing a share's source Session also starts when a reader asks for its page or opens a stream, so a host that restarted before that Session's agent was live still gains the actions it drives with; a share whose Session cannot be confined states that instead of the read-only fact. This package's browser face mounts the viewer surfaces when the carrier's `__DSH_LIVESHARE_VIEWER__` global is present and the Share action otherwise. The served index assigns the reader's own access snapshot to the global that every index sets to the owner baseline, and the page then follows the reader's `remoteAccess/follow` snapshot; CSS hiding is not authorization.
|
||||
|
||||
Fork requests bind the actor, share, source, operation identity, and completed prefix. A durable reservation and the recorded child let a retry of a recorded operation replay the same child; the owner's `SessionForkRequest` mints the child id, so a request interrupted after the child was created but before it was recorded forks again. Registry mutations are asynchronous and resolve only after locked read-modify-write and atomic publication; callers must await reservation, recording, and revocation. Cold activation uses the Host’s ordinary Agent lookup, with serial `agent/created` enforcement before queued input can run, not a Remote `session/prepare` endpoint. The child scope retains one fail-closed guard; reconnection replaces its enforcement installation, and releasing an old installation cannot remove its successor. Guard refusals record `LiveshareForkDeniedError` with a `FORK_*` code from [fork-errors.ts](src/host/fork-errors.ts), such as `FORK_TOOL_NOT_PERMITTED` or `FORK_PATH_OUTSIDE_WORKSPACE`; inside the confined replacements, a target outside the grant or a share that no longer allows writing fails with `FsError` `FS_SANDBOX_DENIED`, arguments the replacement cannot confine fail with `ToolArgsError`, and a tool whose permission lapsed fails with `LiveshareForkDeniedError` `FORK_TOOL_NOT_PERMITTED`.
|
||||
Fork requests bind the actor, share, source, operation identity, and completed prefix. A durable reservation and the recorded child let a retry of a recorded operation replay the same child; the owner's `SessionForkRequest` mints the child id, so a request interrupted after the child was created but before it was recorded forks again. Registry mutations are asynchronous and resolve only after locked read-modify-write and atomic publication; callers must await reservation, recording, and revocation. Cold activation uses the Host’s ordinary Agent lookup, with serial `agent/created` enforcement before queued input can run, not a Remote `session/prepare` endpoint. The child scope retains one fail-closed guard; reconnection replaces its enforcement installation, and releasing an old installation cannot remove its successor. Refusals carry one identity per condition whether the guard or a confined replacement decides: a path outside the granted workspace is `FsError` `FS_SANDBOX_DENIED`; a tool, or a write, that the fork's limit or the share's current grant does not admit is `LiveshareForkDeniedError` `FORK_TOOL_NOT_PERMITTED`; the guard's other refusals use the remaining `FORK_*` codes in [fork-errors.ts](src/host/fork-errors.ts); and arguments a replacement cannot confine fail with `ToolArgsError`.
|
||||
|
||||
A reader's prompt reaches the Session as a `user-rpc` message whose `source.principal` names that reader, and the pre-step re-checks every entering message's viewer against the Relay's admission before it reaches the model. Execution is confined per turn: while any share over the Session is active, a turn whose admitted input names a share viewer runs the Host's confined replacements for the read and search surface (`read`, `read_image`, `glob`, `grep`, `present`), keeps the deployment's own definitions of the tools with no local file effect (`todo_write`, `skill`, `web_search`, `web_fetch`), admits the PTC transport `run_code` from the selected executor, and, when some share may write, its bounded `edit` and `write`. Every other tool is refused to that turn, and every path a permitted call declares is resolved and checked against the granted root. An owner-started turn keeps the Session's native tools until the last share stops or expires. The turn decision is Host memory only, recomputed for each turn and never appended to the Session log. Each operation re-reads the shares' current Relay grants and checks the resolved target against the granted root. A reader's stop is dispatched through the Gateway like a prompt: the `share-viewer` policy admits it while the share's tier is established and the Session is confined, and the owner's own Session controller stops whatever turn the Session is running, including one the owner started. Reads and writes preserve the normal write-observation policy. See the [LiveShare subsystem](../../../docs/subsystems/liveshare.md) for the execution rules.
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ Owner Gateway 按调用指明的 Session 与工作区判定每次调用,并拒
|
||||
|
||||
查看页就是 Owner 自己的 Web shell。Liveshare 服务端通过 `asset` 读取取得 Owner 渲染好的 index 文档,并把 [viewer-carrier.ts](../liveshare-protocol/src/viewer-carrier.ts) 生成的载体脚本放在文档最前面。Shell 资源、客户端插件 bundle,以及 index 相对文档基准引用的三个确切顶层文件(`manifest.webmanifest`、`favicon.svg`、`favicon-dark.svg`)都经同一读取取得,来自 Owner 的前端读取服务和客户端模块注册表,因此页面以 Owner 的版本运行 Owner 的全部插件。任何 asset 路径上的 source map 都被拒绝,且该判定是权威的:经 Liveshare 服务端转发的 `asset` 读取会原样到达这里,因此 Liveshare 服务端侧的同名规则只覆盖它自己的页面资源路由;被服务的文档还会去掉自己的 manifest 链接,否则浏览器会不带凭据地抓取它。载体把 Connection 调用和 Gateway 流转换为 `POST {base}/__share/rpc` 请求,并把 Liveshare 服务端无法作答的只读页面源 Owner 路由(`/open-in-app/apps` 与 `/api/present.host`)也经该通道转发,而不是留给 Liveshare 服务端尾部。Liveshare 服务端在不透明请求体之外提供已认证主体。Owner 读取处理器把每位读者的调用和流以「每个分享、每位读者一个 Peer」分派进自己的 Connection 与 Gateway,该 Peer 的 `share-viewer` principal 携带分享与服务端断言的身份。Gateway 依据本包注册的 `share-viewer` 策略,经 [`dsh-api-remote-access`](../../api/remote-access/README.zh.md) 判定该 Peer 的调用以及转发给它的会话通知:受服务的读者持有共享会话、其自己的 fork 及包含它们的工作区上的读取角色,持有条件按分享档位与其自身 fork 开关判定的 fork 与写入角色,此外别无授权;附件上传随读取角色生效。读取处理器保留分享生命周期拒绝、Liveshare 服务端授权刷新、冷会话准备和 fork 编排,在准备或分派提示词与停止之前读取策略的写入规则,并在授权结束、分享停止或过期、或复检拒绝时释放读者的 Peer。读者索取页面或打开流时也会开始准备该分享的源会话,因此宿主重启时该会话的 agent 尚未存活也能补上驱动所需的层;无法被 confine 的分享会如实说明该状态,而不再声明只读。存在载体写入的 `__DSH_LIVESHARE_VIEWER__` 全局变量时,本包的浏览器端挂载查看页界面,否则挂载分享操作。读者收到的 index 把读者自己的访问快照赋给每个 index 设为所有者基线的同一全局变量,页面随后跟随读者的 `remoteAccess/follow` 快照;CSS 隐藏不构成授权。
|
||||
|
||||
Fork 请求绑定主体、分享、源会话、操作身份和已完成前缀。持久化预留记录与已记录的分叉会话使重试已记录的操作时重放同一分叉会话;owner 的 `SessionForkRequest` 自己生成分叉会话 id,因此在分叉会话已创建、但尚未记录时中断的请求会再次 fork。注册表变更为异步操作,仅在加锁的读取、修改与原子发布后完成;调用方必须等待预留、记录与撤销。冷态激活使用 Host 常规 Agent lookup,由串行 `agent/created` 在排队输入运行前安装限制,不使用 Remote `session/prepare` 端点。分叉会话作用域保留单个默认拒绝的 guard;重连替换其限制安装,释放旧安装不会移除继任。guard 拒绝记录 `LiveshareForkDeniedError` 及 [fork-errors.ts](src/host/fork-errors.ts) 中的 `FORK_*` code,例如 `FORK_TOOL_NOT_PERMITTED` 或 `FORK_PATH_OUTSIDE_WORKSPACE`;在受限替换工具内,授权范围外的目标或已不允许写入的分享以 `FsError` `FS_SANDBOX_DENIED` 失败,替换工具无法限制的参数以 `ToolArgsError` 失败,权限已失效的工具以 `LiveshareForkDeniedError` `FORK_TOOL_NOT_PERMITTED` 失败。
|
||||
Fork 请求绑定主体、分享、源会话、操作身份和已完成前缀。持久化预留记录与已记录的分叉会话使重试已记录的操作时重放同一分叉会话;owner 的 `SessionForkRequest` 自己生成分叉会话 id,因此在分叉会话已创建、但尚未记录时中断的请求会再次 fork。注册表变更为异步操作,仅在加锁的读取、修改与原子发布后完成;调用方必须等待预留、记录与撤销。冷态激活使用 Host 常规 Agent lookup,由串行 `agent/created` 在排队输入运行前安装限制,不使用 Remote `session/prepare` 端点。分叉会话作用域保留单个默认拒绝的 guard;重连替换其限制安装,释放旧安装不会移除继任。无论由 guard 还是受限替换工具判定,同一种拒绝只有一个标识:授权工作区外的路径为 `FsError` `FS_SANDBOX_DENIED`;fork 的限制或分享当前授权不允许的工具或写入为 `LiveshareForkDeniedError` `FORK_TOOL_NOT_PERMITTED`;guard 的其他拒绝使用 [fork-errors.ts](src/host/fork-errors.ts) 中其余的 `FORK_*` code;替换工具无法限制的参数以 `ToolArgsError` 失败。
|
||||
|
||||
读者的提示词以 `user-rpc` 消息进入会话,其 `source.principal` 指明该读者;pre-step 在每条进入消息到达模型前,按 Relay 的准入重新检查其查看者。执行按轮次受限:只要有分享处于活跃状态,已准入输入中带有 share-viewer principal 的轮次就运行 Host 挂载的读取与检索面(`read`、`read_image`、`glob`、`grep`、`present`)受限替代、保留无本地文件副作用工具(`todo_write`、`skill`、`web_search`、`web_fetch`)的原生定义、放行选定执行器提供的 PTC 传输工具 `run_code`,以及(当某个分享允许写入时)有界 `edit` 与 `write`。其余所有工具对该轮次一律拒绝,且每次允许的调用声明的每个路径都会解析并按获授根目录检查。所有者自己发起的轮次保留会话原生工具,直到最后一个分享停止或过期。该轮次判定只存在于 Host 内存,按轮次重算,不写入会话日志。每次操作都会重新读取分享当前的 Relay 授权,并按获授根目录检查解析后的目标。读者的停止与提示词一样经 Gateway 分派:`share-viewer` 策略在分享档位确立且会话受沙箱限制时放行,随后由所有者自己的会话控制器停止该会话当前运行的轮次,包括所有者发起的轮次。读写保留正常写入观察策略。执行规则见 [LiveShare 子系统](../../../docs/subsystems/liveshare.zh.md)。
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ export function installSourceSessionAccess(target: SourceSessionAccess): SourceS
|
||||
await target.refreshAuthorization?.()
|
||||
// The Session's current shares decide, not the tier the layer was installed for: a share can
|
||||
// narrow to view while this layer stays mounted.
|
||||
if (!gate.mayWrite()) throw new FsError('this share does not allow writing this Session', 'FS_SANDBOX_DENIED')
|
||||
if (!gate.mayWrite()) throw new LiveshareForkDeniedError('this share does not allow writing this Session', 'FORK_TOOL_NOT_PERMITTED')
|
||||
const input = isRecord(args) ? args : {}
|
||||
const requested = input.file_path
|
||||
const content = input.content
|
||||
@@ -282,7 +282,7 @@ export function installSourceSessionAccess(target: SourceSessionAccess): SourceS
|
||||
const policy = target.resolvePolicy()
|
||||
// The shares can narrow while the intent awaited: the final refresh above reads the new state, so
|
||||
// ask the gate again before anything is written instead of trusting the earlier verdict.
|
||||
if (!gate.mayWrite()) throw new FsError('this share does not allow writing this Session', 'FS_SANDBOX_DENIED')
|
||||
if (!gate.mayWrite()) throw new LiveshareForkDeniedError('this share does not allow writing this Session', 'FORK_TOOL_NOT_PERMITTED')
|
||||
const outcome = await fs.writeText(candidate, content, intent, exec.signal, policy)
|
||||
// The published version is this caller's own next basis, exactly as the shipped write records it:
|
||||
// without it a second write of the same file would meet a policy that saw nothing since the read.
|
||||
@@ -302,7 +302,7 @@ export function installSourceSessionAccess(target: SourceSessionAccess): SourceS
|
||||
register(FORK_EDIT_TOOL, deploymentEdit, async (args, exec) => {
|
||||
if (!confined(exec)) return await deploymentEdit.execute(args, exec)
|
||||
await target.refreshAuthorization?.()
|
||||
if (!gate.mayWrite()) throw new FsError('this share does not allow writing this Session', 'FS_SANDBOX_DENIED')
|
||||
if (!gate.mayWrite()) throw new LiveshareForkDeniedError('this share does not allow writing this Session', 'FORK_TOOL_NOT_PERMITTED')
|
||||
const edit = sharedEditArguments(args)
|
||||
if (edit === undefined) {
|
||||
throw new ToolArgsError(['a shared session may only edit a named file by replacing non-empty text'])
|
||||
@@ -314,7 +314,7 @@ export function installSourceSessionAccess(target: SourceSessionAccess): SourceS
|
||||
const intent = await context.waterfall('fs/edit-intent', candidate, exec, () => undefined)
|
||||
await target.refreshAuthorization?.()
|
||||
const policy = target.resolvePolicy()
|
||||
if (!gate.mayWrite()) throw new FsError('this share does not allow writing this Session', 'FS_SANDBOX_DENIED')
|
||||
if (!gate.mayWrite()) throw new LiveshareForkDeniedError('this share does not allow writing this Session', 'FORK_TOOL_NOT_PERMITTED')
|
||||
const outcome = await fs.editText(
|
||||
candidate,
|
||||
{ oldString: edit.oldString, newString: edit.newString, replaceAll: edit.replaceAll },
|
||||
|
||||
@@ -7,12 +7,12 @@ import { HarnessError } from '@deepseek-ai/dsh-error'
|
||||
* - `FORK_LIMITS_UNINSTALLED` — no execution limit is installed for the calling fork; nothing it runs can be vouched for.
|
||||
* - `FORK_CHILD_UNKNOWN` — the call cannot be attributed to a fork child.
|
||||
* - `FORK_CHILD_MISMATCH` — the call reaches into a Session other than the fork it came from.
|
||||
* - `FORK_TOOL_NOT_PERMITTED` — the fork's limit or the share's current grant does not admit the tool.
|
||||
* - `FORK_TOOL_NOT_PERMITTED` — the fork's limit or the share's current grant does not admit the tool or its write.
|
||||
* - `FORK_PATHS_UNKNOWN` — the tool's filesystem effect could not be established, so it could not be authorized.
|
||||
* - `FORK_PATH_OUTSIDE_WORKSPACE` — a path leaves the workspace the fork was granted.
|
||||
*
|
||||
* The model should not retry a refused call unchanged; only `FORK_PATH_OUTSIDE_WORKSPACE` and
|
||||
* `FORK_PATHS_UNKNOWN` can succeed with other arguments.
|
||||
* The model should not retry a refused call unchanged; only `FORK_PATHS_UNKNOWN` can succeed with other arguments.
|
||||
* A path outside the granted workspace is a filesystem refusal instead: the guard and the confined tools both
|
||||
* record it as `FsError` with `FS_SANDBOX_DENIED`.
|
||||
*/
|
||||
export const LIVESHARE_FORK_DENIED_CODES = [
|
||||
'FORK_LIMITS_UNINSTALLED',
|
||||
@@ -20,16 +20,15 @@ export const LIVESHARE_FORK_DENIED_CODES = [
|
||||
'FORK_CHILD_MISMATCH',
|
||||
'FORK_TOOL_NOT_PERMITTED',
|
||||
'FORK_PATHS_UNKNOWN',
|
||||
'FORK_PATH_OUTSIDE_WORKSPACE',
|
||||
] as const
|
||||
|
||||
/** One code from {@link LIVESHARE_FORK_DENIED_CODES}. */
|
||||
export type LiveshareForkDeniedCode = typeof LIVESHARE_FORK_DENIED_CODES[number]
|
||||
|
||||
/** Error name recorded on every liveshare fork refusal, thrown or returned by a guard. */
|
||||
/** Error name recorded on every liveshare grant refusal, thrown or returned by a guard. */
|
||||
export const LIVESHARE_FORK_DENIED_ERROR_NAME = 'LiveshareForkDeniedError'
|
||||
|
||||
/** A tool use the fork's execution limit refused inside a tool body. */
|
||||
/** A tool use the fork's execution limit or the share's grant refused inside a tool body. */
|
||||
export class LiveshareForkDeniedError extends HarnessError {
|
||||
override readonly code: LiveshareForkDeniedCode
|
||||
|
||||
@@ -47,11 +46,13 @@ export class LiveshareForkDeniedError extends HarnessError {
|
||||
/** A guard refusal: the model-facing reason and the structured identity the tool runtime records. */
|
||||
export interface ForkToolDenial {
|
||||
readonly reason: string
|
||||
readonly info: { readonly name: typeof LIVESHARE_FORK_DENIED_ERROR_NAME; readonly code: LiveshareForkDeniedCode }
|
||||
readonly info:
|
||||
| { readonly name: typeof LIVESHARE_FORK_DENIED_ERROR_NAME; readonly code: LiveshareForkDeniedCode }
|
||||
| { readonly name: 'FsError'; readonly code: 'FS_SANDBOX_DENIED' }
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a guard refusal.
|
||||
* Build a guard refusal of the grant.
|
||||
* @param reason - Model-facing refusal.
|
||||
* @param code - The refused condition.
|
||||
* @returns The refusal in the structure `ToolGuard` denials take.
|
||||
@@ -59,3 +60,12 @@ export interface ForkToolDenial {
|
||||
export function forkToolDenial(reason: string, code: LiveshareForkDeniedCode): ForkToolDenial {
|
||||
return { reason, info: { name: LIVESHARE_FORK_DENIED_ERROR_NAME, code } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a guard refusal of a path outside the granted workspace, with the identity the confined tools throw.
|
||||
* @param reason - Model-facing refusal.
|
||||
* @returns The refusal in the structure `ToolGuard` denials take.
|
||||
*/
|
||||
export function outsideWorkspaceDenial(reason: string): ForkToolDenial {
|
||||
return { reason, info: { name: 'FsError', code: 'FS_SANDBOX_DENIED' } }
|
||||
}
|
||||
@@ -3,23 +3,22 @@
|
||||
*
|
||||
* It is registered on one child's context, so it speaks for that child alone: it refuses anything the
|
||||
* ceiling does not permit, and it decides paths through the host's real filesystem authorization
|
||||
* rather than by comparing strings or trusting a tool name. The return value is the reason string the
|
||||
* tool runtime expects, and a refusal is monotonic — nothing downstream can turn it back into an
|
||||
* allow.
|
||||
* rather than by comparing strings or trusting a tool name. A refusal is a `ToolGuard` denial: the
|
||||
* model-facing reason with the structured error identity the tool runtime records, and it is
|
||||
* monotonic — nothing downstream can turn it back into an allow.
|
||||
*/
|
||||
|
||||
import { forkToolDecision, type ForkToolDecision, type ForkToolRefusal } from './fork-ceiling.ts'
|
||||
import { forkToolDenial, type ForkToolDenial, type LiveshareForkDeniedCode } from './fork-errors.ts'
|
||||
import { forkToolDenial, outsideWorkspaceDenial, type ForkToolDenial, type LiveshareForkDeniedCode } from './fork-errors.ts'
|
||||
import type { ForkCeiling } from './fork-policy.ts'
|
||||
|
||||
/** The recorded code for each refusal a fork tool decision names. */
|
||||
const REFUSAL_CODES: Readonly<Record<ForkToolRefusal, LiveshareForkDeniedCode>> = {
|
||||
/** The recorded code for each grant refusal a fork tool decision names; a path outside the workspace is a filesystem refusal. */
|
||||
const REFUSAL_CODES: Readonly<Record<Exclude<ForkToolRefusal, 'fork-path-outside-workspace'>, LiveshareForkDeniedCode>> = {
|
||||
'fork-ceiling-uninstalled': 'FORK_LIMITS_UNINSTALLED',
|
||||
'fork-tool-not-permitted': 'FORK_TOOL_NOT_PERMITTED',
|
||||
'fork-child-mismatch': 'FORK_CHILD_MISMATCH',
|
||||
'fork-path-outside-workspace': 'FORK_PATH_OUTSIDE_WORKSPACE',
|
||||
'fork-paths-unknown': 'FORK_PATHS_UNKNOWN',
|
||||
}
|
||||
import type { ForkCeiling } from './fork-policy.ts'
|
||||
|
||||
/** One tool execution as the runtime presents it to a guard. */
|
||||
export interface ForkToolExecution {
|
||||
@@ -175,7 +174,10 @@ export function forkToolGuard(
|
||||
...describe(execution),
|
||||
...(execution.token === undefined ? {} : { token: execution.token }),
|
||||
}, ports)
|
||||
return decision.ok ? undefined : forkToolDenial(decision.message, REFUSAL_CODES[decision.code])
|
||||
if (decision.ok) return undefined
|
||||
return decision.code === 'fork-path-outside-workspace'
|
||||
? outsideWorkspaceDenial(decision.message)
|
||||
: forkToolDenial(decision.message, REFUSAL_CODES[decision.code])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,3 +14,15 @@ export function denial(reason: string | RegExp, code: LiveshareForkDeniedCode):
|
||||
info: { name: 'LiveshareForkDeniedError', code },
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a guard refusal of a path outside the granted workspace.
|
||||
* @param reason - Text the model-facing reason contains, or a pattern it matches.
|
||||
* @returns An asymmetric matcher for `toEqual`.
|
||||
*/
|
||||
export function outsideDenial(reason: string | RegExp): unknown {
|
||||
return {
|
||||
reason: (typeof reason === 'string' ? expect.stringContaining(reason) : expect.stringMatching(reason)) as string,
|
||||
info: { name: 'FsError', code: 'FS_SANDBOX_DENIED' },
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
preflightForkChild,
|
||||
} from '../src/host/fork-enforcement.ts'
|
||||
import type { ForkEnforcementFailure } from '../src/host/fork-enforcement.ts'
|
||||
import { denial } from './fork-denial.ts'
|
||||
import { denial, outsideDenial } from './fork-denial.ts'
|
||||
import type { ForkToolDenial } from '../src/host/fork-errors.ts'
|
||||
|
||||
interface RegisteredTool {
|
||||
@@ -243,7 +243,7 @@ describe('confined fork tools', () => {
|
||||
|
||||
h.target.authorized = () => true
|
||||
expect(guard?.({ name: 'read', arguments: { file_path: 'inside.ts' }, agent: { id: 'child-1' } }))
|
||||
.toEqual(denial('may only read inside the workspace', 'FORK_PATH_OUTSIDE_WORKSPACE'))
|
||||
.toEqual(outsideDenial('may only read inside the workspace'))
|
||||
|
||||
// A definition visible from both registries is trusted even though this host did not install it.
|
||||
const visible = harness({ read })
|
||||
@@ -251,7 +251,7 @@ describe('confined fork tools', () => {
|
||||
visible.forks.enforcedCeiling.mockReturnValue(READ_ONLY_FORK_CEILING)
|
||||
const visibleGuard = visible.guard()
|
||||
expect(visibleGuard?.({ name: 'read', arguments: { file_path: 'inside.ts' }, agent: { id: 'child-1' } }))
|
||||
.toEqual(denial('may only read inside the workspace', 'FORK_PATH_OUTSIDE_WORKSPACE'))
|
||||
.toEqual(outsideDenial('may only read inside the workspace'))
|
||||
expect(visibleGuard?.({ name: 'write', arguments: {}, agent: { id: 'child-1' } }))
|
||||
.toEqual(denial('may not use write', 'FORK_TOOL_NOT_PERMITTED'))
|
||||
|
||||
@@ -275,7 +275,7 @@ describe('confined fork tools', () => {
|
||||
((value: Record<string, unknown>, next: () => unknown) => Promise<unknown>) | undefined
|
||||
await preExecute?.({ token, arguments: { file_path: 'inside.ts' }, agent: { id: 'child-1' } }, () => 'next')
|
||||
expect(h.guard()?.({ name: 'read', arguments: { file_path: 'inside.ts' }, agent: { id: 'child-1' }, token }))
|
||||
.toEqual(denial('may only read inside the workspace', 'FORK_PATH_OUTSIDE_WORKSPACE'))
|
||||
.toEqual(outsideDenial('may only read inside the workspace'))
|
||||
})
|
||||
|
||||
it('admits the PTC transport for a fork child while nested calls stay separately judged', () => {
|
||||
@@ -692,12 +692,12 @@ describe('source-session sandbox', () => {
|
||||
const narrowing = sourceHarness({ tools: ['read', 'write'], writeGate: { mayWrite: vi.fn().mockReturnValueOnce(true).mockReturnValue(false) } })
|
||||
expect(installSourceSessionAccess(narrowing.target as never).writeConfined).toBe(true)
|
||||
await expect(narrowing.installed.get('write')!.execute({ file_path: 'inside.ts', content: 'x' }, { signal: undefined }))
|
||||
.rejects.toMatchObject({ name: 'FsError', code: 'FS_SANDBOX_DENIED', message: expect.stringContaining('does not allow writing') as string })
|
||||
.rejects.toMatchObject({ name: 'LiveshareForkDeniedError', code: 'FORK_TOOL_NOT_PERMITTED', message: expect.stringContaining('does not allow writing') as string })
|
||||
|
||||
const blocked = sourceHarness({ tools: ['read', 'write'], writeGate: { mayWrite: () => false } })
|
||||
installSourceSessionAccess(blocked.target as never)
|
||||
await expect(blocked.installed.get('write')!.execute({ file_path: 'inside.ts', content: 'x' }, { signal: undefined }))
|
||||
.rejects.toMatchObject({ name: 'FsError', code: 'FS_SANDBOX_DENIED', message: expect.stringContaining('does not allow writing') as string })
|
||||
.rejects.toMatchObject({ name: 'LiveshareForkDeniedError', code: 'FORK_TOOL_NOT_PERMITTED', message: expect.stringContaining('does not allow writing') as string })
|
||||
|
||||
h.target.write = { mayWrite: () => true }
|
||||
const result = await confined.execute({ file_path: 'inside.ts', content: 'hello' }, { signal: undefined })
|
||||
@@ -743,7 +743,7 @@ describe('source-session sandbox', () => {
|
||||
installSourceSessionAccess(closedEdit.target as never)
|
||||
await expect(closedEdit.installed.get('edit')!.execute({
|
||||
file_path: 'inside.ts', old_string: 'a', new_string: 'b',
|
||||
}, { signal: undefined })).rejects.toMatchObject({ name: 'FsError', code: 'FS_SANDBOX_DENIED', message: expect.stringContaining('does not allow writing') as string })
|
||||
}, { signal: undefined })).rejects.toMatchObject({ name: 'LiveshareForkDeniedError', code: 'FORK_TOOL_NOT_PERMITTED', message: expect.stringContaining('does not allow writing') as string })
|
||||
// The replacement's own argument check refuses arguments it cannot read.
|
||||
await expect(edit.execute('not a record', { signal: undefined })).rejects.toMatchObject({ name: 'ToolArgsError', code: 'INVALID_ARGS', message: expect.stringContaining('replacing non-empty text') as string })
|
||||
|
||||
@@ -755,7 +755,7 @@ describe('source-session sandbox', () => {
|
||||
installSourceSessionAccess(narrowing.target as never)
|
||||
await expect(narrowing.installed.get('edit')!.execute({
|
||||
file_path: 'inside.ts', old_string: 'a', new_string: 'b',
|
||||
}, { signal: undefined })).rejects.toMatchObject({ name: 'FsError', code: 'FS_SANDBOX_DENIED', message: expect.stringContaining('does not allow writing') as string })
|
||||
}, { signal: undefined })).rejects.toMatchObject({ name: 'LiveshareForkDeniedError', code: 'FORK_TOOL_NOT_PERMITTED', message: expect.stringContaining('does not allow writing') as string })
|
||||
expect(narrowing.fs.editText).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
import { ForkRegistry } from '../src/host/fork-registry.ts'
|
||||
import { SHARED_TOOL_PROFILES } from '../src/host/shared-tools.ts'
|
||||
import type { ForkToolExecution } from '../src/host/fork-tool-guard.ts'
|
||||
import { denial } from './fork-denial.ts'
|
||||
import { denial, outsideDenial } from './fork-denial.ts'
|
||||
import type { ForkToolDenial } from '../src/host/fork-errors.ts'
|
||||
|
||||
const child = 'child-1'
|
||||
@@ -338,12 +338,12 @@ describe('fork enforcement wiring', () => {
|
||||
agent: { id: child },
|
||||
token: Symbol('another-execution'),
|
||||
}
|
||||
expect(captured.guard?.(other)).toEqual(denial(/workspace/u, 'FORK_PATH_OUTSIDE_WORKSPACE'))
|
||||
expect(captured.guard?.(other)).toEqual(outsideDenial(/workspace/u))
|
||||
|
||||
// A path the resolution did not confirm is refused for that same execution.
|
||||
const outside: ForkToolExecution = { ...inside, arguments: { file_path: '/etc/passwd' } }
|
||||
await captured.preExecute?.(outside, () => Promise.resolve({ kind: 'allow' }))
|
||||
expect(captured.guard?.(outside)).toEqual(denial(/workspace/u, 'FORK_PATH_OUTSIDE_WORKSPACE'))
|
||||
expect(captured.guard?.(outside)).toEqual(outsideDenial(/workspace/u))
|
||||
})
|
||||
|
||||
it('refuses a child whose scope cannot register the confined read, and keeps the prompt gate closed', async () => {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
type ForkToolExecution,
|
||||
} from '../src/host/fork-tool-guard.ts'
|
||||
import { READ_ONLY_FORK_CEILING, WRITE_FORK_CEILING } from '../src/host/fork-policy.ts'
|
||||
import { denial } from './fork-denial.ts'
|
||||
import { denial, outsideDenial } from './fork-denial.ts'
|
||||
import { forkToolDenial, type ForkToolDenial } from '../src/host/fork-errors.ts'
|
||||
|
||||
const child = 'child-1'
|
||||
@@ -271,7 +271,7 @@ describe('fork tool guard', () => {
|
||||
const guard = forkToolGuard(host, () => READ_ONLY_FORK_CEILING, describeTool)
|
||||
|
||||
// The path check runs through the host's resolution, not a prefix comparison in the guard.
|
||||
expect(guard(execution('read', { path: '/etc/passwd' }))).toEqual(denial(/may only read inside the workspace/u, 'FORK_PATH_OUTSIDE_WORKSPACE'))
|
||||
expect(guard(execution('read', { path: '/etc/passwd' }))).toEqual(outsideDenial(/may only read inside the workspace/u))
|
||||
expect(refused).toContain('/etc/passwd')
|
||||
// Acting capabilities are refused before any path is even considered.
|
||||
for (const tool of ['bash', 'pwsh', 'cua', 'plugin_manager', 'schedule_create', 'write', 'edit', 'subagent']) {
|
||||
|
||||
@@ -255,6 +255,7 @@ describe('LiveShare current write policy', () => {
|
||||
const result = await pending
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('does not allow writing this Session')
|
||||
expect(result.error?.info).toEqual({ name: 'LiveshareForkDeniedError', code: 'FORK_TOOL_NOT_PERMITTED' })
|
||||
// The final gate asked again after the refresh; trusting the first verdict would have let this write
|
||||
// reach fs.writeText.
|
||||
expect(mayWriteChecks).toBe(2)
|
||||
|
||||
Reference in new issue
Block a user