Reject provider query parameters for connector result passthrough (#62421)

## Why

The Responses client checks the gateway URL and request headers before
allowing connector result bodies to be attached. Provider query parameters
can also change the request while leaving those checks satisfied.

## What changed

Require an empty provider query parameter map, or no map, when selecting
a connector result destination. Check the ChatGPT credential variants
directly and retain the current auth owner for thread grant verification.

## Testing

Extend the client setup test to check that a custom provider URL is
ineligible even with refreshed ChatGPT credentials. Extend the enterprise
MCP lifecycle test to check that the configured provider receives the
account bearer token and executed tool-call metadata. Allow HTTP client
tests to cache a direct system proxy decision as well as a proxied route.

GitOrigin-RevId: 1e7e77ec6e65263eaff658ba39943ec51230d332
This commit is contained in:
ssetty-oai
2026-11-19 03:58:01 +00:00
committed by copyberry
parent fc483d4b4d
commit 770c38d0b1
4 changed files with 71 additions and 29 deletions
+37 -23
View File
@@ -291,32 +291,44 @@ pub(crate) fn is_local_connector_result_gateway(base_url: &str) -> bool {
)
}
fn sampling_result_owner(
#[derive(Debug, PartialEq)]
struct ResultBodyDestination {
owner: AuthOwner,
}
fn sampling_result_destination(
setup: &CurrentClientSetup,
include_internal: bool,
responses_headers: &ApiHeaderMap,
) -> Option<AuthOwner> {
setup
) -> Option<ResultBodyDestination> {
if !include_internal
|| !responses_headers.is_empty()
|| setup
.api_provider
.query_params
.as_ref()
.is_some_and(|params| !params.is_empty())
{
return None;
}
let owner = setup
.auth_owner
.as_ref()
.filter(|owner| {
owner.is_current()
&& include_internal
&& responses_headers.is_empty()
&& matches!(
setup.auth.as_ref().map(CodexAuth::auth_mode),
Some(AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens)
)
&& is_local_connector_result_gateway(&setup.api_provider.base_url)
&& setup.api_provider.headers.keys().all(|name| {
matches!(
name.as_str(),
codex_model_provider::ACCOUNT_ROUTING_HEADER
| codex_model_provider_info::RESIDENCY_HEADER_NAME
) || ExecutedToolCalls::is_result_body_provider_header(name.as_str())
})
})
.cloned()
.filter(|owner| owner.is_current())?
.clone();
let headers = &setup.api_provider.headers;
(matches!(
setup.auth.as_ref(),
Some(CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_))
) && is_local_connector_result_gateway(&setup.api_provider.base_url)
&& headers.keys().all(|name| {
matches!(
name.as_str(),
codex_model_provider::ACCOUNT_ROUTING_HEADER
| codex_model_provider_info::RESIDENCY_HEADER_NAME
) || ExecutedToolCalls::is_result_body_provider_header(name.as_str())
}))
.then_some(ResultBodyDestination { owner })
}
#[derive(Clone, Copy)]
@@ -2123,11 +2135,13 @@ impl ResponsesHttpExecutor<'_> {
let responses_headers = self
.client
.responses_headers(client_setup.auth.as_ref(), &model_info.slug);
let result_body_owner = sampling_result_owner(
let result_body_owner = sampling_result_destination(
&client_setup,
include_internal && self.client.captures_result_bodies(),
&responses_headers,
);
)
// A candidate gateway must also have a verified thread grant before it can receive results.
.map(|destination| destination.owner);
tracing::Span::current().record("api.path", "/responses");
let transport = client_setup.http_transport("/responses")?;
let request_auth_context = AuthRequestTelemetryContext::new(
+10 -4
View File
@@ -12,7 +12,7 @@ use super::X_CODEX_PARENT_THREAD_ID_HEADER;
use super::X_CODEX_TURN_METADATA_HEADER;
use super::X_CODEX_WINDOW_ID_HEADER;
use super::X_OPENAI_SUBAGENT_HEADER;
use super::sampling_result_owner;
use super::sampling_result_destination;
use crate::AttestationContext;
use crate::AttestationProvider;
use crate::GenerateAttestationFuture;
@@ -431,7 +431,6 @@ async fn client_setup_rebuilds_chatgpt_refresh_but_rejects_account_switches() {
AuthManager::from_auth_for_testing_with_home(initial, home.path().to_path_buf());
let refreshed_token = token(user, "refreshed");
let mut info = test_model_provider().info().clone();
info.base_url = Some(CHATGPT_CODEX_BASE_URL.to_string());
info.requires_openai_auth = true;
let provider = Arc::new(SetupRefreshProvider {
inner: create_model_provider(info, Some(manager.clone())),
@@ -456,13 +455,20 @@ async fn client_setup_rebuilds_chatgpt_refresh_but_rejects_account_switches() {
&format!("Bearer {refreshed_token}")
);
let empty = http::HeaderMap::new();
// A configured provider using the same ChatGPT credentials cannot receive results.
assert_eq!(
sampling_result_destination(&setup, /*include_internal*/ true, &empty),
None
);
setup.api_provider.base_url = codex_model_provider_info::CHATGPT_CODEX_BASE_URL.into();
for (internal, response_headers, owner) in [
(true, &empty, setup.auth_owner.clone()),
(false, &empty, None),
(true, &headers, None),
] {
assert_eq!(
sampling_result_owner(&setup, internal, response_headers),
sampling_result_destination(&setup, internal, response_headers)
.map(|destination| destination.owner),
owner
);
}
@@ -471,7 +477,7 @@ async fn client_setup_rebuilds_chatgpt_refresh_but_rejects_account_switches() {
http::HeaderValue::from_static("another-organization"),
);
assert_eq!(
sampling_result_owner(&setup, /*include_internal*/ true, &empty),
sampling_result_destination(&setup, /*include_internal*/ true, &empty),
None,
);
assert_eq!(setup.auth.unwrap().get_token().unwrap(), refreshed_token);
@@ -316,6 +316,16 @@ http_headers = {{ Authorization = "Bearer ordinary-access" }}
))
.with_config(move |config| {
super::configure_scenario_catalog(config);
config.model_provider.requires_openai_auth = true;
config.model_provider.include_internal_metadata = true;
config
.features
.enable(codex_features::Feature::ConnectorToolResultPassthrough)
.expect("enable connector result capture");
config
.features
.enable(codex_features::Feature::ExecutedToolCallMetadata)
.expect("enable tool-call metadata");
if matches!(scenario, EnterpriseLifecycle::RefreshPermissions) {
config.permissions.approval_policy = codex_config::Constrained::allow_any(
codex_protocol::protocol::AskForApproval::Never,
@@ -698,6 +708,15 @@ http_headers = {{ Authorization = "Bearer ordinary-access" }}
.await?;
let requests = mock.requests();
assert_eq!(requests.len(), 4);
assert_eq!(
requests[1].header("authorization").as_deref(),
Some("Bearer account-access"),
);
let output = requests[1].function_call_output("enterprise-call");
assert_eq!(
output["internal_chat_message_metadata_passthrough"]["executed_tool_calls"],
json!([{"name": "mcp__enterprise__calendar_list_events", "arguments": {}}]),
);
let calls = mcp
.received_requests()
.await
+5 -2
View File
@@ -646,8 +646,11 @@ fn cache_system_proxy_decision(request_url: &str, decision: SystemProxyDecision)
///
/// This is public only so tests in HTTP-client consumers can exercise system-proxy routing
/// deterministically on every supported platform.
pub fn cache_system_proxy_route_for_test(request_url: &str, proxy_url: String) {
cache_system_proxy_decision(request_url, SystemProxyDecision::Proxy { url: proxy_url });
pub fn cache_system_proxy_route_for_test(request_url: &str, proxy_url: impl Into<Option<String>>) {
let decision = proxy_url.into().map_or(SystemProxyDecision::Direct, |url| {
SystemProxyDecision::Proxy { url }
});
cache_system_proxy_decision(request_url, decision);
}
fn insert_system_proxy_cache_entry(