fix(codex): parse config.toml structurally for hook trust detection#1803
Open
saiprasannasastry wants to merge 1 commit into
Open
fix(codex): parse config.toml structurally for hook trust detection#1803saiprasannasastry wants to merge 1 commit into
saiprasannasastry wants to merge 1 commit into
Conversation
The Codex hook-trust check scraped the user's config.toml with a regex that only matched double-quoted TOML state keys ([hooks.state."..."]). Current Codex serializes state keys as single-quoted literal strings — the natural form on Windows, where backslashes need no escaping — so every approved hook was reported as untrusted: doctor printed "REVIEW NEEDED" for all four hooks and the SessionStart banner nagged about approvals that already existed. Replace the regex with a structural parse via pelletier/go-toml/v2 (promoted from indirect to direct): enumerate the keys of the hooks.state table, which handles literal keys, unescapes basic keys (so "C:\\repo\\..." compares equal to filepath.Join output — the regex could never match those either), and covers dotted-assignment form. Failure semantics are now explicit: HookTrustGaps returns an ok bool, false when hooks.json or config.toml is missing or unparseable. The SessionStart banner still only warns on gaps; doctor prints "Codex hook trust: NOT VERIFIED" instead of a false "✓ OK" when the config can't be parsed — previously a syntax error anywhere in config.toml silently swallowed genuine trust gaps. Fixes entireio#1761 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Entire-Checkpoint: 01KXSV9C6QNJZ5GMCXRBYTW25E
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1761
Problem
On Windows,
entire doctorreported every approved Codex hook asREVIEW NEEDED, and the SessionStart banner nagged about approvals that already existed. The trust check scraped the user'sconfig.tomlwith a regex that only matches double-quoted TOML state keys, while current Codex writes single-quoted literal keys — the natural serialization on Windows, where backslashes need no escaping:As the issue notes, even accepting double quotes wouldn't be enough on Windows: a valid basic-string key carries escaped backslashes (
"C:\\repo\\..."), and the regex captured them raw, so they could never compare equal tofilepath.Joinoutput.Fix
As suggested in the issue: parse
config.tomlstructurally and enumerate the keys underhooks.state, instead of regex-scraping table headers. Usespelletier/go-toml/v2, which was already in the module graph (promoted indirect → direct, no new dependency). This handles literal keys, unescapes basic keys, and covers dotted-assignment form — the surrounding prefix-match logic is unchanged.Failure semantics are now explicit rather than accidental:
HookTrustGapsreturns([]string, bool)— the bool is false whenhooks.jsonorconfig.tomlis missing or unparseable ("can't tell").Codex hook trust: NOT VERIFIEDinstead of a false✓ OKwhen the config can't be parsed. Previously (post-regex-era design carried over), a syntax error anywhere inconfig.tomlwould degrade to "zero trusted keys"; with a structural parse it would otherwise have silently swallowed genuine trust gaps behind an affirmative OK.hooks.statetable still counts as "nothing approved yet" and the gap warning fires.Regression coverage
Per the matrix suggested in the issue, plus the new failure semantics:
'C:\repo\...'comes back verbatim; basic"C:\\repo\\..."unescapes to single-backslash form[hooks.state]NOT VERIFIED(duplicate-key config)hooks.state→ genuine gap still firesVerification
-tags=integration -race: pass; Vogon E2E canary: pass;golangci-lint(pinned 2.11.3) on the full tree: 0 issues✓ OK(all trusted),REVIEW NEEDED(one approval removed), andNOT VERIFIED(malformed config)windows/amd64andwindows/arm64One residual risk worth noting: if Codex ever writes extended-length (
\\?\C:\) paths or different drive-letter casing into state keys, the exact prefix match could still miss — out of scope for this issue, since the reported key format matchesfilepath.Joinoutput.🤖 Generated with Claude Code