Skip to content

fix(runtime): keep loopback agent-hook env out of SSH terminals - #25520

Closed
matbrgz wants to merge 2 commits into
stablyai:mainfrom
UndefinedDump:fix/ssh-terminal-agent-hook-env
Closed

matbrgz wants to merge 2 commits into
stablyai:mainfrom
UndefinedDump:fix/ssh-terminal-agent-hook-env

Conversation

@matbrgz

@matbrgz matbrgz commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

ELI5

Orca gives each terminal a small "address and password" so coding agents inside it can report their status back to the app. That address only works on your own computer. Terminals running on a remote machine over SSH were being handed your computer's address and password anyway. Now they aren't; the remote machine keeps using the address Orca's remote helper gives it.

What Changed

  • buildTerminalWorkspaceEnv only adds the local agent-hook env (buildAgentHookPtyEnv()) when the terminal's scope is local (connectionId === null), the same gate already used for the jcode runtime dir.
  • Before: SSH terminals created by the runtime got the desktop's loopback hook port, token and local endpoint path. After: they get none of them; stale inherited copies were already stripped and stay stripped. Pane identity (ORCA_PANE_KEY, ORCA_TAB_ID, ORCA_WORKTREE_ID) is unchanged.

Why

The hook port/token are a secret for a receiver bound to the desktop's 127.0.0.1, and the endpoint is a desktop file path the hook scripts source. On a remote host they either leak to whatever listens on that remote port or point at nothing. Remote hooks already get host-valid values from the relay's hook server on that host, so nothing remote depends on the desktop values. Gating at the single env builder (used by both create and split) is the smallest change; stripping later at the SSH spawn boundary was considered but would still mint and pass the secret through more layers first.

Linked Issue

Fixes #25519

Visual Proof

N/A — no UI change; this only changes the environment variables passed to SSH-hosted terminal processes.

Testing

  • Automated tests added/updated, or explained why not below

  • I manually tested these changes locally

  • New regression test src/main/runtime/orca-runtime-tests/ssh-terminal-agent-hook-env.spec.ts (wired into orca-runtime.test.ts): creates a terminal on an SSH repo with a hook env builder and asserts none of the five hook keys reach the spawn, while pane identity does. Verified it fails before the fix (ORCA_AGENT_HOOK_PORT: expected '54321' to be undefined) and passes after.

  • npx vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts — 1350 passed (includes the existing local hook-injection test, still green).

  • pnpm lint — pass.

  • pnpm typecheck — pass.

  • Full pnpm test and pnpm build not run locally; relying on CI.

  • Platforms: macOS only, via unit tests; no live SSH session tested.

AI Disclosure

Implemented with Claude Code (Claude Opus 5.5); reviewed by the author.

Review

  • Security: stops sending a loopback auth token and a local path to remote hosts.
  • SSH: remote agent status keeps working through the relay hook server, which already supplies its own coordinates; no change when the relay is up, and no desktop secret fallback when it is down.
  • Agents: local terminals keep identical hook env (existing test covers it).
  • Cross-platform: pure env logic, no path or platform assumptions.
  • Performance: skips minting a hook env for remote terminals; otherwise none.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred) — lint and typecheck pass locally; full test suite and build left to CI

buildTerminalWorkspaceEnv injected buildAgentHookPtyEnv() for every
runtime-created terminal, so SSH-hosted terminals received the desktop's
127.0.0.1 hook port, auth token and local endpoint path. On the remote
host those point at the remote loopback and a desktop-only file; the
relay hook server supplies host-valid coordinates instead. Only the
jcode runtime dir was guarded; apply the same local-only gate to the
hook env.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa504a0d-ca1a-410b-a4a8-1c7ad9ee81b7
📥 Commits

Reviewing files that changed from the base of the PR and between c8bde74 and eb52e65.

📒 Files selected for processing (1)
  • src/main/runtime/orca-runtime-resolve-browser-network-execution-host-for-worktree.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/orca-runtime-resolve-browser-network-execution-host-for-worktree.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

buildTerminalWorkspaceEnv now adds agent-hook PTY environment variables only for local workspaces. A new SSH terminal test checks that the spawn request uses the SSH connection ID, excludes loopback hook variables even when a hook token is inherited, and includes pane and tab identifiers. The runtime test entrypoint imports this test.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to eb52e

The SSH terminal environment change appears ready to merge after normal checks. No actionable regression was identified.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to c8bde

The change stops desktop hook credentials from being included in SSH terminal requests while preserving local behavior and independently supplied remote credentials. No material security risk was found to be introduced or worsened.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The security-relevant change removes desktop hook coordinates and credentials from SSH spawn requests. Those requests previously contained desktop values, but the inspected relay overrides hook coordinates with its own values; the evidence therefore supports reduced credential propagation, not a claim that every prior remote process received usable desktop credentials.

Security Findings and Attack Paths

  • observed — The supplied Security assessment retains no findings. Its rejected hook-key reintroduction candidate is consistent with the inspected producer: Agent Teams returns explicitly selected team and shim variables without copying inherited hook credentials into its environment overlay.

Trust Boundaries and Controls

  • observed — The builder deletes the six defined hook runtime keys from a copy of the incoming environment before assembly. Desktop hook values are then added only when connectionId is exactly null; SSH requests preserve terminal identity without receiving those desktop values.

Resilience and Maintainability Implications

  • inferred — The desktop callback reads an existing server's environment rather than allocating or rotating credentials. Skipping that read for SSH changes only the per-request projection: repeated or concurrent calls do not introduce shared credential writes, and partial failure or interruption cannot leave a new credential reservation requiring cleanup.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: keeping loopback agent-hook environment values out of SSH terminals.
Description check ✅ Passed The description covers the required sections, explains the change and reason, links the issue, gives a justified N/A for visual proof, and reports tests and review considerations. It also states that …
Linked Issues check ✅ Passed Issue #25519 requires runtime-created SSH terminals to omit the desktop's five ORCA_AGENT_HOOK_* values. buildTerminalWorkspaceEnv removes inherited hook keys and now adds buildAgentHookPtyEnv()…
Out of Scope Changes check ✅ Passed The environment gate and SSH regression test directly support issue #25519. The local-scope variable and comment clarify that gate. The test import only enables the new regression test. No unrelated c…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Gate loopback agent-hook env on local scope — buildTerminalWorkspaceEnv now computes isLocal = scope.connectionId === null and only spreads buildAgentHookPtyEnv() when local, so SSH terminals no longer receive the desktop's loopback port/token or its local endpoint path. Pane identity is unchanged.
  • Regression test added — ssh-terminal-agent-hook-env.spec.ts creates a terminal on an SSH repo and asserts the five hook keys never reach spawn while ORCA_PANE_KEY/ORCA_TAB_ID do; wired into orca-runtime.test.ts.

This matches the existing contract on the local PTY path (buildPtyHostEnv's "do not call for SSH" doc), and remote hooks keep working because the relay's own hook server registers buildPtyEnv() as a PTY env augmenter (src/relay/relay-agent-hook-runtime.ts:76), which wins over renderer-supplied env (src/relay/pty-handler.ts:900). WSL and runtime hosts stay local here, so they are unaffected.

Verified locally against c8bde74: full orca-runtime.test.ts passes (1350 passed, 1 skipped), the new test fails when the gate is ablated (ORCA_AGENT_HOOK_PORT: expected '54321' to be undefined), and oxfmt --check/oxlint are clean on the changed files.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @matbrgz, this was a real problem with the old design. The legacy SSH relay has since been removed (#27214, #27215): SSH terminals are now spawned by Orca's managed server on the host, which injects its own hook receiver address (agent hooks are set up when it starts, #27319), and the desktop no longer spawns SSH terminals itself, so its loopback hook env can't reach them. Closing as resolved.

@OrcaWin OrcaWin closed this Oct 11, 2026
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.

[Bug]: SSH terminals created by the runtime receive the desktop's loopback agent-hook port, token and endpoint path

2 participants