Skip to content

fix: tighten WriteStdin permission boundary - #966

Merged
Astro-Han merged 6 commits into
apache:mainfrom
M4n5ter:fix/856-write-stdin-permission-boundary
Jul 14, 2026
Merged

Astro-Han merged 6 commits into
apache:mainfrom
M4n5ter:fix/856-write-stdin-permission-boundary

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Jul 14, 2026 •

Copy link
Copy Markdown
Member
English

Part of #856.

Summary

  • Keep WriteStdin authorization bound to the exact invocation while retaining a bounded, redacted activity summary.
  • Let Desktop and TUI users deliberately inspect the complete input, ref, and resize as inert escaped text before deciding.
  • Disable turn-level permission memory for WriteStdin, expose that capability on every tool-permission request, and enforce it at the Runtime boundary.

Why

The ordinary activity projection is intentionally bounded and redacted. It is suitable for transcripts and compact tool rows, but not sufficient as the only authorization view: a meaningful suffix may otherwise be outside the preview.

Turn memory is also unsafe for terminal input. The same bytes can perform a different action after the terminal reaches another prompt, so allowing one WriteStdin invocation must not silently authorize a later one.

Design

Decision Rationale
Derive the compact summary and full inspector from the same exact permission args. The displayed authorization data cannot drift from the invocation, and no parallel inspector payload is needed.
Keep the default summary bounded and redacted; reveal the full value only on explicit expansion. Routine activity stays compact while every character remains inspectable when authorization requires it.
Escape terminal controls, bidi controls, and default-ignorable Unicode in the full inspector. The complete value is visible without allowing its contents to execute or alter the inspector presentation.
Make permission memory a required per-tool-permission capability and set it to false for WriteStdin. Every client receives the same policy, and Runtime can reject a forged allow + rememberForTurn response.
Reject only an attempted remembered allow. deny + rememberForTurn has no authorization effect and should still resolve the pending request normally.

The implementation reuses one canonical WriteStdin argument parser for permission and activity projections. It does not introduce another request shape or duplicate resize rules.

Scope

This PR covers the WriteStdin permission policy, Runtime enforcement, and Desktop/TUI human-facing projection. Canonical argument ownership and the TUI permission FIFO are already provided by #884 and #885.

The one-shot additional_permissions protocol remains a separate request kind with its own allow_once / deny contract; it does not reuse the WriteStdin inspector or turn-memory UI.

It does not change PTY delivery semantics, runtime-resource ref validation, process lifecycle, persistence, or Headless/subagent capability. The queued input result and bounded canonical ref contract remain a separate follow-up from #856.

Verification

Root typecheck, tests, and build pass on the integrated branch. Real Storybook interaction covers the bounded collapsed view, explicit full inspection, inert control-character rendering, full suffix visibility, and the absence of a turn-memory control. The completed interaction was also exercised through Electron and the Otty TUI for allow, deny, non-reused approval, and PTY cleanup.

No dependency, CI, storage migration, compatibility alias, or dual permission payload is added.

简体中文

属于 #856 的一部分。

摘要

  • 让 WriteStdin 授权始终绑定精确调用,同时保留有界、脱敏的 activity 摘要。
  • 允许 Desktop 与 TUI 用户在决定前主动检查完整 input、ref 和 resize;内容以不可执行的转义文本展示。
  • 禁用 WriteStdin 的回合内权限记忆,在每个工具权限请求上表达该能力,并由 Runtime 强制执行。

原因

普通 activity 投影会有意保持有界和脱敏,适合 transcript 与紧凑工具行,却不应成为唯一授权视图,否则有意义的输入后缀可能位于预览之外。

Turn memory 对终端输入同样不安全。终端到达另一个提示符后,相同字节可能执行不同操作,因此允许一次 WriteStdin 不应静默授权稍后的另一次调用。

设计

决策 理由
从同一份精确 permission args 派生紧凑摘要和完整检查器。 展示的授权数据不会与实际调用漂移,也不需要另一套 inspector payload。
默认摘要保持有界和脱敏,仅在用户主动展开后显示完整内容。 日常 activity 保持紧凑,授权需要时仍可检查每个字符。
在完整检查器中转义终端控制、双向文本控制和 default-ignorable Unicode。 完整值保持可见,同时不会执行或改变检查器的展示。
将 permission memory 作为工具权限请求必需的逐请求能力,并为 WriteStdin 设为 false。 所有客户端遵守同一策略,Runtime 也能拒绝伪造的 allow + rememberForTurn 响应。
只拒绝试图记忆的允许响应。 deny + rememberForTurn 不会产生授权效果,应正常结束 pending request。

实现让 permission 与 activity 投影复用同一个 canonical WriteStdin 参数解析器,没有引入另一种请求 shape,也没有重复维护 resize 规则。

范围

本 PR 覆盖 WriteStdin permission policy、Runtime 强制约束,以及 Desktop/TUI 的人类可见投影。Canonical 参数所有权和 TUI 权限 FIFO 已由 #884 与 #885 提供。

一次性的 additional_permissions 协议仍是独立请求类型,使用自身的 allow_once / deny 契约;它不会复用 WriteStdin 检查器或 turn-memory UI。

本 PR 不修改 PTY 送达语义、runtime-resource ref 校验、进程生命周期、持久化或 Headless/subagent 能力。输入结果的 queued 语义与有界 canonical ref 契约仍是 #856 中的独立后续。

验证

集成分支的根级 typecheck、测试与 build 均通过。真实 Storybook 交互覆盖默认有界视图、主动展开完整内容、控制字符不可执行展示、完整后缀可见,以及不出现 turn-memory 控件。完成态交互还通过 Electron 与 Otty TUI 验证了允许、拒绝、授权不复用和 PTY 清理。

本 PR 不增加依赖、CI、存储迁移、兼容别名或双重权限 payload。

@M4n5ter

M4n5ter commented Jul 14, 2026 •

Copy link
Copy Markdown
Member Author
English

After #969 landed, this became a semantic integration rather than a mechanical merge. I rechecked the permission boundary and resolved the overlap without folding the two request protocols together.

The integrated model is:

  • tool_permission keeps the exact canonical invocation args and carries a required rememberForTurnAllowed capability. WriteStdin sets it to false, and newly mapped RuntimeEvents retain the explicit tool_permission kind.
  • additional_permissions remains the separate one-shot protocol introduced by feat(runtime): add one-shot additional permission grants #969: raw tool args stay absent, its decisions remain allow_once / deny, and it does not reuse the WriteStdin inspector or turn-memory UI.
  • PermissionEngine uses one internal boolean capability for parked requests, with additional-permission requests fixed to false. A remembered tool scope cannot absorb a parked request that forbids memory, while forged remembered approvals still fail closed under the corresponding request contract.

The conflicts in the event types, SessionEvent-to-RuntimeEvent mapping, and permission engine were resolved around those invariants. The PR body now scopes the required capability explicitly to tool-permission requests.

A post-integration review tightened the boundary further: both request protocols now require an explicit discriminant, and the Runtime mapper rejects a missing or unknown kind instead of normalizing it into either protocol. A real PermissionEngine test also verifies that a remembered ordinary tool approval cannot absorb a same-scope one-shot request.

The integrated branch passes the root typecheck, full test suite, and production build. The final Runtime suite reports 1,600 passing tests with 7 existing skips.

简体中文

#969 合并后,这次冲突已经不是机械合并,而是一次权限语义集成。我重新核对了权限边界,并在不把两种请求协议揉成一套的前提下解决了交集。

集成后的模型如下:

  • tool_permission 保留精确的 canonical 调用参数,并携带必需的 rememberForTurnAllowed 能力。WriteStdin 将其设为 false;新映射的 RuntimeEvent 也会保留显式的 tool_permission 类型。
  • additional_permissions 继续保持 feat(runtime): add one-shot additional permission grants #969 引入的独立一次性协议:不暴露原始工具参数,决策仍为 allow_once / deny,也不复用 WriteStdin 检查器或 turn-memory UI。
  • PermissionEngine 对 parked request 使用统一的内部布尔能力,其中 additional-permission request 固定为 false。已记忆的工具 scope 不会吸收禁止记忆的 pending request;伪造的记忆式允许仍会按对应请求契约 fail closed。

事件类型、SessionEvent 到 RuntimeEvent 的映射和 permission engine 中的冲突均围绕这些不变量解决。PR body 也已把必需能力明确限定为工具权限请求。

集成后的复核进一步收紧了边界:两种请求协议现在都必须携带显式判别字段;Runtime mapper 会拒绝缺失或未知的 kind,不会将其规范化为任一协议。真实 PermissionEngine 测试也确认,普通工具的 remembered approval 不会吸收同 scope 的一次性请求。

集成分支已通过根级 typecheck、完整测试和生产构建。最终 Runtime 测试为 1,600 项通过、7 项既有 skip。

@M4n5ter
M4n5ter marked this pull request as draft July 14, 2026 08:34
@M4n5ter
M4n5ter marked this pull request as ready for review July 14, 2026 09:17

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed independently — no defect findings. The WriteStdin boundary is enforced at the runtime layer (non-rememberable, forged-remember rejected), full input is rendered inertly, and protocol/back-compat holds. CI green, mergeable clean. Approving.

@Astro-Han
Astro-Han merged commit fd9cfac into apache:main Jul 14, 2026
3 checks passed
@M4n5ter
M4n5ter deleted the fix/856-write-stdin-permission-boundary branch July 14, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants