Repository navigation
fix: support UUID generation in insecure browser contexts - #5173
Conversation
🦋 Changeset detectedLatest commit: fa515a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
|
❌ Nix build failed Hash mismatch in
Please update |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3642d89dc1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (target.type === 'Identifier') return target.name === 'crypto'; | ||
| return target.type === 'MemberExpression' && memberName(target) === 'crypto' && isGlobalObject(target.object); |
There was a problem hiding this comment.
Resolve the global binding before rejecting crypto
When Node code uses the common namespace form import * as crypto from 'node:crypto'; crypto.randomUUID(), this predicate classifies the imported identifier as the browser global and fails pnpm lint, despite the rule intentionally allowing Node crypto. Conversely, browser spellings such as self.crypto.randomUUID() evade the guard. Determine whether crypto resolves to the global binding (and recognize browser global aliases) rather than relying only on the identifier text.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa515a2779
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
* fix(core): add Claude 5 output token ceilings (#5096) * fix(core): add Claude 5 output token ceilings * chore: add Claude 5 output ceiling changeset * fix(markdown): keep table actions inside clipped containers (#5098) * fix(markdown): keep table actions inside clipped containers * fix(markdown): observe table action clipping ancestors --------- Co-authored-by: kimi-agent-bot <[email protected]> * fix(hosts): keep project lists usable with SSH hosts (#5102) * ci: release packages (#5094) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: preserve first prompt through project creation (#5161) Co-authored-by: kimi-agent-bot <[email protected]> * fix(agent-core-v2): align fork slicing with restored turn ids (#5165) * fix(agent-core-v2): align fork slicing with restored turn ids * chore: add restored fork fix changeset * fix(core): prevent AJV diagnostics from polluting TUI input (#5168) * refactor(core): route AJV logs through utils logger * chore(core): add AJV logger changeset * chore(core): clarify AJV logger changeset * fix: support UUID generation in insecure browser contexts (#5173) * fix: support UUID generation in insecure browser contexts * chore: update pnpm deps hash * fix: resolve crypto bindings in UUID lint rule --------- Co-authored-by: kimi-agent-bot <[email protected]> * fix(client): keep draft thinking effort after sending (#5170) * fix(client): keep draft thinking effort after sending * chore: add cli changeset for draft thinking fix * test(client): use function stub for websocket in thinking test * fix(client): preserve thinking effort during model normalization * fix(client): reconcile profile updates and model fallbacks * fix(client): scope draft thinking preservation * fix(tui): defer queued prompts until the loop drains (#5166) * fix(tui): defer queued prompts until the loop drains - add core and v2 drained/idle lifecycle events - consume reminder-only queues without starting a model turn - gate TUI queue dispatch and completion notifications on lifecycle state - document notification-handoff queue behavior and add a CLI patch changeset * fix(tui): close loop lifecycle races - emit idle only after the current macro is revalidated - keep queued input pending through compaction and delayed dispatch - reject stale idle after new work starts * fix(loop): correlate lifecycle events by generation - track macro generations in the core and v2 loop state - replace TUI macro inference with event-generation correlation - preserve compaction guards for queued dispatch * fix(desktop): simplify multi-select folder picker actions (#5174) * fix(kap-server): report :wait settled only after the session is on disk (#5176) :wait settled as soon as the turn left the in-memory activity view, but the engine writes wire records through a batched log that flushes in a later task. A server killed right after :wait reported idle could lose the end of the finished turn. Before it replies with a settled session, :wait now flushes the wire of every agent in the session and drains pending metadata writes. A failed write surfaces as an error instead of a settled reply. The KAP guide states the guarantee. A new test in sessions.test.ts slows down the disk write of the turn end and checks that the record is on disk when :wait returns. (cherry picked from commit fc33c6d) Co-authored-by: kai <[email protected]> * ci: release packages (#5163) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix(client): keep config-derived draft thinking effort after sending (#5191) Co-authored-by: liruifengv <[email protected]> * ci: release packages (#5192) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix(kap-server): resume sessions with unavailable models (#5212) * fix(kap-server): resume sessions with unavailable models * fix: let users replace unavailable session models * fix: scope unavailable model recovery state --------- Co-authored-by: kimi-agent-bot <[email protected]> * fix(plugins): detect MCP OAuth with targeted probes (#5197) * fix(plugins): detect MCP OAuth with targeted probes * fix(plugins): use the MCP inspect route * fix(plugins): preserve OAuth requirements across inspection and disconnect * fix(chat): show pending MCP browser authorization (#5246) * fix(chat): show pending MCP browser authorization * fix(chat): resolve MCP authorization lint findings * fix(chat): preserve MCP authorization failure details * fix(mcp): preserve cancellation during OAuth reconnect * fix(desktop): cache feedback form per host and let reply reasons wrap (#5303) * ci: release packages (#5232) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * test: port removed-model recovery coverage to testkit * test: dedupe anthropic output ceiling cases --------- Co-authored-by: Haozhe <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: 7Sageer <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: liruifengv <[email protected]> Co-authored-by: qer <[email protected]> Co-authored-by: kai <[email protected]> Co-authored-by: Luyu Cheng <[email protected]> Co-authored-by: grapedge <[email protected]>
Requirement or Bug
通过局域网 HTTP 访问 CLI Web 时,Chrome 将页面视为非安全上下文,
crypto.randomUUID不可用,空会话的 Composer 会完全消失。这个 PR 让 UUID 生成在安全与非安全上下文都可用,并新增 lint 防护,避免同类调用再次进入仓库。Bug Reproduction Steps
http://<局域网 IP>:<端口>访问,而不是localhost或 HTTPS。window.isSecureContext === false且typeof crypto.randomUUID === 'undefined'。TypeError: crypto.randomUUID is not a function,调用栈经过菜单注册和 Composer setup。Root Cause
browserOverlayMenu在注册菜单时无条件调用crypto.randomUUID()。Composer setup 注册权限菜单和模型菜单时进入该路径,异常使组件挂载失败。crypto.randomUUID()只在安全上下文可用,但代码把它当成了所有浏览器环境都提供的能力。这是根本修复:统一使用仓库已有的
[email protected]。原生randomUUID存在时继续走原生路径,否则通过crypto.getRandomValues生成 RFC 4122 UUID v4;同时用 lint 禁止新的直接调用,而不是只修一个报错点。Code Changes
核心路径如下,调用方不再自行判断运行环境,也不使用
Math.random或时间戳充当随机源:flowchart LR A[UI、VS Code、协议解码调用方] --> B[uuid.v4] B --> C{原生 randomUUID 可用?} C -->|是| D[使用原生 UUID] C -->|否| E[getRandomValues 生成 UUID v4][email protected]node:crypto用法randomUUID不受浏览器安全上下文影响kimi/no-crypto-random-uuidAST 规则node:crypto与uuid.v4建议阅读顺序:
scripts/no-crypto-random-uuid-lint-plugin.mjs:看禁止和放行的边界。apps/desktop/src/renderer/lib/browserOverlayMenu.ts及其测试:看本次故障点和无原生randomUUID的回归。apps/desktop/src/shared/browser.ts、apps/desktop/src/renderer/api/config.ts:看两处原有自制降级如何统一到 CSPRNG。packages/core/src/llm/builtin/protocol/*/decode.ts:看上游已有 tool call ID 仍优先,只有缺失时才生成。pnpm-lock.yaml只补齐直接依赖。Screenshots / Recordings
同一个非安全 HTTP 场景中,修复前只有 Logo 和项目入口,修复后 Composer 正常显示;两图均来自真实发布/开发产物运行。
Behavior Changes and Affected Users
randomUUID is not a function,Composer 可能消失crypto.randomUUID()randomUUIDcreateBrowserId与 Web client ID 的降级Math.randomrandomUUIDnode:crypto直接导入crypto.randomUUID调用pnpm lint报错并要求使用uuid.v4import { v4 as randomUUID } from 'uuid'受影响模块与覆盖:Desktop/Web 菜单由
browser-overlay-menu.test.ts覆盖;app-composer/app-components 由对应包测试覆盖;VS Code 由扩展与 webview 构建、类型检查和目标测试覆盖;四种协议由 core 测试覆盖;lint 规则由独立 Node 测试覆盖。实际验证结果
pnpm lint:通过,包含新规则及配置守卫。@moonshot-ai/core:164/164 通过。tsdown、VS Code extension/webview 构建、CLIsync:web:通过。isSecureContext=false、crypto.randomUUID === undefined,Composer 正常显示且控制台无相关错误。Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.