Skip to content

Commit 4806eaa

Browse files
bkudiessCopilot
andauthored
feat: replace legacy exec approvals with V2 (#1051)
* feat: replace legacy exec approvals with V2 Co-authored-by: Copilot App <[email protected]> * fix: prevent remote exec policy weakening Co-authored-by: Copilot App <[email protected]> * docs: describe V2 as the active approval pipeline Co-authored-by: Copilot App <[email protected]> * fix: close exec approval review bypasses Co-authored-by: Copilot App <[email protected]> * fix: harden approval redaction boundaries Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: Copilot App <[email protected]>
1 parent c04c5fb commit 4806eaa

81 files changed

Lines changed: 6520 additions & 6892 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,22 @@ Packaged installs declare camera, microphone, and location capabilities. Windows
315315
# Speak text aloud on the Windows node (requires TTS enabled in Settings and tts.speak allowed on the gateway)
316316
openclaw nodes invoke --node <id> --command tts.speak --params '{"text":"Hello from OpenClaw","provider":"windows"}'
317317

318-
# Execute a command on the Windows node
319-
openclaw nodes invoke --node <id> --command system.run --params '{"command":"Get-Process | Select -First 5","shell":"powershell","timeoutMs":10000}'
318+
# Execute a command on the Windows node (raw node.invoke requires canonical argv)
319+
openclaw gateway call node.invoke --params '{"nodeId":"<id>","command":"system.run","params":{"command":["cmd.exe","/d","/s","/c","echo hello"],"rawCommand":"echo hello","timeoutMs":10000}}' --json
320320

321321
# View exec approval policy
322322
openclaw nodes invoke --node <id> --command system.execApprovals.get
323323

324-
# Update exec approval policy (add custom rules)
325-
openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"rules":[{"pattern":"echo *","action":"allow"},{"pattern":"*","action":"deny"}],"defaultAction":"deny"}'
324+
# Update exec approvals using baseHash from the preceding get response
325+
openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"baseHash":"<hash-from-get>","file":{"version":1,"defaults":{"security":"allowlist","ask":"on-miss","askFallback":"deny","autoAllowSkills":false},"agents":{"main":{"security":"allowlist","ask":"on-miss","askFallback":"deny","autoAllowSkills":false,"allowlist":[]}}}}'
326326
```
327327
> 📷 **Camera permission**: Desktop builds rely on Windows Privacy settings. Packaged MSIX builds will show the system consent prompt.
328328

329-
> 🔒 **Exec Policy**: `system.run` is gated by an approval policy on the Windows node at `%LOCALAPPDATA%\OpenClawTray\exec-policy.json` (schema: `{ "defaultAction": "...", "rules": [...] }`). This is separate from gateway-side `~/.openclaw/exec-approvals.json`.
329+
> 🔒 **Exec approvals**: `system.run` is gated by the V2 approval coordinator and `%APPDATA%\OpenClawTray\exec-approvals.json`. The file uses the same `defaults`/`agents`/`allowlist` model as the macOS node host. `system.execApprovals.set` requires the current `baseHash` and rejects stale or unsafe remote updates.
330330
>
331-
> Rules are matched against the full command line. Known wrapper payloads such as `cmd /c ...`, `powershell -Command ...`, `pwsh -EncodedCommand ...`, and `bash -c ...` are also evaluated before execution. Dangerous environment overrides like `PATH`, `PATHEXT`, `NODE_OPTIONS`, `GIT_SSH_COMMAND`, `LD_*`, and `DYLD_*` are rejected.
331+
> Allowlist rules match resolved executable paths, using path-aware wildcards such as `**/git.exe`. Script interpreters and command hosts cannot receive reusable grants. Non-empty custom environments are rejected until they can be identity-bound and displayed safely.
332+
>
333+
> **V2 caller migration**: raw MCP, direct `node.invoke`, plugin, and `winnode` callers must replace string-form `{"command":"echo hello","shell":"cmd"}` with canonical `{"command":["cmd.exe","/d","/s","/c","echo hello"],"rawCommand":"echo hello"}`. The normal gateway `exec host=node` path already performs this wrapping. Remove custom `env`; non-empty environments are rejected.
332334

333335
#### Command Center diagnostics
334336

@@ -341,7 +343,7 @@ Open the status detail/Command Center from the tray menu or with `openclaw://com
341343
- recent activity and node invoke results through the Activity Stream, storing command names/status/duration only (not payloads, screenshots, recordings, or secrets)
342344
>
343345
> ```bash
344-
> openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"rules":[{"pattern":"powershell.exe","action":"allow"},{"pattern":"pwsh.exe","action":"allow"},{"pattern":"echo *","action":"allow"},{"pattern":"*","action":"deny"}],"defaultAction":"deny"}'
346+
> openclaw nodes invoke --node <id> --command system.execApprovals.set --params '{"baseHash":"<hash-from-get>","file":{"version":1,"defaults":{"security":"allowlist","ask":"off","askFallback":"deny","autoAllowSkills":false},"agents":{"main":{"security":"allowlist","ask":"off","askFallback":"deny","autoAllowSkills":false,"allowlist":[]}}}}'
345347
> ```
346348

347349
> 🔐 **Web Chat secure context**: Remote web chat requires `https://` (or localhost). If using a self-signed cert, trust it in Windows (Trusted Root Certification Authorities) or use an SSH tunnel to localhost.

‎docs/MCP_MODE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ MCP startup is reported from the actual listener state. `NodeService.McpStartupE
145145

146146
### Testing
147147

148-
The tray's most interesting code lives in capabilities — `system.run` (LocalCommandRunner + ExecApprovalPolicy), `screen.snapshot` (Windows.Graphics.Capture + GraphicsCapturePicker), `canvas.*` (WebView2 with trusted origin enforcement), `camera.snap`/`camera.clip` (MediaCapture + consent prompt), `location.get` (Windows.Devices.Geolocation). All of that has nontrivial Windows-only behavior and almost none of it is currently exercised end-to-end without first standing up a gateway and authenticating.
148+
The tray's most interesting code lives in capabilities: `system.run` (LocalCommandRunner + the V2 exec-approval coordinator), `screen.snapshot` (Windows.Graphics.Capture + GraphicsCapturePicker), `canvas.*` (WebView2 with trusted origin enforcement), `camera.snap`/`camera.clip` (MediaCapture + consent prompt), and `location.get` (Windows.Devices.Geolocation). All of that has nontrivial Windows-only behavior and almost none of it is currently exercised end-to-end without first standing up a gateway and authenticating.
149149

150150
Local MCP changes that. Concrete benefits:
151151

@@ -260,7 +260,7 @@ The server is built on several defensive layers, not just one. Loopback alone is
260260
Together these three checks force a malicious cross-origin browser fetch into a CORS preflight that we deliberately do not honor (no `Access-Control-Allow-*` is ever emitted), so the actual call is blocked before reaching capability code.
261261
4. **Bearer token.** Every request must include the persistent local MCP bearer token (`Authorization: Bearer <token>`) once the server has created `%APPDATA%\OpenClawTray\mcp-token.txt`. This blocks drive-by local clients that know the port but cannot read the per-user token file.
262262
5. **Concurrency cap.** A semaphore limits in-flight handlers to 8. A misbehaving local client cannot pin every threadpool thread on long-running screen/camera calls.
263-
6. **Capability-level controls remain in force.** `SystemCapability.SetApprovalPolicy(...)` (the exec approval policy) still gates `system.run`. Camera and screen capture still go through Windows consent flows. MCP doesn't bypass any of those.
263+
6. **Capability-level controls remain in force.** The V2 exec-approval coordinator still gates `system.run`. Camera and screen capture still go through Windows consent flows. MCP doesn't bypass any of those.
264264

265265
**Authentication is local bearer-token based.** The token is persistent, generated by the tray, stored in the current user's OpenClawTray data directory, and verified before MCP method dispatch. It is defense-in-depth rather than a hard sandbox boundary: a malicious process already running as the same user may still be able to read user-profile files or invoke native APIs directly. If we need stronger isolation for shared machines or low-trust local processes, the next step is scoped or per-call tokens issued by the tray, not URL ACLs or HTTPS — both add deployment pain without solving the same-user trust problem.
266266

‎docs/TELEMETRY.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,10 @@ Reviewed attributes are:
371371
- `openclaw.node.tool.transport`: `gateway` or `mcp`
372372
- `openclaw.outcome`: `success`, `failure`, or `canceled`
373373
- `openclaw.error.category`: a finite typed category
374-
- `openclaw.node.tool.system_run.approval.pipeline`: `legacy` for the existing
375-
approval policy or `v2` for the opt-in direct-argv approval pipeline; present
374+
- `openclaw.node.tool.system_run.approval.pipeline`: `v2` for the authoritative
375+
canonical-argv approval pipeline; current `system.run` always emits this value.
376+
`legacy` remains a finite historical value for backward-compatible telemetry
377+
readers, but the runtime no longer selects the legacy approval path. Present
376378
only for `system.run` traces and failure/cancellation logs
377379
- `openclaw.node.tool.sandbox.requested`: whether sandboxing was configured
378380
- `openclaw.node.tool.sandbox.applied`: whether the command was known to run

‎docs/WINDOWS_NODE_ARCHITECTURE.md‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ Niche scenario. If the "server" must be Windows for some reason, this works but
254254
| `camera.clip` | ✅ | ✅ | ✅ | ❌ | **✅** | MediaCapture + MediaEncoding |
255255
| `camera.list` | ✅ | ✅ | ✅ | ❌ | **✅** | DeviceInformation.FindAllAsync |
256256
| `screen.record` | ✅ CGWindowListCreateImage | ✅ ReplayKit | ✅ MediaProjection | ❌ | **✅** | Windows.Graphics.Capture |
257-
| `system.run` | ✅ | ❌ | ❌ | ✅ | **✅** | Process.Start (cmd/pwsh) + ExecApprovalPolicy |
258-
| `system.execApprovals` | ❌ | ❌ | ❌ | ❌ | **✅** | JSON policy file (exec-policy.json) |
257+
| `system.run` | ✅ | ❌ | ❌ | ✅ | **✅** | Process.Start + V2 exec-approval coordinator |
258+
| `system.execApprovals` | ❌ | ❌ | ❌ | ❌ | **✅** | V2 store (`exec-approvals.json`) with base-hash CAS |
259259
| `system.notify` | ✅ NSUserNotification | ✅ UNUserNotification | ✅ NotificationManager | ❌ | **✅** | ToastNotificationManager |
260260
| `location.get` | ✅ CLLocationManager | ✅ CLLocationManager | ✅ FusedLocation | ❌ | **✅** | Windows.Devices.Geolocation |
261261
| `device.info/status` | ✅ shared schema | ✅ shared schema | ✅ shared schema | ❌ | **✅** | .NET runtime, storage, network |
@@ -453,7 +453,51 @@ string stderr = await process.StandardError.ReadToEndAsync();
453453
await process.WaitForExitAsync();
454454
```
455455

456-
**Critical:** Exec approvals must be enforced locally, same as macOS/headless nodes. Store in `%APPDATA%\OpenClaw\exec-approvals.json`.
456+
**Critical:** Exec approvals must be enforced locally, same as macOS/headless nodes. The default store is `%APPDATA%\OpenClawTray\exec-approvals.json`; `OPENCLAW_STATE_DIR` overrides that location.
457+
458+
#### Decision: retire Windows V1 exec policy without migration
459+
460+
Windows V1 `exec-policy.json` command-text globs are not evaluated or converted after the
461+
V2 cutover. When no valid V2 policy exists, the node uses an empty allowlist with
462+
prompt-on-miss and deny fallback.
463+
464+
**Consequences:**
465+
466+
- Existing V1 files remain untouched during normal runtime but no longer authorize or deny execution.
467+
- Prior V1 allows require attended V2 reapproval; unattended calls deny.
468+
- Prior V1 denies are not imported and may be explicitly superseded through an attended V2 prompt.
469+
- Malformed or untrusted V2 state remains hard deny and is never replaced from V1 state.
470+
471+
This compatibility break is accepted because V1 matched shell command text while V2 binds
472+
resolved executable identity and canonical argv. Mechanical conversion could widen a narrow
473+
command rule into a reusable `cmd.exe` or PowerShell grant, while retaining both evaluators
474+
would preserve parallel authorization paths and bypass drift.
475+
476+
**Rejected alternatives:** V1 runtime fallback, mechanical rule conversion, and file-triggered
477+
migration UI. Revisit this decision only if measured support impact justifies a separate
478+
compatibility feature.
479+
480+
#### Decision: version the low-level `system.run` boundary as canonical argv
481+
482+
The V2 low-level node contract accepts `command` only as `string[]` canonical argv.
483+
String-form `command`, implicit `shell`, separate `args`, and non-empty custom `env`
484+
are intentional breaking changes. The normal gateway `exec host=node` flow already
485+
constructs canonical Windows argv, so this affects raw MCP, direct `node.invoke`,
486+
plugins, and other callers that bypass gateway exec orchestration.
487+
488+
Migration example:
489+
490+
```json
491+
// Before
492+
{"command":"echo hello","shell":"cmd"}
493+
494+
// V2
495+
{"command":["cmd.exe","/d","/s","/c","echo hello"],"rawCommand":"echo hello"}
496+
```
497+
498+
The node returns `command-array-required` for a string command and
499+
`custom-env-not-supported` for a non-empty environment. This explicit boundary
500+
keeps approval identity and process execution on one argv representation.
457501

458502
### Location → Windows.Devices.Geolocation
459503

‎scripts/Uninstall-LocalGateway.ps1‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,50 @@ function Resolve-AppDataDir {
9999
return Join-Path ([Environment]::GetFolderPath([Environment+SpecialFolder]::LocalApplicationData)) $DataDirectoryName
100100
}
101101

102+
function Resolve-UsablePathValue {
103+
param([string]$Value)
104+
$trimmed = if ($null -eq $Value) { '' } else { $Value.Trim() }
105+
if ([string]::IsNullOrEmpty($trimmed) -or $trimmed -in @('undefined', 'null')) {
106+
return $null
107+
}
108+
return $trimmed
109+
}
110+
111+
function Expand-ExecApprovalsHomePath {
112+
param([string]$Path, [string]$Home)
113+
if ($Path -eq '~') { return $Home }
114+
if ($Path.StartsWith('~\') -or $Path.StartsWith('~/')) {
115+
return Join-Path $Home $Path.Substring(2)
116+
}
117+
return $Path
118+
}
119+
120+
function Resolve-ExecApprovalsPaths {
121+
param([string]$DataDir)
122+
123+
$legacyPath = Join-Path $DataDir 'exec-approvals.json'
124+
$stateDir = Resolve-UsablePathValue $env:OPENCLAW_STATE_DIR
125+
if (-not $stateDir) { return @($legacyPath) }
126+
127+
$osHome = Resolve-UsablePathValue $env:HOME
128+
if (-not $osHome) { $osHome = Resolve-UsablePathValue $env:USERPROFILE }
129+
if (-not $osHome) {
130+
$osHome = [Environment]::GetFolderPath([Environment+SpecialFolder]::UserProfile)
131+
}
132+
if (-not $osHome) { $osHome = (Get-Location).Path }
133+
134+
$openClawHome = Resolve-UsablePathValue $env:OPENCLAW_HOME
135+
$effectiveHome = if ($openClawHome) {
136+
[IO.Path]::GetFullPath((Expand-ExecApprovalsHomePath $openClawHome $osHome))
137+
} else {
138+
[IO.Path]::GetFullPath($osHome)
139+
}
140+
$resolvedStateDir = [IO.Path]::GetFullPath(
141+
(Expand-ExecApprovalsHomePath $stateDir $effectiveHome))
142+
$activePath = Join-Path $resolvedStateDir 'exec-approvals.json'
143+
return @($activePath, $legacyPath) | Select-Object -Unique
144+
}
145+
102146
function Get-JsonPropertyValue {
103147
param(
104148
[object]$Object,
@@ -451,7 +495,12 @@ function Resolve-AppDataDir {
451495
Remove-FileIfExists -Path (Join-Path $dataDir 'setup-state.json') -Label 'legacy setup-state.json'
452496
Remove-FileIfExists -Path (Join-Path $localDataDir 'setup-state.json') -Label 'setup-state.json'
453497
Remove-FileIfExists -Path (Join-Path $localDataDir 'run.marker') -Label 'run.marker'
498+
foreach ($execApprovalsPath in (Resolve-ExecApprovalsPaths -DataDir $dataDir)) {
499+
Remove-FileIfExists -Path $execApprovalsPath -Label 'exec-approvals.json'
500+
}
501+
Remove-FileIfExists -Path (Join-Path $localDataDir 'exec-approvals.json') -Label 'local legacy exec-approvals.json'
454502
Remove-FileIfExists -Path (Join-Path $dataDir 'exec-policy.json') -Label 'exec-policy.json'
503+
Remove-FileIfExists -Path (Join-Path $localDataDir 'exec-policy.json') -Label 'local exec-policy.json'
455504
Remove-KeepaliveMarker -LocalDataDir $localDataDir
456505

457506
$registryCleanup = Remove-SetupManagedGatewayRecords -DataDir $dataDir

0 commit comments

Comments
 (0)