Block provider network escapes in restricted runtimes - #2299
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
ApprovabilityVerdict: Needs human review 2 blocking correctness issues found. This PR introduces a new security/policy enforcement layer that mediates provider-side capabilities based on network restrictions. The substantial new mediation logic across multiple dialects, combined with unresolved design questions and two High-severity correctness findings, warrants careful human review. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
important PR to get in. I would prefer if we can return a stable structured error to let the different harnesses optionally recover (we should def not put the onus of crafting a response to let the model know why the request was rejected on the proxy)
otherwise, lgtm!
mikasenghaas
left a comment
There was a problem hiding this comment.
hmm i really dont like us being in charge of network restrictions on any external resource (any inference deployment, api, mcp server, etc. etc.). in my opinion this is a battle we really cannot win. plus it adds a huge amount of line noise and unmaintainable ai slop into our codebase. i would much rather maintain a list of known ways to "escape" the sandbox and tune our interception machinery to reliably detect these things
5a4996d to
2c6096c
Compare
fb8e447 to
4cef434
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4cef434. Configure here.
mikasenghaas
left a comment
There was a problem hiding this comment.
can we run some example traces for each external tool with no block and block where we explicitly ask the model to do use the blocked tool and then check that we a) block the tool and b) so its clear what our mediation strategy acc is
also we choose to only care abt external tools through infernece. we deliberately dont try to block e.g. mcp (this is user respnosibility). should we hav a small note on this in the docs?

Summary
Security model
Any restricted runtime policy disables provider-side fetches and hosted capabilities. Provider DNS and redirects happen outside the sandbox firewall, so a runtime allowlist cannot safely authorize a provider-side URL.
Mediation removes protocol-defined external capability fields before the upstream call. The model sees only structural field paths in the policy notice; URLs, file IDs, MCP authorization, and other request values are never copied into the notice. The sanitized effective request is also what Verifiers parses and records.
Harness behavior
Recoverable policy violations no longer return an HTTP error to the harness. The provider receives a safe request containing the policy notice, and the harness receives the model’s ordinary response, so all harnesses can continue without dialect-specific error handling. Only a capability intrinsic to the configured model remains a hard error.
Testing
The previous live V1 CI failure was an unrelated transient 429 during rubric scoring; 58 other live tests passed.
Note
High Risk
Changes the security-critical interception path and request shaping for all dialects; custom Client subclasses must update signatures, and mediation bugs could leak provider fetches or break harnesses under restricted policies.
Overview
Restricted rollouts now strip provider-side network escapes before upstream calls: hosted tools, MCP, remote file/image URLs, web search, and similar fields are removed in Chat, Responses, and Anthropic dialects, with a value-free user notice so the harness still gets a normal model turn.
PolicyEventrecords affected request paths on eachModelCall.The interception server applies
apply_overridesthenmediate_external_capabilitieswhenRolloutSession.network_policyis restricted; clients receive the final body only (modeldropped fromget_response/relay).NetworkPolicyConfigandnetwork_rule_matcheslive inconfigs/runtime; task allowlists intersect with runtime rules instead of widening by union.Smaller fixes: ACP
replayed_transcriptfor resume vs live turns, Responses terminal failure / streaming context-length handling, Harbor docs on provider capabilities vs runtime egress, and a richer ACP resume fixture.Reviewed by Cursor Bugbot for commit 938a5e9. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Block provider network escapes in restricted runtimes by mediating AI provider requests against rollout network policy
NetworkPolicyConfig.permitsto test egress URLs against allow/block rules, and propagates the resolved policy throughRolloutSessioninto the interception pipeline.mediate_external_capabilitieson all three dialects (anthropic.py, chat.py, responses.py): removes disallowed tools, content references (images, files, hosted IDs), and provider-side features (web search, MCP servers, audio voices), then injects a policy notice into the earliest user message when removals occur.InterceptionErrorbefore the request is sent.PolicyEventtoModelCalltraces so mediation decisions and affected request paths are recorded alongside each call.Client.get_response/relaysignatures:modelis removed as a separate parameter andsampling_argsis renamed tosampling; callers must supply a fully mediated body. Risk: any customClientsubclass must update its method signatures.Changes since #2299 opened
_HOSTED_TOOL_TYPESfrozenset with_HOSTED_TOOL_TYPEcompiled regex pattern matchingfile_search|mcp|code_interpreter|programmatic_tool_calling|image_generation|web_search_preview(?:_\d{4}_\d{2}_\d{2})?to support date-suffixed web_search_preview variants, updated_mediate_toolsfunction to use regex fullmatch for hosted tool detection with string type guard and special handling fortool_searchandshellkinds, and modifiedResponsesDialect.mediate_external_capabilitiesmethod to reject dicttool_choiceentries matching hosted-tool or web tool regex patterns and to validateshellortool_searchtool_choice only when matching tool types exist in the tools array [fde99e0]network_rule_matchesfunction to catchValueErrorwhen accessing parsed port and returnFalsefor rules with invalid port specifications [fde99e0]NetworkPolicyConfigclass andnetwork_rule_matchesfunction fromverifiers.v1.runtimes.basemodule toverifiers.v1.configs.runtimemodule [b0cb17b]NetworkPolicyConfig.with_task_network_policyto retain only exact shared allow rules and always combine blocklists [938a5e9]TaskDatamodel by inserting free-form descriptive text between field docstrings outside string literals [938a5e9]response_from_wireby raising typed exceptions for non-completed response statuses [938a5e9]Rollout.openthat failed rollouts based on intrinsic provider-side model capabilities under restricted policies [938a5e9]ChatDialect.apply_overridesmerge order to ensure selected model remains authoritative over sampling payload fields [938a5e9]Macroscope summarized 4cef434.