Skip to content

[bugfix] desktop: grant the renderer permissions the shell controls use - #458

Open
Zhangbo-cn wants to merge 3 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:fix/desktop-renderer-permissions
Open

Zhangbo-cn wants to merge 3 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:fix/desktop-renderer-permissions

Conversation

@Zhangbo-cn

@Zhangbo-cn Zhangbo-cn commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace the deny-all renderer permission handler in the desktop shell with an explicit allow list scoped to opendirector://app: clipboard-sanitized-write, fullscreen, automatic-fullscreen. Every other renderer permission stays denied.
  • clipboard-sanitized-write is the name a click-activated navigator.clipboard.writeText requests. The read/write clipboard name (clipboard-read) stays denied because it also opens navigator.clipboard.readText, and every copy in the shared UI starts from a click: measured below, granting it lets the page read back the text a scripted write stored.
  • A denial the renderer never sees: denying fullscreen or automatic-fullscreen leaves requestFullscreen's promise unsettled, so the media player's fullscreen button does nothing and no .catch runs.
  • Scope grants by details.requestingUrl and by the check handler's origin. An origin outside opendirector://app, including an empty or unparsable one, is a denial rather than a thrown TypeError.
  • Extend the installed smoke run: a click-activated copy must reach the system clipboard and give the previous text back, a write without user activation and a readText must be refused with NotAllowedError without touching the clipboard, and a fullscreen request must settle, enter and exit.
  • Docs: architecture, development, lessons and validation, in both locales.

Linked issue

Labels

  • type:bug, area:desktop

Test plan

  • apps/desktop → node --test tests/*.test.mjs: 11 pass, 1 skipped (the skip needs the packaged runtime). The policy test pins the granted names, the denied clipboard read, and the origins that must stay denied, including opendirector://app without a path as the check handler serializes it.
  • node scripts/check-i18n.mjs: 3341 keys, 0 problems. check-browser-manifest.mjs: 92 entries OK. check-browser-locale.mjs: 86 pages, 0 problems.
  • Probe in the installed Electron 45.3.3 on Windows: the page is served from the real opendirector://app/ origin, the probe imports this branch's permissions.mjs, and the handler wiring matches main.mjs. The same build was measured under three policies, one process each:
policy scripted write readText click-activated write requestFullscreen
deny all (the handler #397 installed) NotAllowedError NotAllowedError NotAllowedError (the reported bug) pending, fullscreenElement none (the reported bug)
this allow list NotAllowedError, clipboard unchanged NotAllowedError ok, clipboard read back as probe-clicked entered, then exited
grant all (Electron's default) ok, clipboard probe-scripted ok, returns probe-scripted ok entered
  • Recorded permission stream for the same calls: clipboard-read (scripted write), clipboard-read (readText), clipboard-sanitized-write (click write), automatic-fullscreen (check), fullscreen (request); every requesting URL was opendirector://app/.
  • Packaged Windows run (author, before this commit): npm run prepare:runtime + npm run pack, then node scripts/smoke.mjs ...\win-unpacked\OpenDirector.exe. 4 of 5 runs passed with the previous allow list, including both clipboard assertions. The failures were later steps — Project search shortcut in one run, the trace-window step in another — and reproduced with the deny-all handler as well, so they are not permission failures.
  • Left to CI: the macOS job and the installed Windows application. Neither was run for this commit.

Evidence that it works

  • N/A because: no UI or copy changed. The evidence is the three-policy measurement above, where the deny-all row reproduces both reported failures on the same build that the allow-list row passes.

Boundaries this change does not cross. .mjs is outside the TypeScript check, so a clean tsc --noEmit says nothing about permissions.mjs, main.mjs or the smoke script, and this PR does not claim it as coverage. The permission names and the activation split come from Chromium's permission code, which is shared by platform, but the system clipboard and window server of macOS and of the installed Windows build are unmeasured here; the new clipboard and fullscreen assertions are first exercised in the release jobs. The fullscreen sequence has run in the Windows probe above, not yet inside a packaged smoke run.

Provider verification

  • No real-provider calls were made.

Bilingual UI

  • No user-facing copy changed; the updated docs ship in both locales.

@wangtiance wangtiance left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已审阅 7c9f562 的权限处理、origin 校验、测试及冒烟检查变更。四项权限都经同一 allow list 与 ownedURL 校验,空值和非法 URL 会被拒绝;没有发现这些变更把权限直接开放给外部 origin 的问题。当前 head 的 14 项 GitHub 检查均成功。本轮为静态审阅,未在本机运行 Electron 或安装包。

有两点建议在合并前补齐:

  1. 明确记录 clipboard-read 的实际授权范围。它用于修复无用户激活的 writeText,但授权名称也涉及剪贴板读取;当前测试只证明写入成功,没有界定同 origin 下 readText 的行为。建议在真实 Electron 中增加 readText 探针,并在安全说明里准确记录读取是否也被允许,避免把策略描述成只有写入能力。
  2. GitHub 当前报告本分支存在合并冲突。同步 main 后应重跑新提交的检查,保留两种用户激活方式的剪贴板断言,并补 macOS/Windows 安装包结果及全屏进入/退出验证。现有 Windows 4/5 冒烟通过和独立权限探针不能替代同步后的跨平台安装包验收。

结论:修复路径有针对性,但当前证据还不足以作完整安装包验收或合并批准。

dev added 3 commits November 24, 2026 14:35
## summary

- Replace the deny-all renderer permission handler with an explicit allow
  list limited to `opendirector://app`: the two clipboard names
  `navigator.clipboard.writeText` can request and the two fullscreen names
  `requestFullscreen` uses.
- Grant by activation path, not by intent: a scripted write asks for
  `clipboard-read`, while the same write from a click asks for
  `clipboard-sanitized-write`, so a single name passes a scripted check and
  still leaves every copy button failing with `NotAllowedError`.
- Scope grants by `details.requestingUrl` and the check handler's origin,
  and treat an empty or opaque origin as a denial instead of letting
  `new URL` throw.
- Cover the shell policy in the installed smoke run: write from the renderer
  with and without user activation, then compare the system clipboard from
  the main process, polling because the renderer promise settles before the
  system clipboard holds the value.

## validation

- Measured on Windows with Electron 45.3.3 against the real
  `opendirector://app` origin: the deny-all handler rejected the write with
  `NotAllowedError: Write permission denied.`; the allow list accepted both
  activation paths and the system clipboard held the written text.
- `apps/desktop` `node --test tests/*.test.mjs`: 11 passed, 1 skipped (the
  packaged smoke needs a packaged runtime).
- `node --check apps/desktop/scripts/smoke-window.mjs`.
- `npm test`: 952 passed. `npm run check:i18n`: 0 problems.

Refs: ThinkFlowLab#397
## summary

- The installed run failed with only "did not reach the system clipboard",
  which does not distinguish a denied write from a read that arrived before
  Windows handed the clipboard over.
- Poll the read instead of taking one sample, and include the observed value
  in the failure, so the next packaged failure names the cause.

## verification

- Packaged Windows build (win-unpacked, Electron 45.3.3): the scripted and the
  click-activated write both reach the system clipboard before the smoke moves
  on. The run then stops at the trace-window step, which reproduces with the
  previous deny-all handler as well and is unrelated to renderer permissions.
…ks for

Chromium reports a scripted clipboard write as `clipboard-read`, which is the
same permission that opens `navigator.clipboard.readText`. Granting it kept the
scripted smoke write green and handed the page the ability to read the system
clipboard, a capability the shared UI never uses.

Grant `clipboard-sanitized-write` only, the name a click-activated copy asks
for, and assert the rest of the policy where it runs: a write without user
activation and a `readText` are refused with NotAllowedError, a click-activated
copy reaches the system clipboard and gives the previous text back, and a
fullscreen request settles, enters and exits rather than staying pending.

Measured in Electron 45.3.3 on Windows with a deny-all handler, this policy and
a grant-all handler: deny-all rejects the click write and leaves
`requestFullscreen` pending, which are the two reported failures; grant-all
lets the page read back the text a scripted write stored; this policy refuses
both scripted calls and keeps the click path working.
@Zhangbo-cn
Zhangbo-cn force-pushed the fix/desktop-renderer-permissions branch from 7c9f562 to f7dcd6e Compare November 24, 2026 06:41
@Zhangbo-cn

Copy link
Copy Markdown
Contributor Author

谢谢审阅,两点都取了。已 rebase 到当前 main(3c151e15)并 force-push f7dcd6e0,冲突解除,检查重跑中。

1. clipboard-read 的授权范围:不授权了。

同意这条是问题:Chromium 把「无用户激活的 writeText」报成 clipboard-read,而这个名字同时打开 navigator.clipboard.readText。之前为了让脚本写入那条断言通过而授予它,等于用读取能力换一个产品里不存在的调用方式。现在只授予 clipboard-sanitized-write,并在同一个安装版 Electron 45.3.3(Windows、页面从真实 opendirector://app/ 加载、直接 import 本分支的 permissions.mjs)上用同一份构建跑了三种策略:

策略 脚本写入 readText 点击激活写入 requestFullscreen
全部拒绝(#397 的处理器) NotAllowedError NotAllowedError NotAllowedError(报告的问题) 挂起,fullscreenElement 为 none(报告的问题)
本清单 NotAllowedError,剪贴板未变 NotAllowedError 成功,主进程读回 probe-clicked 进入后退出
全部授予(Electron 默认) 成功,剪贴板变成 probe-scripted 成功,读回 probe-scripted 成功 进入

第三行就是「授权名称必须按能力而不是按调用看」的证据:全放开时,页面能读回脚本写入留下的文本。记录到的权限流是 clipboard-read(脚本写入)、clipboard-read(readText)、clipboard-sanitized-write(点击写入)、automatic-fullscreen(check)、fullscreen(request),requesting URL 都是 opendirector://app/。

安全说明已按实测改写:docs/architecture/desktop{,.zh-CN}.md 写明只授予点击路径的名称、读写名称不授予及原因;docs/development/desktop{,.zh-CN}.md 记录两种激活方式分别申请什么名称、以及脚本路径被拒绝;docs/development/lessons.md 增加了一条 follow-up,措辞是「按能力命名,不按调用命名」。

2. 冒烟断言与全屏验证。

「保留两种用户激活方式的剪贴板断言」保留了,但对两条的期望值不同:点击激活的写入断言成功并核对系统剪贴板,无激活写入断言 NotAllowedError 且剪贴板内容不变,另外新增 readText 断言同样被拒。这一条如果你想的是「两种方式都必须写入成功」,那就得把读取能力重新授回去——我按前一种做了,理由同上。

新增 assertFullscreen:requestFullscreen 与 10 秒超时 race,断言进入、document.fullscreenElement 命中、exitFullscreen 后退出。挂起会被判为失败而不是超时等待,因为「拒绝后 Promise 永不落地」正是这条权限最隐蔽的坏法。

仍然缺的证据,先说清楚:

  • macOS 打包版和 Windows 安装版这次都没有跑。上面的探测跑在 Windows 的开发版 Electron 上,用真实 origin 和真实模块,但它不等于安装包冒烟。新断言第一次真正在有窗口服务、有系统剪贴板的打包环境里执行,是发布流水线里的 macOS 与 Windows 作业。
  • 上一轮作者侧的 Windows 打包冒烟(4/5 通过,含两条剪贴板断言)是在这次提交之前跑的,不能算作对新断言的验收;两次失败的后继步骤分别是 Project search shortcut 和 trace window,用 deny-all 处理器也能复现,与权限无关。
  • .mjs 不在 tsc --noEmit 覆盖范围内,所以类型检查通过不能作为这次改动的证据,PR 描述里已经删掉这条。

结论我同意你的判断:这是修对了方向、但安装包级证据还不足的程度。合并前还差发布流水线那两次运行的结果。

@wangtiance wangtiance left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已复核 f7dcd6e 中对上轮意见的调整。clipboard-read 已从 allow list 移除,点击触发的 clipboard-sanitized-write 保留;新增断言分别检查无激活写入被拒且剪贴板不变、readText 被拒、点击写入成功,以及全屏进入和退出。这个方向解决了上轮提出的读取能力扩大问题;“保留两种激活断言”不要求两种都成功,现在按产品实际需求分别断言允许和拒绝是合适的。

作者提供的三种策略对照探针把开发版 Electron 的结果和安装包证据分开,更新后的说明也不再用 TypeScript 检查替代 .mjs 覆盖。当前 f7dcd6e 的 14 项 GitHub 检查均已成功。

本轮没有在复核的权限模块和新增断言中发现新的阻塞缺陷。安装包层面的 macOS 与 Windows 剪贴板、全屏验证仍以 PR 中列出的待办为准:旧提交的 4/5 冒烟结果不计作本提交验收,源码 CI 全绿也不替代发布作业结果。本轮只做远程静态复核,未运行本地 Electron,未批准或执行合并。

@Zhangbo-cn

Zhangbo-cn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@wangtiance — I checked your latest review against the head, and I can close one of the two open items with a real measurement on Windows, plus one small nit.

1. The earlier "merge conflict" note no longer applies. GET /repos/.../pulls/458 returns mergeable=true, mergeable_state=clean, and git merge-tree --write-tree origin/main <head> against a5ff3f22 produces no conflict records. Whatever GitHub reported at 7c9f562f, it is not reproducible now.

2. clipboard-read scope is measured on Windows at this head, not just asserted in a comment. Probe: real Windows (10.0.26200), Electron 45.3.3, page served from the actual opendirector://app/ origin, the branch's own apps/desktop/src/permissions.mjs imported unchanged, and the two handlers copied from main.mjs:137-140 (setPermissionRequestHandler on details.requestingUrl, setPermissionCheckHandler on the origin):

call result
navigator.clipboard.readText() NotAllowedError
writeText without user activation NotAllowedError, system clipboard unchanged
writeText with click activation granted, clipboard reads back probe-clicked
element.requestFullscreen() entered (fullscreenElement set), then exitFullscreen → none

Recorded permission stream for those calls, every requestingUrl = opendirector://app/: clipboard-read (scripted write), clipboard-read (readText), clipboard-sanitized-write (click write), automatic-fullscreen (check), fullscreen (request). That is the same stream the PR body lists, now reproduced at f7dcd6e0.

Boundary, stated plainly: this is an Electron probe on the branch's policy module, not a packaged win-unpacked/OpenDirector.exe smoke run, so it does not replace the release job. macOS I have no machine for. The probe script is C:\temp\od458\main.mjs if you want the exact code.

3. One nit worth taking before merge. In Electron 45 the main-process clipboard.readText()/writeText() return promises. All the reads in scripts/smoke-window.mjs are awaited, but the restore at line 301 (clipboard.writeText(previous);) is not: an un-awaited write at the end of the smoke can race the app exit, and a rejection there is unhandled rather than reported. await clipboard.writeText(previous); fixes it.

I am not asking to merge. As far as I can see the remaining gate is the packaged Windows + macOS run, and the code itself needs only the await above.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:desktop Desktop integration / 桌面集成 type:bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants