Repository navigation
fix(codex): prevent duplicate config.toml hook trust key on Windows - #6318
Conversation
📝 WalkthroughWalkthroughThe PR normalizes Codex trust paths and hook-state keys to forward slashes. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 37cebdc2-2f83-4bf2-946e-9a241eaf7974
📒 Files selected for processing (3)
src/main/codex/config-toml-trust.test.tssrc/main/codex/config-toml-trust.tssrc/main/codex/hook-service.test.ts
Jinwoo-H
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d8bee9d8-d057-44f3-83e2-f6b1416f61be
📒 Files selected for processing (3)
src/main/codex/config-toml-trust.test.tssrc/main/codex/config-toml-trust.tssrc/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
| function usesWindowsPathSeparators(sourcePath: string): boolean { | ||
| return /^[A-Za-z]:[\\/]/.test(sourcePath) || sourcePath.startsWith('\\\\') | ||
| } |
There was a problem hiding this comment.
🗄️ 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
…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]>
Summary
config.tomlusing different path separator and casing conventions. Orca'sescapeTomlStringdoubles backslashes in a basic-string key; Codex uses literal-string keys with raw backslashes. WhenrealpathSync.nativeadditionally returns a differently-cased path than what Codex wrote (e.g.C:\Users\RodvsC:\Users\rod),findTrustBlockRangescan't match the existing entry and appends a second block, producing duplicate TOML table headers that corrupt the config.getCodexCanonicalTrustPathso Orca writes consistent keys going forward. AddednormalizeTrustKeyPathinfindTrustBlockRangesthat 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 lintpnpm typecheckpnpm testpnpm buildFocused 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: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), andgetTrustedSystemHookHashesByEvent(trust validation). All three callers compare keys that go through the same normalization on both sides — the change is bilateral and consistent.findTrustBlockRanges—normalizeTrustKeyPathapplies 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 whenprocess.platform === 'win32', leaving POSIX paths unaffected.macOS/Linux:
realpathSync.nativeon POSIX resolves symlinks to forward-slash paths — no behavior change. ThenormalizeTrustKeyPathcase-fold is skipped on non-Windows. Forward-slash.replaceon an already-forward-slash path is a no-op. SSH/remote: no network paths or UNC paths in scope —getOrcaManagedCodexHomePathreturns 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.
computeTrustedHashand 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.nativestill 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:
getCodexCanonicalTrustPathhandles new writes (Orca always writes forward-slash keys after this change);findTrustBlockRangeshandles pre-existing Codex-written keys until they are naturally replaced on next upsert. A single-site fix at onlyfindTrustBlockRangeswould match existing keys but leave Orca still writing backslash keys on fresh installs — a latent issue. A single-site fix at onlygetCodexCanonicalTrustPathwould normalize new keys but not find existing Codex-written backslash keys — no dedup. Both sites are required.