feat: add managed hooks lockdown

This commit is contained in:
viyatb-oai
2026-04-07 14:48:50 -07:00
parent fa5270abef
commit b04edb1685
18 changed files with 260 additions and 4 deletions
+26
View File
@@ -28,6 +28,11 @@ pub(crate) fn discover_handlers(config_layer_stack: Option<&ConfigLayerStack>) -
let mut handlers = Vec::new();
let mut warnings = Vec::new();
let mut display_order = 0_i64;
let allow_managed_hooks_only = config_layer_stack
.requirements()
.allow_managed_hooks_only
.as_ref()
.is_some_and(|requirement| requirement.value);
for layer in config_layer_stack.get_layers(
ConfigLayerStackOrdering::LowestPrecedenceFirst,
@@ -40,6 +45,13 @@ pub(crate) fn discover_handlers(config_layer_stack: Option<&ConfigLayerStack>) -
if !source_path.as_path().is_file() {
continue;
}
if allow_managed_hooks_only && !layer.is_managed() {
warnings.push(format!(
"skipping hooks config {} because `allow_managed_hooks_only` is enabled",
source_path.display()
));
continue;
}
let contents = match fs::read_to_string(source_path.as_path()) {
Ok(contents) => contents,
@@ -102,6 +114,20 @@ pub(crate) fn discover_handlers(config_layer_stack: Option<&ConfigLayerStack>) -
}
}
if !handlers.is_empty() {
let mut source_paths = handlers
.iter()
.map(|handler| handler.source_path.display().to_string())
.collect::<Vec<_>>();
source_paths.sort();
source_paths.dedup();
warnings.push(format!(
"Loaded {} lifecycle hook(s) from {}. Hooks run arbitrary shell commands outside the sandbox; review hooks.json changes before continuing.",
handlers.len(),
source_paths.join(", ")
));
}
DiscoveryResult { handlers, warnings }
}
+1 -1
View File
@@ -49,7 +49,7 @@ pub struct SessionStartOutcome {
pub additional_contexts: Vec<String>,
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, Default, PartialEq, Eq)]
struct SessionStartHandlerData {
should_stop: bool,
stop_reason: Option<String>,
@@ -36,7 +36,7 @@ pub struct UserPromptSubmitOutcome {
pub additional_contexts: Vec<String>,
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, Default, PartialEq, Eq)]
struct UserPromptSubmitHandlerData {
should_stop: bool,
stop_reason: Option<String>,