Verify signed remote plugin archives before extraction (#63489)

## Why

Remote plugin downloads need to check that the archive matches the digest
and signature supplied by the release before using its contents.

## What changed

Use the shared archive verifier for remote installs, installed-plugin
updates, shared plugin checkouts, and measurement reference downloads.
Fetch signing keys through the authenticated plugin service transport.
Reject malformed signing metadata and failed verification before extraction,
and continue accepting releases that omit signing metadata.

## Testing

Extend runtime authentication coverage to check that signing-key requests
include the product SKU header and that a prepared request fails after its
network policy is revoked.

GitOrigin-RevId: 27322921cd2778a3f06d1dee124dd8a5037c2f00
This commit is contained in:
Alex Ionescu
2026-11-24 01:28:15 +00:00
committed by copyberry
parent 05d375287d
commit e173e7b9b2
13 changed files with 131 additions and 45 deletions
+1
View File
@@ -3261,6 +3261,7 @@ dependencies = [
"codex-model-provider",
"codex-otel",
"codex-plugin",
"codex-plugin-archive-verification",
"codex-protocol",
"codex-runtime-agent-instance",
"codex-shell-command",
+1
View File
@@ -292,6 +292,7 @@ codex-ollama = { path = "ollama" }
codex-otel = { path = "otel" }
codex-otel-trace-websocket = { path = "otel-trace-websocket" }
codex-plugin = { path = "plugin" }
codex-plugin-archive-verification = { path = "plugin-archive-verification" }
codex-model-provider = { path = "model-provider" }
codex-process-hardening = { path = "process-hardening" }
codex-protocol = { path = "protocol" }
@@ -2550,6 +2550,9 @@ fn remote_plugin_bundle_install_error_type(err: &RemotePluginBundleInstallError)
RemotePluginBundleInstallError::UnsupportedBundleDownloadFinalUrl { .. } => {
"remote_bundle_unsupported_download_final_url"
}
RemotePluginBundleInstallError::ArchiveVerification { .. } => {
"remote_bundle_archive_verification"
}
RemotePluginBundleInstallError::ExtractedBundleTooLarge { .. } => {
"remote_bundle_extracted_too_large"
}
+1
View File
@@ -32,6 +32,7 @@ codex-mcp = { workspace = true }
codex-model-provider = { workspace = true }
codex-otel = { workspace = true }
codex-plugin = { workspace = true }
codex-plugin-archive-verification = { workspace = true }
codex-protocol = { workspace = true }
codex-runtime-agent-instance = { workspace = true }
codex-shell-command = { workspace = true }
@@ -56,7 +56,7 @@ pub(crate) async fn fetch_measurement_reference_bundle(
REMOTE_GLOBAL_MARKETPLACE_NAME,
&plugin.name,
plugin.release.version.as_deref(),
plugin.release.bundle_download_url.as_deref(),
&plugin.release.archive_download,
plugin.release.app_manifest,
)?;
Ok(Some((plugin.id, bundle)))
@@ -196,6 +196,7 @@ impl RemotePluginMeasurementCache {
return Ok(None);
};
if let Some(sender) = initializer {
let auth = auth.clone();
// The cache keeps the receiver alive when individual callers cancel.
// Once the cache and all callers disappear, stop waiting/downloading.
tokio::spawn(async move {
@@ -203,7 +204,7 @@ impl RemotePluginMeasurementCache {
biased;
_ = sender.closed() => return,
reference = async {
let bytes = download_remote_plugin_bundle(&service, &bundle).await?;
let bytes = download_remote_plugin_bundle(&service, Some(&auth), &bundle).await?;
// Blocking extraction cannot be aborted once started. Its
// owner must keep the store alive even if this task stops.
tokio::task::spawn_blocking(move || {
+48 -16
View File
@@ -33,8 +33,11 @@ use codex_plugin::PluginCapabilitySummary;
use codex_plugin::PluginId;
use codex_plugin::app_connector_ids_from_declarations;
use codex_plugin::prompt_safe_plugin_description;
use codex_plugin_archive_verification::ArchiveVerificationFailure;
use codex_plugin_archive_verification::RemotePluginArchiveDownload;
use codex_runtime_agent_instance::RuntimeAuthSlot;
use codex_utils_absolute_path::AbsolutePathBuf;
use futures::future::BoxFuture;
use http::HeaderMap;
use http::Method;
use http::StatusCode;
@@ -225,19 +228,25 @@ impl RemotePluginServiceConfig {
config
}
pub(crate) async fn authenticated_request(
&self,
method: Method,
url: &str,
auth: &CodexAuth,
) -> Result<RequestBuilder, codex_api::AuthError> {
let (request, headers) = self
.prepare_authenticated_request(method, url, auth)
.await?;
Ok(request.headers(headers))
}
// Keep runtime registration out of callers' async stack frames.
pub(crate) fn authenticated_request<'a>(
fn prepare_authenticated_request<'a>(
&'a self,
method: Method,
url: &'a str,
auth: &'a CodexAuth,
) -> std::pin::Pin<
Box<
dyn std::future::Future<Output = Result<RequestBuilder, codex_api::AuthError>>
+ Send
+ 'a,
>,
> {
) -> BoxFuture<'a, Result<(RequestBuilder, HeaderMap), codex_api::AuthError>> {
Box::pin(async move {
if self.runtime_auth.is_some() {
codex_model_provider::validate_runtime_destination(Some(&self.chatgpt_base_url))
@@ -279,7 +288,7 @@ impl RemotePluginServiceConfig {
None => self.http_clients.request(method, url),
};
let headers = resolved.auth.apply_auth_headers(HeaderMap::new()).await?;
Ok(request.headers(default_headers()).headers(headers))
Ok((request.headers(default_headers()), headers))
})
}
@@ -427,7 +436,7 @@ pub struct RemotePluginDetail {
pub share_url: Option<String>,
pub description: Option<String>,
pub release_version: Option<String>,
pub bundle_download_url: Option<String>,
pub archive_download: RemotePluginArchiveDownload,
pub app_manifest: Option<JsonValue>,
pub skills: Vec<RemotePluginSkill>,
pub onboarding_skill_name: Option<String>,
@@ -757,8 +766,8 @@ struct RemotePluginReleaseResponse {
version: Option<String>,
display_name: String,
description: String,
#[serde(default)]
bundle_download_url: Option<String>,
#[serde(flatten)]
archive_download: RemotePluginArchiveDownload,
#[serde(default)]
app_ids: Vec<String>,
#[serde(default)]
@@ -1632,7 +1641,7 @@ async fn build_remote_plugin_detail(
share_url: plugin.share_url,
description: non_empty_string(Some(&plugin.release.description)),
release_version: plugin.release.version,
bundle_download_url: plugin.release.bundle_download_url,
archive_download: plugin.release.archive_download,
app_manifest: plugin.release.app_manifest,
skills,
onboarding_skill_name: plugin.release.onboarding_skill_name,
@@ -2485,13 +2494,36 @@ async fn authenticated_request(
url: &str,
auth: &CodexAuth,
) -> Result<RequestBuilder, RemotePluginCatalogError> {
Ok(config
let request = config
.authenticated_request(method, url, auth)
.await
.map_err(std::io::Error::other)
.map_err(RemotePluginCatalogError::AuthToken)?
.map_err(RemotePluginCatalogError::AuthToken)?;
Ok(with_catalog_request_options(config, request))
}
/// Pair the selected transport with the exact credentials used to scope the signing-key cache.
pub(crate) async fn prepare_signing_key_request(
config: &RemotePluginServiceConfig,
url: String,
auth: Option<&CodexAuth>,
) -> Result<(RequestBuilder, HeaderMap), ArchiveVerificationFailure> {
let auth = ensure_chatgpt_auth(auth)
.map_err(|_| ArchiveVerificationFailure::AuthenticationRequired)?;
let (request, headers) = config
.prepare_authenticated_request(Method::GET, &url, auth)
.await
.map_err(|_| ArchiveVerificationFailure::AuthenticationRequired)?;
Ok((with_catalog_request_options(config, request), headers))
}
fn with_catalog_request_options(
config: &RemotePluginServiceConfig,
request: RequestBuilder,
) -> RequestBuilder {
request
.timeout(REMOTE_PLUGIN_CATALOG_TIMEOUT)
.header(OAI_PRODUCT_SKU_HEADER, &config.product_sku))
.header(OAI_PRODUCT_SKU_HEADER, &config.product_sku)
}
async fn send_and_decode<T: for<'de> Deserialize<'de>>(
@@ -267,7 +267,7 @@ pub(crate) async fn sync_remote_installed_plugin_bundles_once_with_snapshot(
&marketplace_name,
&plugin.name,
release_version,
plugin.release.bundle_download_url.as_deref(),
&plugin.release.archive_download,
plugin.release.app_manifest.clone(),
) {
Ok(bundle) => bundle,
@@ -292,6 +292,7 @@ pub(crate) async fn sync_remote_installed_plugin_bundles_once_with_snapshot(
capabilities.include_active_bundle(&store, &plugin_id).await;
match crate::remote_bundle::download_and_install_remote_plugin_bundle(
config,
Some(auth),
codex_home.clone(),
bundle,
)
@@ -85,7 +85,7 @@ pub async fn checkout_remote_plugin_share(
&detail.marketplace_name,
&plugin_name,
detail.release_version.as_deref(),
detail.bundle_download_url.as_deref(),
&detail.archive_download,
/*app_manifest*/ None,
)
.map_err(|err| {
@@ -95,6 +95,7 @@ pub async fn checkout_remote_plugin_share(
})?;
crate::remote_bundle::download_and_extract_remote_plugin_bundle_to_path(
config,
auth,
bundle,
local_plugin_path.clone(),
)
+54 -13
View File
@@ -3,6 +3,7 @@ use crate::plugin_bundle_archive::PluginBundleUnpackError;
use crate::plugin_bundle_archive::unpack_plugin_bundle_tar_gz;
use crate::remote::REMOTE_GLOBAL_MARKETPLACE_NAME;
use crate::remote::RemotePluginServiceConfig;
use crate::remote::prepare_signing_key_request;
use crate::store::PluginInstallResult;
use crate::store::PluginStore;
use crate::store::PluginStoreError;
@@ -10,6 +11,7 @@ use crate::store::error_context_sub_error_type;
use crate::store::validate_plugin_version_segment;
use codex_http_client::HttpResponse;
use codex_http_client::RouteAwareRequestError;
use codex_login::CodexAuth;
use codex_plugin::PluginId;
use codex_plugin::PluginIdError;
use codex_utils_absolute_path::AbsolutePathBuf;
@@ -28,6 +30,9 @@ use std::time::Duration;
use url::Host;
use url::Url;
use codex_plugin_archive_verification::ArchiveVerificationFailure;
use codex_plugin_archive_verification::RemotePluginArchiveDownload;
const REMOTE_PLUGIN_BUNDLE_DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(60);
const REMOTE_PLUGIN_BUNDLE_MAX_DOWNLOAD_BYTES: u64 = 100 * 1024 * 1024;
const REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES: u64 = 8 * 1024;
@@ -44,6 +49,7 @@ pub struct ValidatedRemotePluginBundle {
remote_plugin_id: String,
app_manifest: Option<JsonValue>,
bundle_download_url: String,
archive_download: RemotePluginArchiveDownload,
}
impl std::fmt::Debug for ValidatedRemotePluginBundle {
@@ -128,6 +134,16 @@ pub enum RemotePluginBundleInstallError {
)]
UnsupportedBundleDownloadFinalUrl { host: String, scheme: String },
#[error(
"plugin `{plugin_id}` version `{plugin_version}` failed archive verification: {source}"
)]
ArchiveVerification {
plugin_id: String,
plugin_version: String,
#[source]
source: ArchiveVerificationFailure,
},
#[error(
"remote plugin bundle extracted size would be {bytes} bytes, exceeding the maximum total size of {max_bytes} bytes"
)]
@@ -154,6 +170,7 @@ impl RemotePluginBundleInstallError {
pub fn sub_error_type(&self) -> Option<String> {
match self {
Self::ArchiveVerification { source, .. } => Some(source.as_str().to_owned()),
Self::Io { context, .. } => Some(error_context_sub_error_type(context)),
Self::Store(err) => err.sub_error_type(),
Self::DownloadStatus { status, .. } => {
@@ -180,7 +197,7 @@ pub fn validate_remote_plugin_bundle(
remote_marketplace_name: &str,
plugin_name: &str,
release_version: Option<&str>,
bundle_download_url: Option<&str>,
archive_download: &RemotePluginArchiveDownload,
app_manifest: Option<JsonValue>,
) -> Result<ValidatedRemotePluginBundle, RemotePluginBundleInstallError> {
let plugin_id = PluginId::new(plugin_name.to_string(), remote_marketplace_name.to_string())
@@ -201,7 +218,9 @@ pub fn validate_remote_plugin_bundle(
message,
}
})?;
let bundle_download_url = bundle_download_url
let bundle_download_url = archive_download
.bundle_download_url
.as_deref()
.map(str::trim)
.filter(|url| !url.is_empty())
.ok_or_else(
@@ -234,6 +253,7 @@ pub fn validate_remote_plugin_bundle(
remote_plugin_id: remote_plugin_id.to_string(),
app_manifest,
bundle_download_url,
archive_download: archive_download.clone(),
})
}
@@ -267,10 +287,11 @@ fn is_loopback_url(url: &Url) -> bool {
pub async fn download_and_install_remote_plugin_bundle(
config: &RemotePluginServiceConfig,
auth: Option<&CodexAuth>,
codex_home: PathBuf,
bundle: ValidatedRemotePluginBundle,
) -> Result<PluginInstallResult, RemotePluginBundleInstallError> {
let bundle_bytes = download_remote_plugin_bundle(config, &bundle).await?;
let bundle_bytes = download_remote_plugin_bundle(config, auth, &bundle).await?;
tokio::task::spawn_blocking(move || {
install_remote_plugin_bundle(codex_home, bundle, bundle_bytes)
})
@@ -284,10 +305,11 @@ pub async fn download_and_install_remote_plugin_bundle(
pub(crate) async fn download_and_extract_remote_plugin_bundle_to_path(
config: &RemotePluginServiceConfig,
auth: Option<&CodexAuth>,
bundle: ValidatedRemotePluginBundle,
destination: AbsolutePathBuf,
) -> Result<AbsolutePathBuf, RemotePluginBundleInstallError> {
let bundle_bytes = download_remote_plugin_bundle(config, &bundle).await?;
let bundle_bytes = download_remote_plugin_bundle(config, auth, &bundle).await?;
tokio::task::spawn_blocking(move || {
extract_remote_plugin_bundle_to_path(bundle, bundle_bytes, destination)
})
@@ -301,14 +323,29 @@ pub(crate) async fn download_and_extract_remote_plugin_bundle_to_path(
pub(crate) async fn download_remote_plugin_bundle(
config: &RemotePluginServiceConfig,
auth: Option<&CodexAuth>,
bundle: &ValidatedRemotePluginBundle,
) -> Result<Vec<u8>, RemotePluginBundleInstallError> {
download_remote_plugin_bundle_with_limit(
let bytes = download_remote_plugin_bundle_with_limit(
config,
&bundle.bundle_download_url,
/*max_bytes*/ REMOTE_PLUGIN_BUNDLE_MAX_DOWNLOAD_BYTES,
)
.await
.await?;
bundle
.archive_download
.verify(bytes, &config.chatgpt_base_url, |url| {
prepare_signing_key_request(config, url, auth)
})
.await
.map(|(bytes, _)| bytes)
.map_err(
|source| RemotePluginBundleInstallError::ArchiveVerification {
plugin_id: bundle.plugin_id.as_key(),
plugin_version: bundle.plugin_version.clone(),
source,
},
)
}
async fn download_remote_plugin_bundle_with_limit(
@@ -696,7 +733,7 @@ mod tests {
"openai-curated-remote",
"linear",
Some("1.2.3"),
Some("https://example.com/linear.tar.gz?sig=signed-token"),
&archive_download("https://example.com/linear.tar.gz?sig=signed-token"),
/*app_manifest*/ None,
)
.expect("valid install plan");
@@ -718,7 +755,7 @@ mod tests {
"openai-curated-remote",
"linear",
/*release_version*/ None,
Some("https://example.com/linear.tar.gz"),
&archive_download("https://example.com/linear.tar.gz"),
/*app_manifest*/ None,
)
.expect_err("missing release version should be rejected");
@@ -736,7 +773,7 @@ mod tests {
"openai-curated-remote",
"linear",
Some("../1.2.3"),
Some("https://example.com/linear.tar.gz"),
&archive_download("https://example.com/linear.tar.gz"),
/*app_manifest*/ None,
)
.expect_err("invalid release version should be rejected");
@@ -754,7 +791,7 @@ mod tests {
"openai-curated-remote",
"linear",
Some("1.2.3"),
/*bundle_download_url*/ None,
&RemotePluginArchiveDownload::default(),
/*app_manifest*/ None,
)
.expect_err("missing bundle download URL should be rejected");
@@ -772,7 +809,7 @@ mod tests {
"openai-curated-remote",
"linear",
Some("1.2.3"),
Some("http://example.com/linear.tar.gz"),
&archive_download("http://example.com/linear.tar.gz"),
/*app_manifest*/ None,
)
.expect_err("plain HTTP URLs should be rejected before cloud install");
@@ -903,7 +940,7 @@ mod tests {
"workspace-shared-with-me",
"linear",
Some("backend-version"),
Some("https://example.com/linear.tar.gz"),
&archive_download("https://example.com/linear.tar.gz"),
Some(serde_json::json!({
"apps": {
"remote": {
@@ -1078,13 +1115,17 @@ mod tests {
assert_eq!(mode, 0o755);
}
fn archive_download(url: &str) -> RemotePluginArchiveDownload {
RemotePluginArchiveDownload::new(Some(url.to_owned()))
}
fn valid_remote_plugin_bundle() -> ValidatedRemotePluginBundle {
validate_remote_plugin_bundle(
REMOTE_PLUGIN_ID,
"openai-curated-remote",
"linear",
Some("1.2.3"),
Some("https://example.com/linear.tar.gz"),
&archive_download("https://example.com/linear.tar.gz"),
/*app_manifest*/ None,
)
.expect("valid install plan")
@@ -143,7 +143,7 @@ impl PluginsManager {
&detail.marketplace_name,
&detail.summary.name,
detail.release_version.as_deref(),
detail.bundle_download_url.as_deref(),
&detail.archive_download,
detail.app_manifest.clone(),
)
.map_err(|err| resolved(Error::Bundle(err)))?;
@@ -164,6 +164,7 @@ impl PluginsManager {
// Materialize first: a failed download must never leave a backend installation behind.
let installed = remote_bundle::download_and_install_remote_plugin_bundle(
&service,
auth,
self.codex_home.clone(),
bundle,
)
@@ -22,6 +22,7 @@ use uuid::Uuid;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::header;
use wiremock::matchers::path;
#[tokio::test]
@@ -53,7 +54,13 @@ async fn plugin_runtime_auth_shares_registration_and_strips_cross_origin_auth()
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"plugins": [], "pagination": {"next_page_token": null},
})))
.expect(2)
.expect(1)
.mount(&server)
.await;
Mock::given(path("/backend-api/ps/plugins/signing-keys"))
.and(header(OAI_PRODUCT_SKU_HEADER, CODEX_PRODUCT_SKU))
.respond_with(ResponseTemplate::new(200))
.expect(1)
.mount(&server)
.await;
Mock::given(path("/backend-api/plugins/featured"))
@@ -175,24 +182,20 @@ async fn plugin_runtime_auth_shares_registration_and_strips_cross_origin_auth()
.contains_key("x-openai-agent-assertion")
);
destination.verify().await;
let url = format!("{}/backend-api/ps/plugins/list", server.uri());
let pending = config
.authenticated_request(Method::GET, &url, &auth)
let url = format!("{}/backend-api/ps/plugins/signing-keys", server.uri());
let (pending, headers) = prepare_signing_key_request(&config, url.clone(), Some(&auth))
.await
.unwrap();
policy.invalidate();
assert!(controller.publish(policy.revision(), DestinationPolicy::Unrestricted));
assert!(matches!(
pending.send().await,
pending.headers(headers).send().await,
Err(RouteAwareRequestError::Policy(NetworkPolicyDenied::Revoked))
));
let response = config
.authenticated_request(Method::GET, &url, &auth)
.await
.unwrap()
.send()
let (request, headers) = prepare_signing_key_request(&config, url, Some(&auth))
.await
.unwrap();
let response = request.headers(headers).send().await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let requests = server.received_requests().await.unwrap();
let mut proof_ids = HashSet::new();
+1 -1
View File
@@ -808,7 +808,7 @@ fn directory_plugin(id: &str, name: &str) -> RemotePluginDirectoryItem {
version: None,
display_name: name.to_string(),
description: String::new(),
bundle_download_url: None,
archive_download: RemotePluginArchiveDownload::default(),
app_ids: Vec::new(),
app_manifest: None,
app_templates: Vec::new(),