Skip to content

fix: reject Codex hooks from a different workspace - #23754

Open
paust0929 wants to merge 2 commits into
stablyai:mainfrom
paust0929:fix/codex-hook-shared-daemon-upstream
Open

paust0929 wants to merge 2 commits into
stablyai:mainfrom
paust0929:fix/codex-hook-shared-daemon-upstream

Conversation

@paust0929

@paust0929 paust0929 commented Sep 29, 2026 •

Copy link
Copy Markdown

ELI5

When Codex reuses a background process started from workspace A, a prompt typed in workspace B can appear in workspace A's status card. A hook that says it ran in B will no longer update A's status.

What Changed

The Codex hook listener checks the hook's working directory against the worktree path stamped on the hook. It resolves path traversal and WSL UNC/Linux path spellings before checking containment, and discards a cross-workspace mismatch before changing status state. Hooks from that worktree and its nested directories still work. Focused regression tests cover these cases.

Why

The shared Codex app-server can inherit the Orca pane environment of the first terminal that started it. The hook includes a working directory, so Orca can reject a provably wrong worktree attribution at the existing status ingestion point. The hook does not include the originating terminal identity, so this change cannot distinguish multiple panes in one worktree; see openai/codex#37537.

Linked Issue

Related: #22873; openai/codex#37537.

Visual Proof

Automated before/after: the new regression presents a FusionRF-stamped hook with an Albedo working directory. Before this change the listener accepts it; after this change it returns null and leaves the pane status untouched. A same-worktree hook in a nested directory still updates the pane. A screenshot from a running build is pending; this is a draft PR.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Linux source checks:

  • Focused Vitest suite: 30 passed.
  • Node TypeScript check: passed with an 8 GB heap.
  • Pre-commit oxlint, react-doctor lint, and oxfmt: passed.
  • Changed-code quality gate: 0 new findings across both changed files.
  • macOS, Windows, SSH, full lint/test/build, and a live Orca UI check: not run; CI and review remain.

AI Disclosure

GPT-6 Codex assisted with diagnosis, implementation, and the focused regression test. The reporter reviewed the diff and local checks.

Review

Agent skill upstream boundary

  • Not applicable; this change copies no upstream skill-installer material.

Notes

The check uses Orca's existing worktree ID parser and cross-platform path containment helper. It changes neither the hook wire format nor a client/server RPC. Hooks without a usable working directory or worktree path retain their current behavior. No installed Orca service or active session was changed to test this patch.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • Full lint, typecheck, test, and build pass; CI will cover broader checks

@paust0929
paust0929 marked this pull request as ready for review September 29, 2026 01:03
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds workspace isolation check to hook processing.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR rejects Codex hooks whose reported working directory falls outside the stamped worktree, while accepting nested directories and Linux paths corresponding to WSL UNC worktrees.

  • Adds regression coverage for mismatched, traversing, same-worktree, and WSL hook paths.

Reviews (2) · Last reviewed commit: "fix: normalize Codex hook paths before w..."

Comment thread src/shared/agent-hook-listener.ts Resolved
@coderabbitai

coderabbitai Bot commented Sep 29, 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: 558fbdba-63f5-497c-8e33-ad9c22bd95be

📥 Commits

Reviewing files that changed from the base of the PR and between d382710 and 0d534c2.

📒 Files selected for processing (2)
  • src/shared/agent-hook-listener-hermes-codex-droid.test.ts
  • src/shared/agent-hook-listener.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/agent-hook-listener-hermes-codex-droid.test.ts
  • src/shared/agent-hook-listener.ts

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


📝 Walkthrough

Walkthrough

Codex hook normalization now checks the payload’s cwd against its stamped worktree path. It rejects the payload when both paths are present and the runtime-resolved cwd is outside the worktree. For WSL UNC worktrees, it uses the parsed Linux path for Unix-style cwd values that are not UNC paths. Tests cover outside paths, descendant paths, and WSL path forms.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0d534

Codex hooks from another workspace are rejected in the inspected cases, while hooks from the stamped worktree continue to work. The change is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to d3827

The change prevents the demonstrated cross-workspace status update without changing the hook format. It is a partial safeguard, not proof that every hook belongs to its claimed workspace.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated outcome is wrong-pane status attribution, including a session ID and tool-input preview. The available evidence does not establish that this hook path grants filesystem or service privileges.

Security Findings and Attack Paths

  • inferred — A sender able to control the incoming stamp and payload can supply agreeing values, so the new rule cannot authenticate origin. This residual capability predates the rule; its effective reachability to an attacker is not established.

Trust Boundaries and Controls

  • observed — The new control rejects a present, textually outside cwd before status-event construction, but does not enforce containment when cwd or a parseable worktree path is missing.
  • inferred — The string comparison does not resolve dot segments: a cwd containing a parent traversal can match the stamped prefix while denoting a location outside it. Whether the production producer emits such a cwd is unverified; the PR does not newly enable this pre-existing attribution route.

Resilience and Maintainability Implications

  • observed — The regression covers a simple mismatch and a nested accepted path, but not missing fields, noncanonical paths, or repetition; a rejected hook may still consume a diagnostic warning-deduplication entry before the new gate.

Hardening Proposals

  • proposed — If this comparison must establish semantic containment, define canonical-path handling for both fields and test traversal and alias cases. Treat sender-supplied agreement as a consistency check rather than authentication of pane origin.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting Codex hooks from a different workspace.
Description check ✅ Passed The description covers the user impact, implementation, rationale, linked issues, testing, AI disclosure, cross-platform considerations, and checklist status. Visual proof is pending, but this is a sm…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4d9b40e4-7a2a-4862-909f-491b0acfa67f

📥 Commits

Reviewing files that changed from the base of the PR and between da48d98 and d382710.

📒 Files selected for processing (2)
  • src/shared/agent-hook-listener-hermes-codex-droid.test.ts
  • src/shared/agent-hook-listener.ts

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

Comment thread src/shared/agent-hook-listener.ts Resolved

@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.

Caution

On a Windows WSL pane this gate rejects the pane's own Codex hooks, so Codex status stops updating for every WSL workspace. The stamped worktree path is a UNC path (repo::\\wsl.localhost\Ubuntu\..., forwarded untranslated through WSLENV as /u), while Codex runs inside the distro and reports a Linux cwd; isPathInsideOrEqual folds the UNC root to //wsl/<distro>/... and never bridges it to the Linux spelling, so the containment test is always false.

Reviewed changes

  • Codex cwd/worktree containment gate — normalizeHookPayload now reads the Codex hook payload's cwd, derives the stamped worktree path with splitWorktreeIdForFilesystem, and returns null when cwd is not inside it; hooks lacking either value keep prior behavior.
  • Regression test — rejects a FusionRF-stamped hook carrying an Albedo cwd and accepts a same-worktree hook from a nested directory.

ℹ️ This mitigates attribution, not the daemon-lifecycle half of #22873

The linked issue reports two symptoms: hooks misattributed to the wrong pane, and releasing the first worker killing the sibling because the shared daemon is its child. This change only addresses the first. The PR body already notes hooks cannot distinguish panes within one worktree, but the sibling-death symptom is also untouched; worth confirming it is tracked separately (upstream openai/codex#37537) so the issue is not closed as fully resolved.

Technical details
# Scope of the fix

## Affected sites
- `src/shared/agent-hook-listener.ts:48-55` — rejects on a `cwd` outside the stamped worktree path.

## Open questions for the human
- Is the daemon-lifecycle symptom (releasing worker A terminates worker B) intended to be fixed here, or tracked upstream only?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/shared/agent-hook-listener.ts Outdated
Comment on lines +49 to +54
const stampedWorktreePath = stampedWorktreeId
? splitWorktreeIdForFilesystem(stampedWorktreeId)?.worktreePath
: undefined
// Codex's shared app-server can inherit another pane's Orca env; reject a mismatched session.
if (codexCwd && stampedWorktreePath && !isPathInsideOrEqual(stampedWorktreePath, codexCwd)) {
return null

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.

This rejects valid Codex hooks on Windows WSL workspaces. For a WSL pane, ORCA_WORKTREE_ID is repo::\\wsl.localhost\Ubuntu\... (crossed via WSLENV as /u, so the UNC string is imported verbatim), while the Codex process runs inside the distro and reports cwd as /home/...; isPathInsideOrEqual maps the UNC root to //wsl/<distro>/... and never bridges it to the Linux spelling, so the test is always false and every Codex hook is dropped.

Technical details
# WSL UNC worktree path vs Linux Codex cwd

## Affected sites
- `src/shared/agent-hook-listener.ts:49-54` — compares the stamped UNC worktree path against a Linux cwd.
- `src/shared/cross-platform-path.ts:190-194` — `isPathInsideOrEqual` normalizes the UNC root to `//wsl/<distro>/...` but leaves `/home/...` unchanged; the alias helpers (`isWslUncPathForCallerLinuxPath`, `toWindowsWslPath`) are not applied here.
- `src/main/pty/wsl-orca-env.ts:87` — `ORCA_WORKTREE_ID/u` imports the UNC string untranslated into the distro.

## Required outcome
- A WSL Codex hook whose `cwd` is the distro-side spelling of the stamped worktree must still be accepted.
- Add coverage for the UNC-root + Linux-cwd case; the added test only exercises Linux-vs-Linux paths.

## Suggested approach
- When the stamped path parses as a WSL UNC path (`parseWslUncPath`), compare `cwd` against the parsed `linuxPath`, or fold both sides through the WSL alias handling already used elsewhere.

## Open questions for the human
- Should a canonicalized/symlinked workspace root also be tolerated? Codex `getcwd` resolves symlinks while Orca stores the chosen spelling, so the same pure-string containment can reject a local workspace.

@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.

Important

The new WSL handling closes the UNC-root case but not a Windows-drive repo opened in a WSL terminal: the stamped path is C:\repo while Codex reports a /mnt/c/repo cwd, and the containment test rejects it, dropping the pane's own hooks.

Reviewed changes (incremental since d382710)

  • WSL UNC root vs Linux cwd — when the Codex cwd is a Linux path and the stamped worktree parses as a WSL UNC path, comparisonRoot now uses parseWslUncPath(...).linuxPath; both sides pass through resolveRuntimePath(..., '.') so a/../b traversal is resolved before the containment test.
  • Tests — added a WSL case (Linux cwd against a UNC root, a UNC-form cwd, and a .. escape that must be rejected) plus a ..-traversal rejection in the original test.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +54 to +58
const wslRoot = parseWslUncPath(stampedWorktreePath)
const comparisonRoot =
wslRoot && codexCwd.startsWith('/') && !codexCwd.startsWith('//')
? wslRoot.linuxPath
: stampedWorktreePath

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.

This covers a distro-internal workspace but not a Windows-drive repo opened in a WSL terminal. There the stamped path is C:\repo (ORCA_WORKTREE_ID/u imports it verbatim) while Codex runs in the distro with cwd /mnt/c/repo; parseWslUncPath returns null for a drive path, so comparisonRoot stays C:\repo and isPathInsideOrEqual('C:\repo', '/mnt/c/repo') is false — every hook from that pane is dropped.

Technical details
# Windows drive-rooted worktree in a WSL terminal

## Affected sites
- `src/shared/agent-hook-listener.ts:54-58` — a drive-rooted stamped path falls through to the raw string, so it is never translated to the drvfs spelling Codex reports.
- `src/shared/wsl-paths.ts:47-63` — `toLinuxPath` maps `C:\...` to `/mnt/c/...` (platform-independent drive branch); its UNC branch is `win32`-guarded, which is why `parseWslUncPath` is needed for the distro-internal case.
- `src/main/providers/windows-shell-args.ts:241-244` — a drive-rooted repo's WSL shell starts at the `/mnt/<drive>` spelling, and `src/main/pty/wsl-orca-env.ts:87` forwards `ORCA_WORKTREE_ID/u` untranslated.

## Required outcome
- A Codex hook whose stamped worktree is a Windows drive path and whose Linux `cwd` is that path's `/mnt/<drive>` spelling must still be accepted.

## Suggested approach
- When `codexCwd` is a Linux path, normalize a drive-rooted `stampedWorktreePath` through `toLinuxPath` before comparing; keep the `parseWslUncPath().linuxPath` branch for UNC roots. Add a regression case mirroring the UNC one.

## Open questions for the human
- Is a Windows-path repo launched in a WSL terminal in scope for Codex status? The docs describe that configuration as supported.

This branch has not been deployed

No deployments
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.

1 participant