Skip to content

fix: enforce trusted-before-project ordering for hooks#15936

Open
viyatb-oai wants to merge 47 commits intomainfrom
codex/viyatb/hooks-trust-precedence
Open

fix: enforce trusted-before-project ordering for hooks#15936
viyatb-oai wants to merge 47 commits intomainfrom
codex/viyatb/hooks-trust-precedence

Conversation

@viyatb-oai
Copy link
Copy Markdown
Collaborator

@viyatb-oai viyatb-oai commented Mar 27, 2026

Summary

  • execute trust-sensitive hook events in trust-precedence tiers so non-project hooks run before project hooks for PreToolUse, SessionStart, and UserPromptSubmit
  • preserve parallel execution within each trust tier while skipping lower-precedence project hooks once a higher-precedence hook blocks or stops processing
  • add regression coverage for prompt/session hook data exposure so project hooks cannot observe those payloads before higher-trust hooks have a chance to stop processing

Security

  • closes the PreToolUse race where a project hook could observe or exfiltrate a tool invocation before a higher-precedence non-project hook denied it
  • closes the analogous prompt/session leak where project UserPromptSubmit or SessionStart hooks could observe prompt or startup data before a higher-precedence hook stopped processing
  • keeps project hook execution aligned with the trust boundary established by fix: trust-gate project hooks and exec policies #14718, which prevents untrusted project-local hook config from loading before trust is granted

Stack

  • Builds on the fix: trust-gate project hooks and exec policies #14718 trust-gate work now in main
  • This PR enforces trust precedence at hook execution time for hook events that can block or stop downstream processing
  • Managed hook policy and enterprise lockdown behavior remain covered by the follow-up managed-hooks PR, not this one

Test

  • cargo test -p codex-hooks
  • cargo test -p codex-hooks higher_precedence_stop_skips_lower_precedence_handlers
  • cargo clippy -p codex-hooks --tests -- -D warnings
  • just argument-comment-lint -p codex-hooks -- --tests

@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from 8dfdefd to a5e69ff Compare March 27, 2026 18:36
@viyatb-oai viyatb-oai marked this pull request as ready for review March 30, 2026 17:22
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9401e5ff84

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/config_loader/mod.rs
@viyatb-oai viyatb-oai changed the title fix: run project pre-tool hooks after trusted hooks fix: enforce trusted-before-project ordering for hooks Mar 30, 2026
Co-authored-by: Codex noreply@openai.com
Co-authored-by: Codex noreply@openai.com
# Conflicts:
#	codex-rs/core/src/tasks/review.rs
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from 9401e5f to f0f222a Compare March 31, 2026 04:39
# Conflicts:
#	codex-rs/core/src/codex_tests.rs
#	codex-rs/core/src/config/mod.rs
#	codex-rs/core/src/config_loader/mod.rs
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from f0f222a to 456697a Compare April 6, 2026 19:40
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from 456697a to c564cda Compare April 7, 2026 03:04
Co-authored-by: Codex <noreply@openai.com>
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from c564cda to 647f61a Compare April 7, 2026 03:41
Co-authored-by: Codex <noreply@openai.com>
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from 647f61a to c22dec5 Compare April 7, 2026 03:53
Keep canonical project trust keys first so persisted trusted project entries keep their existing lookup shape while still matching symlink aliases.

Use the per-thread derived config for app-server thread-initialized analytics and isolate app-server integration subprocesses from host managed config by default.

Co-authored-by: Codex <noreply@openai.com>
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from 15872f2 to 6b3ef89 Compare April 7, 2026 04:45
Use the production project trust key helper in hook trust tests and normalize the migrated project expectation so Windows canonical path handling matches runtime behavior.

Co-authored-by: Codex <noreply@openai.com>
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from 6b3ef89 to d22f07a Compare April 7, 2026 17:59
viyatb-oai and others added 3 commits April 7, 2026 12:02
Session-start hook discovery is disabled on Windows, so trust-loading assertions for hooks are not meaningful there. Keep the cross-platform project trust normalization regression covered separately.

Co-authored-by: Codex <noreply@openai.com>
The session-start hook trust-loading assertions depend on hooks.json lifecycle hook discovery, which is intentionally disabled on Windows. Mark the two coverage tests ignored there so Windows CI stops expecting handlers that cannot load.\n\nCo-authored-by: Codex <noreply@openai.com>
viyatb-oai and others added 3 commits April 7, 2026 12:25
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex noreply@openai.com
Co-authored-by: Codex <noreply@openai.com>
@viyatb-oai viyatb-oai force-pushed the codex/viyatb/hooks-trust-precedence branch from d22f07a to 8110afa Compare April 7, 2026 19:25
viyatb-oai and others added 18 commits April 7, 2026 14:05
The observer hook precedence tests only need an ASCII stdout fixture. Avoid Windows PowerShell as the test shell so the JSON stop/block payload reaches the hook parser reliably when stdout is piped.\n\nCo-authored-by: Codex <noreply@openai.com>
cmd.exe removes unescaped JSON quotes before echoing. Caret-escape the quotes so the observer hook stop/block tests feed valid JSON to the hook output parser on Windows.\n\nCo-authored-by: Codex <noreply@openai.com>
Re-enable hook discovery on Windows so the trust-gating tests cover the real behavior instead of skipping it.

Avoid alias-expanded project maps that can let a configured symlink alias satisfy the canonical project lookup; keep exact/case-normalized matching deterministic instead.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex noreply@openai.com
Co-authored-by: Codex noreply@openai.com
Co-authored-by: Codex noreply@openai.com
Co-authored-by: Codex noreply@openai.com
…om:openai/codex into codex/viyatb/pr15936-p3
Co-authored-by: Codex noreply@openai.com
…om:openai/codex into codex/viyatb/pr15936-p3
viyatb-oai added a commit that referenced this pull request Apr 18, 2026
## Summary
- trust-gate project `.codex` layers consistently, including repos that
have `.codex/hooks.json` or `.codex/execpolicy/*.rules` but no
`.codex/config.toml`
- keep disabled project layers in the config stack so nested trusted
project layers still resolve correctly, while preventing hooks and exec
policies from loading until the project is trusted
- update app-server/TUI onboarding copy to make the trust boundary
explicit and add regressions for loader, hooks, exec-policy, and
onboarding coverage

## Security
Before this change, an untrusted repo could auto-load project hooks or
exec policies from `.codex/` as long as `config.toml` was absent. This
makes trust the single gate for project-local config, hooks, and exec
policies.

## Stack
- Parent of #15936

## Test
- cargo test -p codex-core without_config_toml

---------

Co-authored-by: Codex <noreply@openai.com>
Base automatically changed from codex/viyatb/trusted-project-config-gating to main April 18, 2026 00:57
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