mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Harden plugin manifest handling during installation (#39590)
## Why Plugin installation skips symlinks while copying a plugin into the cache. A symlinked manifest could therefore be used during source validation but omitted from the staged copy, allowing a lower-precedence manifest to take its place. ## What changed - Require discoverable manifests and their parent directories to be regular files and directories, rejecting symlinks and other non-regular entries at a higher-precedence manifest path. - Verify that staging preserves the selected manifest path and contents before activating the cached plugin. - Preserve generated fallback manifests by injecting and validating them in the staged plugin. ## Testing Add coverage for symlinked manifest files and directories, precedence changes, and fallback-manifest staging. GitOrigin-RevId: 1b69c1e75cdfecb8cab4070a32aa9739833a70de
This commit is contained in:
@@ -632,6 +632,27 @@ fn replace_plugin_root_atomically(
|
||||
})?;
|
||||
let staged_root = staged_dir.path().join(plugin_dir_name);
|
||||
let staged_version_root = staged_root.join(plugin_version);
|
||||
let (source_manifest_relative_path, source_manifest_contents) = match manifest {
|
||||
InstallManifest::OnDisk => {
|
||||
let manifest_path = find_plugin_manifest_path(source)
|
||||
.ok_or_else(|| PluginStoreError::Invalid("missing plugin.json".to_string()))?;
|
||||
let relative_path = manifest_path
|
||||
.strip_prefix(source)
|
||||
.map_err(|_| {
|
||||
PluginStoreError::Invalid(
|
||||
"plugin manifest is outside the plugin source".to_string(),
|
||||
)
|
||||
})?
|
||||
.to_path_buf();
|
||||
let contents = fs::read(&manifest_path)
|
||||
.map_err(|err| PluginStoreError::io("failed to read plugin.json", err))?;
|
||||
(relative_path, contents)
|
||||
}
|
||||
InstallManifest::Fallback(contents) => (
|
||||
PathBuf::from(".codex-plugin/plugin.json"),
|
||||
contents.as_bytes().to_vec(),
|
||||
),
|
||||
};
|
||||
copy_dir_recursive(source, &staged_version_root)?;
|
||||
if let InstallManifest::Fallback(contents) = manifest {
|
||||
// Inject the generated manifest into Store's existing atomic copy so install does not
|
||||
@@ -648,6 +669,24 @@ fn replace_plugin_root_atomically(
|
||||
fs::write(&manifest_path, contents)
|
||||
.map_err(|err| PluginStoreError::io("failed to write fallback plugin manifest", err))?;
|
||||
}
|
||||
let staged_manifest_path =
|
||||
find_plugin_manifest_path(&staged_version_root).ok_or_else(|| {
|
||||
PluginStoreError::Invalid(
|
||||
"plugin manifest is missing after installation staging".to_string(),
|
||||
)
|
||||
})?;
|
||||
if staged_manifest_path != staged_version_root.join(&source_manifest_relative_path) {
|
||||
return Err(PluginStoreError::Invalid(
|
||||
"plugin manifest changed during installation staging".to_string(),
|
||||
));
|
||||
}
|
||||
let staged_manifest_contents = fs::read(&staged_manifest_path)
|
||||
.map_err(|err| PluginStoreError::io("failed to read staged plugin.json", err))?;
|
||||
if staged_manifest_contents != source_manifest_contents {
|
||||
return Err(PluginStoreError::Invalid(
|
||||
"plugin manifest contents changed during installation staging".to_string(),
|
||||
));
|
||||
}
|
||||
let is_agent_plugin = fs::read_to_string(staged_version_root.join("plugin.json"))
|
||||
.ok()
|
||||
.is_some_and(|contents| {
|
||||
|
||||
Reference in New Issue
Block a user