Skip to content

fix(codex): prevent duplicate config.toml hook trust key on Windows - #6318

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
rodboev:pr/fix-codex-toml-trust-windows
Jun 25, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
rodboev:pr/fix-codex-toml-trust-windows

Conversation

@rodboev

@rodboev rodboev commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On Windows, Orca and Codex write the hook trust key to config.toml using different path separator and casing conventions. Orca's escapeTomlString doubles backslashes in a basic-string key; Codex uses literal-string keys with raw backslashes. When realpathSync.native additionally returns a differently-cased path than what Codex wrote (e.g. C:\Users\Rod vs C:\Users\rod), findTrustBlockRanges can't match the existing entry and appends a second block, producing duplicate TOML table headers that corrupt the config.
  • Normalized path separators to forward slashes in getCodexCanonicalTrustPath so Orca writes consistent keys going forward. Added normalizeTrustKeyPath in findTrustBlockRanges that normalizes separators and case-folds on Windows before comparing, so existing Codex-written backslash/camel-case keys are found and replaced rather than duplicated.

Closes #6163.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused validation run in this session:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/codex/config-toml-trust.test.ts src/main/codex/hook-service.test.ts — 99 tests passed, 0 failed (77 in config-toml-trust.test.ts including 4 new Windows path tests, 22 in hook-service.test.ts)
  • pnpm run typecheck:node — passed (no errors)

AI Review Report

Reviewed on macOS, Linux, and Windows. The change touches two functions in config-toml-trust.ts:

  1. getCodexCanonicalTrustPath — adds .replace(/\\/g, '/') to the return value on both the success and fallback paths. This affects all callers: computeTrustKey (trust key construction), removeStaleRuntimeHookTrustEntries (stale key comparison in hook-service.ts), and getTrustedSystemHookHashesByEvent (trust validation). All three callers compare keys that go through the same normalization on both sides — the change is bilateral and consistent.

  2. findTrustBlockRanges — normalizeTrustKeyPath applies only to the comparison; it does not modify what is stored in the file. Existing Codex-written keys with raw backslashes will be found, their blocks replaced with the Orca-written forward-slash form on next upsert. Case-fold applies only when process.platform === 'win32', leaving POSIX paths unaffected.

macOS/Linux: realpathSync.native on POSIX resolves symlinks to forward-slash paths — no behavior change. The normalizeTrustKeyPath case-fold is skipped on non-Windows. Forward-slash .replace on an already-forward-slash path is a no-op. SSH/remote: no network paths or UNC paths in scope — getOrcaManagedCodexHomePath returns an app-local Electron user-data path. Provider-neutral: trust key format change is internal to Orca's TOML subsystem.

Security Audit

The trust key change is additive — it normalizes path representation for comparison without changing trust evaluation logic. computeTrustedHash and trusted-hash validation are unaffected. Path traversal: the normalized forward-slash form is used only for TOML key identity, not as a filesystem path for any read or write operation. realpathSync.native still resolves the real path for filesystem operations; only the trust key derived from it is normalized. No privilege escalation risk.

Notes

The fix is two-site intentionally: getCodexCanonicalTrustPath handles new writes (Orca always writes forward-slash keys after this change); findTrustBlockRanges handles pre-existing Codex-written keys until they are naturally replaced on next upsert. A single-site fix at only findTrustBlockRanges would match existing keys but leave Orca still writing backslash keys on fresh installs — a latent issue. A single-site fix at only getCodexCanonicalTrustPath would normalize new keys but not find existing Codex-written backslash keys — no dedup. Both sites are required.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR normalizes Codex trust paths and hook-state keys to forward slashes. getCodexCanonicalTrustPath() now normalizes paths on both success and fallback, findTrustBlockRanges() compares normalized keys, and readHookTrustEntries() stores normalized map keys. Tests were updated for Windows path handling, hook trust upserts, TOML header escaping, CRLF preservation, and normalized project trust headers.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR’s main Windows trust-key deduplication fix and is concise.
Description check ✅ Passed The description covers all required sections, including summary, tests, AI review, security audit, and notes.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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: Pro

Run ID: 37cebdc2-2f83-4bf2-946e-9a241eaf7974

📥 Commits

Reviewing files that changed from the base of the PR and between bad9afe and 7cffe26.

📒 Files selected for processing (3)
  • src/main/codex/config-toml-trust.test.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service.test.ts

Comment thread src/main/codex/config-toml-trust.ts Resolved
@Jinwoo-H
Jinwoo-H self-requested a review June 25, 2026 02:05

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

Thanks, this is the right fix direction. I added a small follow-up to make the normalization consistent across read/status/stale-cleanup paths, avoid rewriting POSIX/SSH literal backslashes, and preserve old backslash-form project trust blocks.

Validated:

  • focused Codex TOML trust + hook-service tests
  • node/full typecheck
  • lint
  • Electron headless hook-endpoint smoke

@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: Pro

Run ID: d8bee9d8-d057-44f3-83e2-f6b1416f61be

📥 Commits

Reviewing files that changed from the base of the PR and between 7cffe26 and 09851a3.

📒 Files selected for processing (3)
  • src/main/codex/config-toml-trust.test.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex/config-toml-trust.test.ts

Comment on lines +140 to 142
function usesWindowsPathSeparators(sourcePath: string): boolean {
return /^[A-Za-z]:[\\/]/.test(sourcePath) || sourcePath.startsWith('\\\\')
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Handle forward-slash UNC paths when generating header variants.

getCodexCanonicalTrustPath() can normalize \\server\share\project to //server/share/project, but usesWindowsPathSeparators() returns false for that normalized UNC form. Then buildProjectHeaderPattern() won’t add the backslash variant, so an existing [projects."\\\\server\\share\\project"] header can still be missed and duplicated.

Suggested fix
 function usesWindowsPathSeparators(sourcePath: string): boolean {
-  return /^[A-Za-z]:[\\/]/.test(sourcePath) || sourcePath.startsWith('\\\\')
+  return /^[A-Za-z]:[\\/]/.test(sourcePath) || /^[\\/]{2}[^\\/]/.test(sourcePath)
 }

Also applies to: 420-423

@Jinwoo-H
Jinwoo-H merged commit 1732648 into stablyai:main Jun 25, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#6318)

* fix(codex): prevent duplicate config.toml hook trust key on Windows (stablyai#6163)

* fix codex hook trust key normalization

---------

Co-authored-by: Jinwoo Hong <[email protected]>
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]: Orca-managed Codex CODEX_HOME config.toml throws "duplicate key" because hooks.state keys are serialized two different ways

2 participants