only use inner powershell command for rule matching

This commit is contained in:
iceweasel-oai
2026-04-29 21:17:35 -07:00
parent 0c30ead917
commit c23edf2838
2 changed files with 43 additions and 2 deletions
+12 -2
View File
@@ -801,7 +801,10 @@ fn try_derive_execpolicy_amendment_for_prompt_rules(
fn try_derive_execpolicy_amendment_for_allow_rules(
matched_rules: &[RuleMatch],
) -> Option<ExecPolicyAmendment> {
if matched_rules.iter().any(is_policy_match) {
if matched_rules
.iter()
.any(|rule_match| is_policy_match(rule_match) && rule_match.decision() != Decision::Allow)
{
return None;
}
@@ -843,7 +846,14 @@ fn derive_requested_execpolicy_amendment_from_prefix_rule(
}
// if any policy rule already matches, don't suggest an additional rule that might conflict or not apply
if matched_rules.iter().any(is_policy_match) {
// PowerShell evaluation can combine outer wrapper matches with unmatched
// inner commands. Existing explicit allow rules should not suppress a
// requested inner-command prefix rule that would resolve the remaining
// prompt, but explicit prompt/forbidden matches still should.
if matched_rules
.iter()
.any(|rule_match| is_policy_match(rule_match) && rule_match.decision() != Decision::Allow)
{
return None;
}
+31
View File
@@ -866,6 +866,37 @@ async fn powershell_outer_allow_does_not_override_unmatched_wrapper_prompt() {
.await;
}
#[cfg(windows)]
#[tokio::test]
async fn powershell_outer_allow_still_allows_inner_prefix_rule_suggestion() {
assert_exec_approval_requirement_for_command(
ExecApprovalRequirementScenario {
policy_src: Some(
r#"prefix_rule(pattern=["powershell.exe"], decision="allow")"#.to_string(),
),
command: vec_str(&[
"powershell.exe",
"-WindowStyle",
"Hidden",
"-Command",
"Get-Content Cargo.toml",
]),
approval_policy: AskForApproval::OnRequest,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
file_system_sandbox_policy: read_only_file_system_sandbox_policy(),
sandbox_permissions: SandboxPermissions::UseDefault,
prefix_rule: Some(vec_str(&["Get-Content"])),
},
ExecApprovalRequirement::NeedsApproval {
reason: None,
proposed_execpolicy_amendment: Some(ExecPolicyAmendment::new(vec_str(&[
"Get-Content",
]))),
},
)
.await;
}
#[test]
fn commands_for_exec_policy_falls_back_for_empty_shell_script() {
let command = vec!["bash".to_string(), "-lc".to_string(), "".to_string()];