mirror of
https://github.com/openai/codex.git
synced 2026-11-23 07:17:11 +00:00
Enforce Agent Plugin runtime boundaries (#37027)
## What changed - Track Agent Plugin manifests through plugin, skill, and MCP loading so their capabilities use format-specific behavior without changing legacy plugins. - Discover only direct-child skills, exclude app and hook capabilities, isolate MCP data, and reject MCP configuration files that are non-regular or resolve outside the plugin root. - Bound model-visible skill instructions, plugin instructions, MCP descriptions, schemas, individual tools, and the aggregate Agent Plugin MCP tool set. - Stop MCP and OAuth redirects when Agent Plugins send configured or authorization headers, while retaining existing redirect behavior for legacy MCP servers. ## Testing - Add coverage for capability filtering, skill discovery, isolated MCP data and reserved-path expansion, unsafe MCP configuration files, context limits, and redirect handling. GitOrigin-RevId: c9af66b051269f3226628ca280a58d32c808c38f
This commit is contained in:
1 parent
f21dc46388
commit
56b82e676c
63 files changed
+1830
-106
No files matched your search
@@ -8,6 +8,7 @@ use codex_exec_server::HttpHeader;
|
||||
use codex_exec_server::HttpRedirectPolicy;
|
||||
use codex_exec_server::HttpRequestParams;
|
||||
use http::HeaderMap;
|
||||
use http::header::AUTHORIZATION;
|
||||
use oauth2::HttpRequest;
|
||||
use oauth2::HttpResponse;
|
||||
use rmcp::transport::auth::OAuthHttpClient;
|
||||
@@ -17,6 +18,7 @@ use rmcp::transport::auth::OAuthHttpRedirectPolicy;
|
||||
use rmcp::transport::auth::OAuthHttpRequest;
|
||||
|
||||
use crate::auth_status::OAuthDiscoveryTimeout;
|
||||
use crate::http_client_adapter::StreamableHttpRedirectMode;
|
||||
|
||||
const MAX_OAUTH_HTTP_RESPONSE_BODY_BYTES: usize = 1024 * 1024;
|
||||
static NEXT_OAUTH_REQUEST_ID: AtomicU64 = AtomicU64::new(0);
|
||||
@@ -40,26 +42,50 @@ pub(crate) struct OAuthHttpClientAdapter {
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
default_headers: HeaderMap,
|
||||
timeout: OAuthDiscoveryTimeout,
|
||||
has_configured_headers: bool,
|
||||
redirect_mode: StreamableHttpRedirectMode,
|
||||
}
|
||||
|
||||
impl OAuthHttpClientAdapter {
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new(http_client: Arc<dyn HttpClient>, default_headers: HeaderMap) -> Self {
|
||||
Self {
|
||||
http_client,
|
||||
default_headers,
|
||||
timeout: OAuthDiscoveryTimeout::Requested,
|
||||
has_configured_headers: false,
|
||||
redirect_mode: StreamableHttpRedirectMode::Legacy,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_max_timeout(
|
||||
pub(crate) fn new_with_redirect_mode(
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
default_headers: HeaderMap,
|
||||
has_configured_headers: bool,
|
||||
redirect_mode: StreamableHttpRedirectMode,
|
||||
) -> Self {
|
||||
Self {
|
||||
http_client,
|
||||
default_headers,
|
||||
timeout: OAuthDiscoveryTimeout::Requested,
|
||||
has_configured_headers,
|
||||
redirect_mode,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_max_timeout_and_redirect_mode(
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
default_headers: HeaderMap,
|
||||
max_timeout: Duration,
|
||||
has_configured_headers: bool,
|
||||
redirect_mode: StreamableHttpRedirectMode,
|
||||
) -> Self {
|
||||
Self {
|
||||
http_client,
|
||||
default_headers,
|
||||
timeout: OAuthDiscoveryTimeout::Capped(max_timeout),
|
||||
has_configured_headers,
|
||||
redirect_mode,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +110,12 @@ impl OAuthHttpClientAdapter {
|
||||
headers.remove(name);
|
||||
}
|
||||
headers.extend(parts.headers);
|
||||
let redirect_policy = oauth_redirect_policy(
|
||||
self.redirect_mode,
|
||||
&headers,
|
||||
self.has_configured_headers,
|
||||
redirect_policy,
|
||||
);
|
||||
|
||||
let headers = headers
|
||||
.iter()
|
||||
@@ -139,8 +171,84 @@ impl OAuthHttpClientAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
fn oauth_redirect_policy(
|
||||
mode: StreamableHttpRedirectMode,
|
||||
headers: &HeaderMap,
|
||||
has_configured_headers: bool,
|
||||
requested_policy: HttpRedirectPolicy,
|
||||
) -> HttpRedirectPolicy {
|
||||
if mode == StreamableHttpRedirectMode::AgentPluginV1
|
||||
&& (has_configured_headers || headers.contains_key(AUTHORIZATION))
|
||||
{
|
||||
HttpRedirectPolicy::Stop
|
||||
} else {
|
||||
requested_policy
|
||||
}
|
||||
}
|
||||
|
||||
impl OAuthHttpClient for OAuthHttpClientAdapter {
|
||||
fn execute(&self, request: OAuthHttpRequest) -> OAuthHttpClientFuture<'_> {
|
||||
Box::pin(self.execute_request(request.request, request.redirect_policy, request.timeout))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use http::HeaderValue;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn agent_plugin_oauth_stops_only_for_sensitive_headers() {
|
||||
assert_eq!(
|
||||
policy(
|
||||
StreamableHttpRedirectMode::AgentPluginV1,
|
||||
/*has_configured_headers*/ true,
|
||||
/*has_authorization*/ false,
|
||||
),
|
||||
HttpRedirectPolicy::Stop
|
||||
);
|
||||
assert_eq!(
|
||||
policy(
|
||||
StreamableHttpRedirectMode::AgentPluginV1,
|
||||
/*has_configured_headers*/ false,
|
||||
/*has_authorization*/ true,
|
||||
),
|
||||
HttpRedirectPolicy::Stop
|
||||
);
|
||||
assert_eq!(
|
||||
policy(
|
||||
StreamableHttpRedirectMode::AgentPluginV1,
|
||||
/*has_configured_headers*/ false,
|
||||
/*has_authorization*/ false,
|
||||
),
|
||||
HttpRedirectPolicy::Follow
|
||||
);
|
||||
assert_eq!(
|
||||
policy(
|
||||
StreamableHttpRedirectMode::Legacy,
|
||||
/*has_configured_headers*/ true,
|
||||
/*has_authorization*/ true,
|
||||
),
|
||||
HttpRedirectPolicy::Follow
|
||||
);
|
||||
}
|
||||
|
||||
fn policy(
|
||||
mode: StreamableHttpRedirectMode,
|
||||
has_configured_headers: bool,
|
||||
has_authorization: bool,
|
||||
) -> HttpRedirectPolicy {
|
||||
let mut headers = HeaderMap::new();
|
||||
if has_authorization {
|
||||
headers.insert(AUTHORIZATION, HeaderValue::from_static("Bearer secret"));
|
||||
}
|
||||
oauth_redirect_policy(
|
||||
mode,
|
||||
&headers,
|
||||
has_configured_headers,
|
||||
HttpRedirectPolicy::Follow,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user