Skip to content

fix: Windows cmd command argument escaping in open_terminal_with_command - #458

Open
qiangxinglin wants to merge 1 commit into
leookun:mainfrom
qiangxinglin:fix/windows-cmd-escaping
Open

qiangxinglin wants to merge 1 commit into
leookun:mainfrom
qiangxinglin:fix/windows-cmd-escaping

Conversation

@qiangxinglin

@qiangxinglin qiangxinglin commented Sep 16, 2026

Copy link
Copy Markdown

改动概要

本 PR 包含两个修复,均在 Windows 平台生效:

1. CA 证书存储从 Machine Level 改为 User Level

原先 CA 证书通过 certutil -addstore (无 -user) 和 Win32 CERT_SYSTEM_STORE_LOCAL_MACHINE 安装/检查在系统级根证书存储中,这要求管理员权限。

改为 certutil -user -addstoreCERT_SYSTEM_STORE_CURRENT_USER,将证书操作限定在当前用户级别,无需管理员提权。

2. 修复 Windows cmd 命令参数传递

open_terminal_with_command 原先使用 cmd /C start cmd /K 嵌套链,导致命令参数被 start 二次解析后丢失/错位。

改为直接 cmd /K 并通过 std::os::windows::process::CommandExt::raw_arg() 原样传递命令字符串。

涉及文件

  • apps/desktop/src-tauri/src/desktop.rs — Windows 终端打开路径
  • server/src/local_app/ca/mod.rs — certutil 回退路径加 -user
  • server/src/local_app/ca/windows.rs — Win32 API 路径改为 CURRENT_USER

Copilot AI lite review requested due to automatic review settings September 16, 2026 05:49
@qiangxinglin
qiangxinglin force-pushed the fix/windows-cmd-escaping branch from f08bda2 to 8c736c7 Compare September 16, 2026 05:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The CA store changes are out of scope and need migration or dual-store handling for existing installations.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes Windows terminal command escaping by launching cmd /K directly with raw_arg.

Changes:

  • Removes nested cmd /C start cmd /K invocation.
  • Switches Windows CA installation and detection to the per-user certificate store.
File summaries
File Summary
server/src/local_app/ca/windows.rs Detects CAs in CurrentUser\Root; existing machine-wide installations may be reported as untrusted.
server/src/local_app/ca/mod.rs Generates a per-user CA installation command, introducing a separate trust-scope change.
apps/desktop/src-tauri/src/desktop.rs Launches Windows commands directly with cmd /K and raw_arg.
Review details

Suppressed comments (1)

server/src/local_app/ca/windows.rs:48

  • This changes the Windows trust scope beyond the command-escaping fix: the previous certutil -addstore flow used the machine store, while this line makes detection use only CurrentUser (and the paired install command adds -user). Existing users with the CA already installed in LocalMachine\Root will therefore be reported as untrusted and blocked until they reinstall it. Please keep the existing store contract or add an explicit migration/dual-store check and document this behavior change.
        CERT_SYSTEM_STORE_CURRENT_USER | CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG;
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

}),
"windows" => Some(format!(
"certutil -addstore -f Root \"{}\"",
"certutil -user -addstore -f Root \"{}\"",
…scaping

- Switch CA certificate store from LocalMachine (system) to CurrentUser
  (user-level) in both certutil fallback and native Win32 API path. This
  removes the need for admin elevation when installing/checking the
  local CA cert on Windows.

- Fix the Windows open_terminal_with_command path: remove the nested
  `cmd /C start cmd /K` chain which broke command argument passing, and
  replace it with `cmd /K` + raw_arg() for correct escaping.
@qiangxinglin
qiangxinglin force-pushed the fix/windows-cmd-escaping branch 2 times, most recently from ec32f39 to 5b63b85 Compare September 16, 2026 05:59
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