Skip to content

Commit d3dea9c

Browse files
committed
fix(cortex-cli): integrate allows_risk() for proper autonomy level validation
Address Greptile review feedback by actually calling the allows_risk() method in the exec command approval flow. Previously, the security fix only added the method but did not integrate it into the command execution path. Changes: - Replace simple AutonomyLevel::ReadOnly check with allows_risk(risk, command) - Extract risk_level from sandbox_assessment if available - Pass actual command string to validate read-only commands properly - Provide clearer error messages including risk level and autonomy mode
1 parent 239e0af commit d3dea9c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/cortex-cli/src/exec_cmd/runner.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,29 @@ impl ExecCli {
466466
}
467467
}
468468
EventMsg::ExecApprovalRequest(approval) => {
469-
// Check autonomy level
470-
if let Some(level) = autonomy
471-
&& level == AutonomyLevel::ReadOnly
472-
{
473-
// Fail fast in read-only mode
474-
error_occurred = true;
475-
error_message = Some(
476-
"Permission denied: Command execution not allowed in read-only mode. \
477-
Use --auto low|medium|high to enable."
478-
.to_string(),
479-
);
480-
break;
469+
// Check autonomy level using allows_risk for proper validation
470+
if let Some(level) = autonomy {
471+
let command_str = approval.command.join(" ");
472+
let risk_level = approval
473+
.sandbox_assessment
474+
.as_ref()
475+
.map(|a| match a.risk_level {
476+
cortex_protocol::SandboxRiskLevel::Low => "low",
477+
cortex_protocol::SandboxRiskLevel::Medium => "medium",
478+
cortex_protocol::SandboxRiskLevel::High => "high",
479+
})
480+
.unwrap_or("low");
481+
482+
if !level.allows_risk(risk_level, &command_str) {
483+
// Command not allowed at this autonomy level
484+
error_occurred = true;
485+
error_message = Some(format!(
486+
"Permission denied: Command '{}' (risk: {}) not allowed in {} mode. \
487+
Use --auto with higher autonomy level to enable.",
488+
command_str, risk_level, level
489+
));
490+
break;
491+
}
481492
}
482493

483494
// Auto-approve based on autonomy level (already set via approval_policy)

0 commit comments

Comments
 (0)