Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Security
- More destructive commands (e.g. `shred`, `wipefs`, `find -delete`, `zfs destroy`, SQL `DROP TABLE`) are now rated red and ask for confirmation, and more credential files (Terraform state, KeePass, Azure and gcloud credentials) count as secret paths.
46 changes: 46 additions & 0 deletions crates/app-logic/src/orchestration/action_exec/tests_red_risk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,49 @@ fn test_red_risk_reason_escalates_even_without_a_pattern_reason() {
Some("Server-Risiko rot: rot eingestuft")
);
}

// --- Issue #1725: new destructive families / secret paths ---------------

async fn decision_code_for(command: &str) -> (Decision, serde_json::Value) {
let session = red_risk_session(MockSshTransport::default().with_response(command, output("")));
tokio::time::timeout(
std::time::Duration::from_secs(5),
proposed_decision_code(
&session,
AiAction::SuggestCommand {
command: command.to_string(),
},
),
)
.await
.expect("Dialog muss enden")
}

/// Issue #1725: a newly red destructive command still asks despite an
/// allow-everything rule.
#[tokio::test]
async fn test_new_destructive_family_requires_confirmation_despite_allow_rule() {
let command = "wipefs -a /dev/sdb";
let (decision, payload) = decision_code_for(command).await;
assert!(
matches!(&decision, Decision::Confirm { code, .. }
if code == "FILTER_RED_RISK_REQUIRES_CONFIRM"),
"{payload}"
);
assert!(
confirm_reason(&payload).contains("wipefs"),
"{}",
confirm_reason(&payload)
);
}

/// Issue #1725: a newly added secret path asks despite an allow rule.
#[tokio::test]
async fn test_new_secret_path_requires_confirmation_despite_allow_rule() {
let (decision, payload) = decision_code_for("cat infra/terraform.tfstate").await;
assert!(
matches!(&decision, Decision::Confirm { code, .. }
if code == "FILTER_SECRET_PATH_READ_REQUIRES_CONFIRM"),
"{payload}"
);
}
12 changes: 12 additions & 0 deletions crates/core/src/filter/adversarial_tests/sudo_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ const OPAQUE_VALUES: [(&str, &str); 15] = [

/// Compares decision (under three policies) and risk of each pair.
pub(super) async fn mismatches(pairs: &[(&str, &str)]) -> Vec<String> {
risk_mismatches(pairs, filter_mismatches(pairs).await)
}

/// Like `mismatches`, but compares only the filter decisions, not the risk
/// rating (for pairs the risk classifier deliberately rates differently).
pub(super) async fn filter_mismatches(pairs: &[(&str, &str)]) -> Vec<String> {
let policies: [(&str, Vec<Rule>); 3] = [
("allow-all + deny-rm", vec![allow_all(), deny_rm()]),
("allow-all", vec![allow_all()]),
Expand All @@ -97,6 +103,12 @@ pub(super) async fn mismatches(pairs: &[(&str, &str)]) -> Vec<String> {
));
}
}
}
mismatches
}

fn risk_mismatches(pairs: &[(&str, &str)], mut mismatches: Vec<String>) -> Vec<String> {
for &(with_option, without_option) in pairs {
let expected = RuleBasedRiskClassifier.classify(without_option);
let actual = RuleBasedRiskClassifier.classify(with_option);
let expected = (expected.server_risk, expected.data_risk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! see the command they run as they see the bare command, and where it
//! cannot be read for sure the call needs at least `Confirm`.

use super::sudo_options::mismatches;
use super::sudo_options::{filter_mismatches, mismatches};
use super::*;
use crate::risk::RuleBasedRiskClassifier;

Expand Down Expand Up @@ -258,10 +258,11 @@ async fn test_adv_nested_execution_wrappers_hit_deny_rule() {
}
}

/// `find -delete` removes what it finds, like `rm -r`.
/// `find -delete` removes what it finds, like `rm -r`. Only the filter
/// decisions are compared: the risk classifier rates `find -delete` red (#1725).
#[tokio::test]
async fn test_adv_find_delete_is_checked_like_rm() {
let found = mismatches(&[
let found = filter_mismatches(&[
("find /srv -delete", "rm -r /srv"),
("find -name '*.log' -delete", "rm -r ."),
("find / -xdev -delete", "rm -r /"),
Expand Down
5 changes: 5 additions & 0 deletions crates/core/src/risk/classifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::patterns::{
SFTP_SERVER_INVOCATION, SSH_KEY_GLOB_CANDIDATES,
};
use super::sftp_word_check::{quoted_sftp_server_invocation, sftp_server_word_check, WordCheck};
use super::sql_statement::{destructive_sql, SQL_DESTRUCTIVE_REASON};
use super::types::{RiskAssessment, RiskLevel};

/// Regelbasierter Klassifikator (Spec 0026, Abschnitt 2) —
Expand Down Expand Up @@ -247,6 +248,10 @@ fn rate_segments(
acc.data_risk_reason = Some(reason);
}
}
if acc.server_risk < RiskLevel::Red && destructive_sql(&lower) {
acc.server_risk = RiskLevel::Red;
acc.server_risk_reason = Some(SQL_DESTRUCTIVE_REASON);
}
if acc.data_risk < RiskLevel::Red && glob_reads_private_key(&lower) {
acc.data_risk = RiskLevel::Red;
acc.data_risk_reason =
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/risk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
mod classifier;
mod patterns;
mod sftp_word_check;
mod sql_statement;
mod types;
mod wrapper_state;

Expand All @@ -34,6 +35,8 @@ mod property_tests;
#[cfg(test)]
mod tests_chaining;
#[cfg(test)]
mod tests_destructive_families;
#[cfg(test)]
mod tests_sftp_server_args;
#[cfg(test)]
mod tests_ssh_key_names;
Expand Down
Loading
Loading