Skip to content

fix(guardrails): check Responses tools in namespace and tool_search_output against allowed_tools - #49132

Open
Acacian wants to merge 1 commit into
BerriAI:mainfrom
Acacian:fix-responses-namespace-tool-allowlist
Open

Acacian wants to merge 1 commit into
BerriAI:mainfrom
Acacian:fix-responses-namespace-tool-allowlist

Conversation

@Acacian

@Acacian Acacian commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

A key or team with allowed_tools set could still use tools outside that list on /v1/responses when the request carried them inside a namespace tool or a tool_search_output input item. Codex sends its MCP and multi-agent tools inside namespace tools, 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_tools ignores tools inside a Responses namespace tool
  • That includes a namespace inside an additional_tools input item
  • It ignores tools a tool_search_output input item loads
  • Codex sends tools in the first shape, so the list never applied to them

How it solves it:

  • The allowlist opens each namespace into its member tools
  • It also reads tools from tool_search_output input items
  • It reuses the chat tool-search replay's parsers
  • Flat tools in additional_tools items are already read on main, so this PR leaves them alone
  • ToolPolicyGuardrail reads the same tool names, so it sees these tools too

Intentional 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_tools extraction this PR first carried has since landed on main, so it was dropped here

User Flow

Before: a proxy admin limits a key's tools, but Codex on that key still calls an MCP tool outside the list

  1. The admin sends POST https://litellm-domain/key/generate with allowed_tools set to the ten flat tools Codex sends, without search_issues
  2. A developer runs Codex with that key, a proxy model name Codex doesn't know, and an MCP server exposing search_issues
  3. They ask Codex to call search_issues; Codex sends POST https://litellm-domain/v1/responses with search_issues inside a namespace tool
  4. The proxy answers 200, the model calls search_issues, and Codex prints its result

After: the same request is refused because it carries tools that are not on the key's list

  1. The admin sends POST https://litellm-domain/key/generate with allowed_tools set to the ten flat tools Codex sends, without search_issues
  2. A developer runs Codex with that key, a proxy model name Codex doesn't know, and an MCP server exposing search_issues
  3. They ask Codex to call search_issues; Codex sends POST https://litellm-domain/v1/responses with search_issues inside a namespace tool
  4. The proxy answers 403 Tool(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_permission guardrail. 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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-default cases were rerun at main (07c7229) and the tip (315ca3d) with Codex 0.167.0, see "Rerun after the rebase" at the end. The gpt-5.6-luna cases were not rerun: they now depend on the additional_tools extraction that main carries

Both 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-luna and sends additional_tools for it, and doesn't know team-default, so for that name it falls back to tools with namespaces

model_list:
  - model_name: gpt-5.6-luna
    litellm_params: {model: chatgpt/gpt-5.6-luna}
  - model_name: team-default
    litellm_params: {model: chatgpt/gpt-5.6-luna}
general_settings:
  master_key: sk-master

Codex 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 4011

model_provider = "litellm"

[model_providers.litellm]
name = "litellm"
base_url = "http://127.0.0.1:4012/v1"
env_key = "LITELLM_KEY"
wire_api = "responses"

[mcp_servers.mock]
command = "python"
args = ["mock_mcp.py"]

Every case runs codex exec -m <model> "Call the search_issues tool with query 'login bug' and print exactly what it returned." with a key whose metadata.allowed_tools is listed in the case. "Ten flat tools" means exec_command, write_stdin, list_mcp_resources, list_mcp_resource_templates, read_mcp_resource, request_user_input, view_image, get_goal, create_goal, update_goal

What Codex sent, from the recorder (descriptions and schemas left out)

team-default  tools: [ten flat tools, web_search,
                      {"type": "namespace", "name": "multi_agent_v1", "tools": [close_agent, resume_agent, send_input, spawn_agent, wait_agent]},
                      {"type": "namespace", "name": "mcp__mock", "tools": [search_issues]}]
              then:  {"type": "function_call", "name": "search_issues", "namespace": "mcp__mock", "arguments": "{\"query\":\"login bug\"}"}

gpt-5.6-luna  tools: []
              input: [{"type": "additional_tools", "tools": [{"type": "namespace", "name": "functions", "tools": [exec, wait, request_user_input]}]}, ...]
              then:  {"type": "custom_tool_call", "name": "exec", "input": "... await tools.mcp__mock__search_issues({query: \"login bug\"}) ..."}

Before (4c8b909)

team-default, key allows the ten flat tools

  1. Run the command above
  2. Codex prints mcp: mock/search_issues (completed) and {"result":"none"}, exit 0

gpt-5.6-luna, key allows exec_command only

  1. Run the command above
  2. Codex prints mcp: mock/search_issues (completed) and none, exit 0

After (c00cf1823c)

team-default, key allows the ten flat tools

  1. Run the command above
  2. Codex prints the error below and exits 1
ERROR: unexpected status 403 Forbidden: Tool(s) ['close_agent', 'resume_agent', 'send_input', 'spawn_agent', 'wait_agent', 'search_issues'] are not in the allowed tools list for this key/team., url: http://127.0.0.1:4012/v1/responses

gpt-5.6-luna, key allows exec_command only

  1. Run the command above
  2. Codex prints the error below and exits 1
ERROR: unexpected status 403 Forbidden: Tool(s) ['exec', 'wait', 'request_user_input'] are not in the allowed tools list for this key/team., url: http://127.0.0.1:4012/v1/responses

team-default, key also allows the five multi_agent_v1 tools and search_issues

  1. Run the command above
  2. Codex prints mcp: mock/search_issues (completed) and {"result":"none"}, exit 0

gpt-5.6-luna, key allows exec, wait, request_user_input

  1. Run the command above
  2. Codex prints mcp: mock/search_issues (completed) and the tool result, exit 0

Rerun after the rebase

Codex 0.167.0, same team-default request shape (the model is a stub that answers ok, since the allowlist decides before the upstream is called). The MCP server mock exposing search_issues is required, so it is loaded before the first request. Keys: A allows the ten flat tools, B also allows the five multi_agent_v1 tools, C also allows search_issues

Key main (07c7229) tip (315ca3d)
A 200, request carried search_issues 403 Tool(s) ['close_agent', 'resume_agent', 'send_input', 'spawn_agent', 'wait_agent', 'search_issues'] are not in the allowed tools list for this key/team.
B 200, request carried search_issues 403 Tool(s) ['search_issues'] are not in the allowed tools list for this key/team.
C 200 200

Red and green for the new tests

tests/unit/proxy/test_tools_allowlist_enforcement.py, run with litellm/ at main (07c7229) and then at the tip (315ca3d)

Test 07c7229 315ca3d
test_openai_responses_namespace_tools fail pass
test_openai_responses_tool_search_output_in_input fail pass
test_openai_responses_namespace_inside_additional_tools fail pass
test_disallowed_namespace_member_raises_on_responses_route[namespace_in_tools] fail pass
test_disallowed_namespace_member_raises_on_responses_route[tool_search_output_in_input] fail pass

The whole file passes at the tip (39 tests)

Type

🐛 Bug Fix

Caveats (if any)

Severe

  • Changes auth behavior for keys and teams with allowed_tools on /v1/responses
    • Names Codex sends inside these groups are now checked, so a list without them gets 403
    • Measured with Codex: the five multi_agent_v1 tools plus MCP tool names, or exec, wait, request_user_input on gpt-5.6-luna

Medium

  • The rerun after the rebase used a stub upstream, not a real model
    • The allowlist decides before the upstream is called, so the 200 or 403 is the same
    • The gpt-5.6-luna (additional_tools) cases were not rerun
  • On gpt-5.6-luna, Codex calls MCP tools from inside exec
    • The allowlist sees exec, not the MCP tool name, so it can't limit those calls
    • Not addressed here

Low

  • Namespace members are matched by their own name (search_issues), not mcp__mock
    • This is how the chat tool-search replay already names them, so one list works on both routes
  • No Codex run here sent tool_search_output; unit tests cover that shape
  • Codex 0.166.0 sometimes sent its first request before the MCP server loaded
    • The first After case ran 4 times; mcp__mock was in the request once (shown above)
    • The other 3 times the 403 listed only the five multi_agent_v1 tools
  • On a 403, Codex retried 5 times before exiting

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pd88xuMVHt4chTrc8ZzAzv


Note

High Risk
Changes authorization for keys/teams with allowed_tools on /v1/responses by enforcing nested and deferred tool names that were previously skipped.

Overview
/v1/responses tool allowlisting now sees tools that were previously invisible when clients (e.g. Codex) send them inside namespace groupings or tool_search_output input items instead of flat tools[] entries.

New shared helpers with_namespace_members and input_tool_search_tools in the Responses transformation layer flatten those shapes. OpenAIResponsesHandler.extract_request_tool_names uses them so proxy allowed_tools checks 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 inside additional_tools.

Reviewed by Cursor Bugbot for commit 315ca3d. Bugbot is set up for automated code reviews on this repo. Configure here.

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…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
Acacian force-pushed the fix-responses-namespace-tool-allowlist branch from c00cf18 to 315ca3d Compare November 8, 2026 01:12
@Acacian Acacian changed the title fix(guardrails): check Responses tools in namespace, additional_tools and tool_search_output against allowed_tools fix(guardrails): check Responses tools in namespace and tool_search_output against allowed_tools Nov 8, 2026
@mubashir1osmani

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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.

@devin-ai-integration

Copy link
Copy Markdown
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.

Case Before 07c7229 After 315ca3d
team-default restricted 200, search_issues ran 403
team-default allowed 200 200
gpt-5.6-luna restricted 200, search_issues ran 403
gpt-5.6-luna allowed 200 200
Codex CLI and Admin UI screenshots
Before After
before restricted after restricted
before control after control
before known model restricted after known model restricted
before accepted detail after 403 detail

Written by Devin

This branch has not been deployed

No deployments
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.

3 participants