Repository navigation
fix(guardrails): check Responses tools in namespace and tool_search_output against allowed_tools - #49132
Open
Acacian wants to merge 1 commit into
Open
fix(guardrails): check Responses tools in namespace and tool_search_output against allowed_tools#49132Acacian wants to merge 1 commit into
Acacian wants to merge 1 commit into
Conversation
Acacian
force-pushed
the
fix-responses-namespace-tool-allowlist
branch
from
October 30, 2026 09:21
5a4c938 to
c00cf18
Compare
Closed
3 of 6 tasks
…ls against allowed_tools extract_request_tool_names for /v1/responses read only flat function, custom and mcp tools. Codex groups MCP tools in a `namespace` tool, and with tool_search the deferred tools arrive only in an input[] tool_search_output, so a key/team allowed_tools list never saw them and let them through. Open namespace tools (top level and inside additional_tools items) into their members and add the tools a tool_search_output in input[] loads, reusing the helpers the chat-path replay already uses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UdzBQQSPWtuGErP5D6XkXj
Acacian
force-pushed
the
fix-responses-namespace-tool-allowlist
branch
from
November 8, 2026 01:12
c00cf18 to
315ca3d
Compare
Contributor
|
bugbot run |
Contributor
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 315ca3d. Configure here.
Contributor
|
Codex 0.167.0 on real OpenAI bypassed restricted keys before and got 403 after, for both team-default and gpt-5.6-luna. Allowed controls passed.
|
4 of 6 tasks
8 tasks done
This branch has not been deployed
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.
A key or team with
allowed_toolsset could still use tools outside that list on/v1/responseswhen the request carried them inside anamespacetool or atool_search_outputinput item. Codex sends its MCP and multi-agent tools insidenamespacetools, so the list never applied to them. This PR makes the allowlist open those groups too, using the parsers the proxy already has for these shapes.Details
TLDR
Problem this solves:
allowed_toolsignores tools inside a Responsesnamespacetoolnamespaceinside anadditional_toolsinput itemtool_search_outputinput item loadsHow it solves it:
namespaceinto its member toolstool_search_outputinput itemsadditional_toolsitems are already read on main, so this PR leaves them aloneIntentional product change: a key that worked with Codex can now get 403, because names Codex sends inside these groups are checked for the first time (see Caveats)
Updated after rebasing onto main (315ca3d): the
additional_toolsextraction this PR first carried has since landed on main, so it was dropped hereUser Flow
Before: a proxy admin limits a key's tools, but Codex on that key still calls an MCP tool outside the list
allowed_toolsset to the ten flat tools Codex sends, withoutsearch_issuessearch_issuessearch_issues; Codex sends POST https://litellm-domain/v1/responses withsearch_issuesinside anamespacetoolsearch_issues, and Codex prints its resultAfter: the same request is refused because it carries tools that are not on the key's list
allowed_toolsset to the ten flat tools Codex sends, withoutsearch_issuessearch_issuessearch_issues; Codex sends POST https://litellm-domain/v1/responses withsearch_issuesinside anamespacetoolTool(s) [..., 'search_issues'] are not in the allowed tools list for this key/team.Before this change, anyone with a restricted key could use tools outside the list by sending them in one of these shapes. After it, they can't.
Relevant issues
Related to #40583 and #41011, which cover the
tool_permissionguardrail. This PR does not touch that guardrail, so it does not conflict with #41011.Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
The Codex runs below were done at c00cf1823c, before the rebase, against a real model. After the rebase the
team-defaultcases were rerun at main (07c7229) and the tip (315ca3d) with Codex 0.167.0, see "Rerun after the rebase" at the end. Thegpt-5.6-lunacases were not rerun: they now depend on theadditional_toolsextraction that main carriesBoth runs use the same proxy config on Postgres, against a real model through a ChatGPT account, no mocks. The same model sits behind two names: Codex knows
gpt-5.6-lunaand sendsadditional_toolsfor it, and doesn't knowteam-default, so for that name it falls back totoolswith namespacesCodex CLI 0.166.0 has one stdio MCP server exposing
search_issues. It points at a small recorder on port 4012 that saves each request body and forwards it unchanged to the proxy on 4011Every case runs
codex exec -m <model> "Call the search_issues tool with query 'login bug' and print exactly what it returned."with a key whosemetadata.allowed_toolsis listed in the case. "Ten flat tools" meansexec_command,write_stdin,list_mcp_resources,list_mcp_resource_templates,read_mcp_resource,request_user_input,view_image,get_goal,create_goal,update_goalWhat Codex sent, from the recorder (descriptions and schemas left out)
Before (4c8b909)
team-default, key allows the ten flat toolsmcp: mock/search_issues (completed)and{"result":"none"}, exit 0gpt-5.6-luna, key allowsexec_commandonlymcp: mock/search_issues (completed)andnone, exit 0After (c00cf1823c)
team-default, key allows the ten flat toolsgpt-5.6-luna, key allowsexec_commandonlyteam-default, key also allows the fivemulti_agent_v1tools andsearch_issuesmcp: mock/search_issues (completed)and{"result":"none"}, exit 0gpt-5.6-luna, key allowsexec,wait,request_user_inputmcp: mock/search_issues (completed)and the tool result, exit 0Rerun after the rebase
Codex 0.167.0, same
team-defaultrequest shape (the model is a stub that answersok, since the allowlist decides before the upstream is called). The MCP servermockexposingsearch_issuesisrequired, so it is loaded before the first request. Keys: A allows the ten flat tools, B also allows the fivemulti_agent_v1tools, C also allowssearch_issuessearch_issuesTool(s) ['close_agent', 'resume_agent', 'send_input', 'spawn_agent', 'wait_agent', 'search_issues'] are not in the allowed tools list for this key/team.search_issuesTool(s) ['search_issues'] are not in the allowed tools list for this key/team.Red and green for the new tests
tests/unit/proxy/test_tools_allowlist_enforcement.py, run withlitellm/at main (07c7229) and then at the tip (315ca3d)test_openai_responses_namespace_toolstest_openai_responses_tool_search_output_in_inputtest_openai_responses_namespace_inside_additional_toolstest_disallowed_namespace_member_raises_on_responses_route[namespace_in_tools]test_disallowed_namespace_member_raises_on_responses_route[tool_search_output_in_input]The whole file passes at the tip (39 tests)
Type
🐛 Bug Fix
Caveats (if any)
Severe
allowed_toolson/v1/responsesmulti_agent_v1tools plus MCP tool names, orexec,wait,request_user_inputongpt-5.6-lunaMedium
gpt-5.6-luna(additional_tools) cases were not rerungpt-5.6-luna, Codex calls MCP tools from insideexecexec, not the MCP tool name, so it can't limit those callsLow
search_issues), notmcp__mocktool_search_output; unit tests cover that shapemcp__mockwas in the request once (shown above)multi_agent_v1toolsFinal Attestation
🤖 Generated with Claude Code
https://claude.ai/code/session_01Pd88xuMVHt4chTrc8ZzAzv
Note
High Risk
Changes authorization for keys/teams with
allowed_toolson/v1/responsesby enforcing nested and deferred tool names that were previously skipped.Overview
/v1/responsestool allowlisting now sees tools that were previously invisible when clients (e.g. Codex) send them insidenamespacegroupings ortool_search_outputinput items instead of flattools[]entries.New shared helpers
with_namespace_membersandinput_tool_search_toolsin the Responses transformation layer flatten those shapes.OpenAIResponsesHandler.extract_request_tool_namesuses them so proxyallowed_toolschecks and ToolPolicyGuardrail enumerate every member tool name, not just top-level tools.Behavior change: restricted keys/teams that could call nested MCP or deferred tools before may now receive 403 unless those names are on the allowlist. Unit tests cover namespace-in-tools, tool search replay in
input[], and namespace insideadditional_tools.Reviewed by Cursor Bugbot for commit 315ca3d. Bugbot is set up for automated code reviews on this repo. Configure here.