Skip to content

fix(gateway): harden embedded terminal policy - #100081

Merged
steipete merged 6 commits into
mainfrom
codex/fix-terminal-policy
Jul 4, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/fix-terminal-policy

Conversation

@steipete

@steipete steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Follow-up to #99918. The embedded operator terminal reached main while review was still in progress, leaving three correctness and safety gaps:

  • new tabs opened against the default agent instead of the currently selected agent;
  • tighter sandbox policy did not terminate already-running or in-flight PTYs;
  • terminal access and its relaxed WASM CSP were enabled by default.

Closes #77362.

Why This Change Was Made

  • Make gateway.terminal.enabled explicit opt-in and drive RPC, Control UI bootstrap, document metadata, and CSP from the same effective launch policy.
  • Carry the active agent into each terminal tab and preserve that tab's agent identity for its lifetime.
  • Centralize terminal admission in a bounded launch-policy owner.
  • Stage cumulative restrictions before hot-reload work begins, terminate disallowed sessions immediately, and commit grants only after a successful reload.
  • Keep restart-bound grants and launch-detail changes unavailable until process replacement, while allowing revocations to take effect immediately.

User Impact

Operators must set gateway.terminal.enabled: true to expose the browser terminal. Terminal tabs now use the active agent's sandbox and workspace. Tightening terminal or agent sandbox policy closes affected live sessions, and failed or ignored reloads cannot accidentally re-enable access.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Jul 4, 2026
@steipete

steipete commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready review completed for exact head 5a2822db81651a955e6eb99beab47090c2f899a5.

Review blockers from #99918 are fixed:

  • terminal exposure is explicit opt-in, with effective admission driving RPC, Control UI bootstrap, document metadata, and WASM CSP;
  • each terminal tab carries the active agent into launch policy, workspace, and sandbox selection;
  • restrictive config transitions close affected live and in-flight PTYs before reload work;
  • failed, ignored, and restart-pending changes cannot grant or smuggle terminal access.

Proof:

Known proof note: one local targeted lint invocation crashed inside upstream tsgolint/Go before reporting code findings. The same gateway surface and the complete core/UI/package lint set passed in Testbox.

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 4, 2026, 4:30 PM ET / 20:30 UTC.

Summary
The PR changes the embedded Control UI terminal to explicit opt-in, carries selected agent IDs into new terminal sessions, adds a terminal launch-policy owner, updates reload/CSP/UI plumbing, and expands docs/tests.

PR surface: Source +206, Tests +641, Docs +25. Total +872 across 36 files.

Reproducibility: yes. Source inspection reproduces the failure: gateway.reload.mode=hot plus gateway.terminal.enabled true-to-false reaches the restart-only hot-mode return before onConfigChange can prepare terminal revocations.

Review metrics: 1 noteworthy metric.

  • Terminal config/default surfaces: 1 default changed, 0 keys added, 0 removed. gateway.terminal.enabled moves from default-enabled to explicit opt-in, which affects operator setup, CSP exposure, and upgrade expectations before merge.

Stored data model
Persistent data-model change detected: serialized state: src/gateway/terminal/session-manager.test.ts, serialized state: src/gateway/terminal/session-manager.ts, unknown-data-model-change: src/gateway/terminal/session-manager.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #77362
Summary: This PR is the current hardening/fix candidate for the open Control UI web-terminal request; the earlier terminal PR is closed unmerged and useful as direct design/security context.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🌊 off-meta tidepool
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Fix terminal policy reconciliation before the gateway.reload.mode=hot restart-only return.
  • [P2] Add or update regression coverage showing terminal disable under hot mode closes/refuses live and pending PTYs.

Risk before merge

  • [P1] Merging as-is leaves a security-boundary gap: with gateway.reload.mode=hot, disabling the terminal can return before terminalLaunchPolicy.prepareConfig and closeDisallowedAgents run, leaving live or in-flight PTYs usable.
  • [P1] The PR changes the newly-main terminal default from enabled to explicit opt-in; that is likely the safer security posture, but maintainers should explicitly accept the compatibility/operator setup impact before merge.

Maintainer options:

  1. Fix hot-mode terminal revocations before merge (recommended)
    Update the reload path so disabling terminal access or tightening agent sandbox policy prepares the terminal policy and closes/refuses affected PTYs before hot mode ignores a restart-only change.
  2. Accept manual-restart semantics explicitly
    Maintainers could choose to let hot mode require a manual restart for terminal disables, but then the PR body, docs, and tests should stop claiming immediate revocation.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Fix the gateway config reload path so restrictive terminal policy changes still notify terminalLaunchPolicy and closeDisallowedAgents before a gateway.reload.mode=hot restart-only change is ignored; update config-reload and terminal policy tests for gateway.terminal.enabled=false under hot mode.

Next step before merge

  • [P1] A narrow automated repair can move terminal policy reconciliation before the hot-mode restart-only return and update the matching regression tests.

Security
Needs attention: Needs attention: a hot-mode ignored restart can leave the browser-exposed host terminal active after an operator disables it.

Review findings

  • [P1] Reconcile terminal revocations before hot-mode skip — src/gateway/config-reload.ts:309-315
Review details

Best possible solution:

Keep the explicit opt-in and active-agent launch policy, but make restrictive terminal revocations reach the terminal policy/session owner before any hot-mode restart-only skip, with focused regression coverage and accepted upgrade semantics.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection reproduces the failure: gateway.reload.mode=hot plus gateway.terminal.enabled true-to-false reaches the restart-only hot-mode return before onConfigChange can prepare terminal revocations.

Is this the best way to solve the issue?

No. The centralized terminal launch-policy owner is the right shape, but the current PR is not the best mergeable fix until restrictive terminal changes are reconciled before the hot-mode skip.

Full review comments:

  • [P1] Reconcile terminal revocations before hot-mode skip — src/gateway/config-reload.ts:309-315
    The previous blocker is still present at the current head. When gateway.reload.mode is hot, a terminal disable remains restart-required and this branch returns before onConfigChange runs; since terminalLaunchPolicy.prepareConfig and closeDisallowedAgents are only reached through that hook, live and pending host PTYs can survive after the operator disables the terminal. Notify the terminal policy owner before returning here or special-case restrictive terminal changes.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7a0188cbd20d.

Label changes

Label justifications:

  • P2: This is a normal-priority but security-sensitive gateway/UI hardening PR with a concrete merge blocker, not a shipped live regression.
  • merge-risk: 🚨 compatibility: Changing terminal default availability can affect current-main/source-build operators that expected the Control UI terminal to appear by default.
  • merge-risk: 🚨 security-boundary: The PR governs a browser-authenticated host PTY surface, and the hot-mode path can leave that surface active after a terminal disable attempt.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The PR carries the protected maintainer label, so the external-contributor proof gate is not applied; the body still lists targeted tests and Testbox validation.
Evidence reviewed

PR surface:

Source +206, Tests +641, Docs +25. Total +872 across 36 files.

View PR surface stats
Area Files Added Removed Net
Source 20 255 49 +206
Tests 12 660 19 +641
Docs 4 25 0 +25
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 36 940 68 +872

Security concerns:

  • [high] Terminal disable can be skipped in hot reload mode — src/gateway/config-reload.ts:309
    Because the hot-mode restart-only branch returns before terminal policy reconciliation, disabling the terminal may not close or block existing host PTYs in that mode.
    Confidence: 0.9

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/config-reload.test.ts.
  • [P1] node scripts/run-vitest.mjs src/gateway/terminal/launch.test.ts.
  • [P1] node scripts/run-vitest.mjs src/gateway/server-methods/terminal.test.ts.

What I checked:

  • Root and scoped policy read: Read root AGENTS.md plus scoped guides for gateway, gateway server methods, UI, and docs; the config/security-sensitive gateway guidance applies to this review. (AGENTS.md:1, 7a0188cbd20d)
  • Hot-mode skip still bypasses reconciliation: At PR head, restart-required config changes in gateway.reload.mode=hot still log and return before opts.onConfigChange runs. (src/gateway/config-reload.ts:309, 5a2822db8165)
  • Test currently locks in skipped notification: The PR head test expects no lifecycle-owner notification when hot mode ignores a restart-only terminal disable, which is opposite the claimed immediate revocation behavior. (src/gateway/config-reload.test.ts:883, 5a2822db8165)
  • Terminal reconciliation only runs through onConfigChange: Managed reload wires onConfigChange to reconcileTerminalSessions, and startGatewayServer prepares terminal policy then closes disallowed live/pending sessions through that path. (src/gateway/server-reload-handlers.ts:741, 5a2822db8165)
  • Terminal launch policy is fail-closed when prepared: createTerminalLaunchPolicy records terminal-disabled and blocked-agent restrictions, but those restrictions only affect RPC/CSP state after prepareConfig is reached. (src/gateway/terminal/launch.ts:175, 5a2822db8165)
  • Previous finding remains unchanged: The only commit after the prior review changed src/scripts/test-projects.test.ts; config-reload.ts has no diff between the reviewed SHA and current head. (src/gateway/config-reload.ts:309, 5a2822db8165)

Likely related people:

  • steipete: Recent current-main commits introduced the embedded operator terminal, terminal UI, and follow-up hardening surface now being changed by this PR. (role: recent feature owner and current PR author; confidence: high; commits: f083f35ddb46, 2399ce7c854d, cd6fde21fde4; files: src/gateway/terminal/launch.ts, src/gateway/terminal/session-manager.ts, ui/src/ui/terminal/terminal-panel.ts)
  • root: Blame for the pre-existing hot-mode restart-skip branch points to the grafted base commit in this checkout, so the exact human owner of older reload behavior is ambiguous. (role: base reload-history committer; confidence: low; commits: c79c38035873; files: src/gateway/config-reload.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-04T20:20:38.546Z sha d5f74a9 :: needs real behavior proof before merge. :: [P1] Reconcile terminal revocations before hot-mode skip

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 4, 2026
@steipete
steipete merged commit 7e8ea61 into main Jul 4, 2026
97 checks passed
@steipete
steipete deleted the codex/fix-terminal-policy branch July 4, 2026 20:34
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 5, 2026
* fix(gateway): harden operator terminal policy

* test(gateway): complete terminal context coverage

* test(gateway): narrow terminal policy mock

* test(gateway): satisfy CSP header lint

* docs: refresh terminal docs map

* test: route terminal temp helper importer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Web Terminal in Control UI Dashboard

1 participant