Skip to content

🤖 fix: block a Codex PreToolUse call when its hook output is malformed - #7834

Merged
ThomasK33 merged 9 commits into
mainfrom
cursor-plugins/codex-pretooluse
Oct 31, 2026
Merged

ThomasK33 merged 9 commits into
mainfrom
cursor-plugins/codex-pretooluse

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

A Codex PreToolUse hook whose output is malformed or fails its schema check now blocks the tool call instead of being ignored. The user sees one notice that names the plugin and says how to turn the hook off. Every other Codex hook failure keeps failing open: a timeout, an MCP error result, a missing server, and broken output from PostToolUse, UserPromptSubmit and Stop.

Background

This is PR 6 of the Cursor plugin RFC, decision D8: rfc/20261030_cursor-plugin-support.md (RFC PR #7829), section "PR 6", section 5.5 and the section 8 row. It needs no other PR of the program.

Before this PR, a trusted PreToolUse guard with broken output let every matching call through, silently. The owner chose the more secure rule: a guard that cannot be read blocks. Codex itself fails such a hook open, so this is a deliberate Xum difference.

Implementation

  • codexHookRunner.ts: invoke takes a malformed option beside inputTooLarge. Only the PreToolUse call sets it. It returns the deny its output is malformed: <detail> and emits one plugin.hook.notice. applyOutput now runs parse. A parse error or an invalid output goes through rejectOutput, which blocks when malformed is set and warns and ignores otherwise.
  • The block reason and the notice carry the parser's detail, so no detail quotes the hook's own keys or values (a hook can put a secret there). An invalid enum value reads invalid <field> value, an unknown field returned <where> with an unknown field.
  • An MCP tool error (isError: true) still fails open, although parse throws for it. It is the hook failing, not its output (RFC 5.5, "an error from the MCP call").
  • codexHookOutput.ts: Codex's looks_like_json rule. Text that starts with { or [ must be a JSON object, so [] or a list of findings is malformed. Other text, a bare JSON scalar such as true included, is plain text and is ignored, as in Codex.
  • docs/hooks/plugins.mdx: new "What blocks a PreToolUse call" list and a rewritten "What fails open" list. builtInSkillContent.generated.ts is regenerated from the page.

Validation

  • Unit tests cover every RFC 6.2 case. The changed tests fail on the base runner.
  • A real-instance proof (not committed) ran the real plugin files, registry and trust store, the real CodexPluginHookService and EventSpine, Xum's MCP client and a real stdio MCP server. At the base, every malformed case lets rm -rf build run. At the head, each one blocks with one notice. A tool error, a missing server, a timeout, valid output and plain text still let the call through.
  • An independent verifier ran its own 16-case and 5-case harnesses on the same real path and returned CLEAN at 7c7a4eb.

Risks

  • A hook that relied on fail-open now blocks every matching call. The notice names the plugin, the reason and how to turn the hook off, so the block is visible. The model sees the same reason as the tool error.
  • The most likely trigger is a hook ported from Claude Code that answers a bare permissionDecision: "allow". Codex reports that as unsupported and runs the call. Xum now blocks it. See the release note.

Release note

A Codex PreToolUse hook whose output is malformed or fails its schema check now blocks the tool call instead of being ignored. A chat line names the plugin and the hook, and says how to turn the hook off in Settings > Plugins.

This includes eight outputs that Codex marks as a failed hook run and then runs the call anyway. In Xum, each of them now blocks a matching call (an explicit deny in the same output still applies with its own reason):

  1. A bare permissionDecision: "allow" (without updatedInput).
  2. permissionDecision: "ask".
  3. The legacy decision: "approve".
  4. continue: false.
  5. stopReason.
  6. suppressOutput: true.
  7. updatedInput without permissionDecision: "allow".
  8. A reason without a decision (reason or permissionDecisionReason).

Text that starts with { or [ but is not a JSON object (for example [] or a list of findings) and a result over 1 MiB block too. Text that does not start with { or [, a bare JSON scalar such as true included, stays plain text and is ignored, as in Codex.

A timeout, an MCP error result, a missing server and broken output from PostToolUse, UserPromptSubmit and Stop still fail open.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

A Codex PreToolUse hook whose output is malformed or fails its schema check
now blocks the tool call instead of being ignored (Cursor plugin RFC, D8,
PR 6). The model gets "Tool call blocked by plugin '<plugin>' hook: its
output is malformed: <detail>", and the user gets one plugin hook notice
that names the hook and how to turn it off.

invoke takes a `malformed` option beside `inputTooLarge`; only PreToolUse
sets it. A parse throw or an `invalid` output returns that decision. Every
other failure keeps failing open: a timeout, an MCP call error, a missing
server, an MCP tool error (isError), and malformed PostToolUse,
UserPromptSubmit and Stop output.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
Comment pass over the previous commit: drop comments that restate the code
or an assertion, and name the inputTooLarge block in the runner's failure
rule next to blockRewrite.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
Verifier findings on 0699b8c:

- A PreToolUse guard whose output text was a JSON array (`[]`, a list of
  findings) or another non-object JSON value still let the call run, with no
  notice and no warning. Such text is now a malformed output: PreToolUse
  blocks the call with the notice, and the other events fail open with a
  warning. Plain text that is not JSON stays ignored.
- docs/hooks/plugins.mdx still said malformed PreToolUse output fails open.
  It now lists what blocks a PreToolUse call (bare `allow`, `ask` and
  legacy `approve` included, unlike Codex) and what still fails open. The
  built-in xum-docs skill content is regenerated from it.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
Re-verifier findings on 58a832c. Follow Codex's looks_like_json rule
exactly: only text that starts with `{` or `[` and is not a JSON object is
malformed (a PreToolUse call blocks with the notice). Other text, a bare
JSON scalar such as `42`, `"ok"`, `true` or `null` included, is plain text
and is ignored on PreToolUse, as before this PR. A hook written to Codex's
contract that answers `true` no longer blocks every matching call.

docs/hooks/plugins.mdx now says which text is ignored and which is
malformed. The built-in xum-docs skill content is regenerated from it.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
Verifier follow-ups on 7c7a4eb: the codexHookOutput.ts header and the
docs/hooks/plugins.mdx failure lists now say "starts with `{` or `[` and is
not a JSON object", so they no longer read as covering a bare scalar such as
`42`. The built-in xum-docs skill content is regenerated from the page.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
@mintlify

mintlify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Mux 🟢 Ready View Preview Oct 31, 2026, 11:20 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T23:25:42.753721Z e0bab7c Manual request
🔒 Security Review ✅ Completed 2026-10-31T23:25:44.729224Z e0bab7c Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

22 agent steps · 7 replayed from cache · 15 model calls · 47.1k tokens (27% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 4.8s
🟢 a chat survives a restart of the server 1 step · 1 call 4.8s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.3s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.3s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 9.0s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 9.0s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 8.4s
🟢 a chat survives trips through Settings 2 steps · 1 call 8.4s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.4s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.4s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.4s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.4s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 8.2s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 8.2s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 2.6s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 2.6s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 20.7s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.5s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.6s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.1s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 2.9s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 3.1s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 2.5s

e2e 0.20.0 · 1m 8s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 7.9k tokens (33% cached)
Spend: $0.01 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 5.1s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 5.1s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 6.0s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 6.0s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 5.4s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 5.4s

e2e 0.20.0 · 18.9s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 5.8s · 2 targets (web, phone) · run artifacts

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: 599c48a

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 599c48a682

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

Copy link
Copy Markdown

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: 599c48a682

ℹ️ 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".

…k reason

Codex review P1 on 599c48a: a PreToolUse block shows the parser's detail
to the model (tool error) and to the user (notice). Two details quoted the
hook's own data: an invalid enum value and an unknown field name, where a
hook can put a secret. Both messages are now value-free ("invalid
permissionDecision value", "returned output with an unknown field"). This
also covers the existing deny of a voided rewrite, which quoted the
unknown field name.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: 7aa6cae

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 7aa6caeacd

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7aa6caeacd

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 31, 2026
Main (PR 7, per-hook stop limits) replaced `stopHookActive` in
TurnStopHookInput with `turnContinuations` and `hookContinuations`. Two
runTurnStopHooks calls that this branch added still passed the old field
and failed the merge-group typecheck. They now pass main's shape. No
behavior change.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh -->
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: e0bab7c

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e0bab7ca6f

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e0bab7ca6f

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 89a8d14 Oct 31, 2026
34 of 35 checks passed
@ThomasK33
ThomasK33 deleted the cursor-plugins/codex-pretooluse branch October 31, 2026 23:41

This branch was successfully deployed

1 active deployment
staging - docs — e0bab7ca Deployed Oct 31, 2026 by mintlify[bot]
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