Skip to content

Commit fcc95a8

Browse files
committed
Move remote plugin id validation to remote module
1 parent 2bf3f10 commit fcc95a8

2 files changed

Lines changed: 28 additions & 32 deletions

File tree

codex-rs/app-server/src/codex_message_processor/plugins.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use super::*;
22
use crate::error_code::internal_error;
33
use crate::error_code::invalid_request;
44
use codex_app_server_protocol::PluginInstallPolicy;
5+
use codex_core_plugins::remote::is_valid_remote_plugin_id;
6+
use codex_core_plugins::remote::validate_remote_plugin_id;
57

68
impl CodexMessageProcessor {
79
pub(super) async fn plugin_list(
@@ -452,11 +454,7 @@ impl CodexMessageProcessor {
452454
"remote plugin install is not enabled for marketplace {remote_marketplace_name}"
453455
)));
454456
}
455-
if plugin_name.is_empty() || !is_valid_remote_plugin_id(&plugin_name) {
456-
return Err(invalid_request(
457-
"invalid remote plugin id: only ASCII letters, digits, `_`, `-`, and `~` are allowed",
458-
));
459-
}
457+
validate_remote_plugin_id(&plugin_name)?;
460458

461459
let auth = self.auth_manager.auth().await;
462460
let remote_plugin_service_config = RemotePluginServiceConfig {
@@ -715,11 +713,7 @@ impl CodexMessageProcessor {
715713
{
716714
return Err(invalid_request("remote plugin uninstall is not enabled"));
717715
}
718-
if plugin_id.is_empty() || !is_valid_remote_plugin_id(&plugin_id) {
719-
return Err(invalid_request(
720-
"invalid remote plugin id: only ASCII letters, digits, `_`, `-`, and `~` are allowed",
721-
));
722-
}
716+
validate_remote_plugin_id(&plugin_id)?;
723717

724718
let auth = self.auth_manager.auth().await;
725719
let remote_plugin_service_config = RemotePluginServiceConfig {
@@ -755,15 +749,8 @@ impl CodexMessageProcessor {
755749
}
756750
}
757751

758-
fn is_valid_remote_plugin_id(plugin_name: &str) -> bool {
759-
plugin_name
760-
.chars()
761-
.all(|ch| ch.is_ascii_alphanumeric() || ch == '-' || ch == '_' || ch == '~')
762-
}
763-
764752
fn is_valid_remote_uninstall_plugin_id(plugin_name: &str) -> bool {
765-
!plugin_name.is_empty()
766-
&& is_valid_remote_plugin_id(plugin_name)
753+
is_valid_remote_plugin_id(plugin_name)
767754
&& (plugin_name.starts_with("plugins~")
768755
|| plugin_name.starts_with("app_")
769756
|| plugin_name.starts_with("asdk_app_")
@@ -866,20 +853,6 @@ fn remote_plugin_catalog_error_to_jsonrpc(
866853
}
867854
}
868855

869-
fn validate_remote_plugin_id(plugin_id: &str) -> Result<(), JSONRPCErrorError> {
870-
if plugin_id.is_empty()
871-
|| !plugin_id
872-
.chars()
873-
.all(|ch| ch.is_ascii_alphanumeric() || ch == '-' || ch == '_' || ch == '~')
874-
{
875-
return Err(invalid_request(
876-
"invalid remote plugin id: only ASCII letters, digits, `_`, `-`, and `~` are allowed",
877-
));
878-
}
879-
880-
Ok(())
881-
}
882-
883856
fn remote_plugin_bundle_install_error_to_jsonrpc(
884857
err: codex_core_plugins::remote_bundle::RemotePluginBundleInstallError,
885858
) -> JSONRPCErrorError {

codex-rs/core-plugins/src/remote.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::store::PLUGINS_CACHE_DIR;
22
use crate::store::PluginStore;
3+
use codex_app_server_protocol::JSONRPCErrorError;
34
use codex_app_server_protocol::PluginAuthPolicy;
45
use codex_app_server_protocol::PluginInstallPolicy;
56
use codex_app_server_protocol::PluginInterface;
@@ -25,6 +26,7 @@ pub const REMOTE_WORKSPACE_MARKETPLACE_DISPLAY_NAME: &str = "ChatGPT Workspace P
2526
const REMOTE_PLUGIN_CATALOG_TIMEOUT: Duration = Duration::from_secs(30);
2627
const REMOTE_PLUGIN_LIST_PAGE_LIMIT: u32 = 200;
2728
const MAX_REMOTE_DEFAULT_PROMPT_LEN: usize = 128;
29+
const INVALID_REQUEST_ERROR_CODE: i64 = -32600;
2830

2931
#[derive(Debug, Clone, PartialEq, Eq)]
3032
pub struct RemotePluginServiceConfig {
@@ -83,6 +85,27 @@ pub struct RemotePluginSkillDetail {
8385
pub contents: Option<String>,
8486
}
8587

88+
pub fn is_valid_remote_plugin_id(plugin_id: &str) -> bool {
89+
!plugin_id.is_empty()
90+
&& plugin_id
91+
.chars()
92+
.all(|ch| ch.is_ascii_alphanumeric() || ch == '-' || ch == '_' || ch == '~')
93+
}
94+
95+
pub fn validate_remote_plugin_id(plugin_id: &str) -> Result<(), JSONRPCErrorError> {
96+
if !is_valid_remote_plugin_id(plugin_id) {
97+
return Err(JSONRPCErrorError {
98+
code: INVALID_REQUEST_ERROR_CODE,
99+
message:
100+
"invalid remote plugin id: only ASCII letters, digits, `_`, `-`, and `~` are allowed"
101+
.to_string(),
102+
data: None,
103+
});
104+
}
105+
106+
Ok(())
107+
}
108+
86109
#[derive(Debug, thiserror::Error)]
87110
pub enum RemotePluginCatalogError {
88111
#[error("chatgpt authentication required for remote plugin catalog")]

0 commit comments

Comments
 (0)