The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(security): gate the read verbs that can mutate; keep php and lua as executors
M3gA-Mind0d33a978a8ba
diff --git a/crates/openhuman-core/src/security/policy/command_vocabulary.rs b/crates/openhuman-core/src/security/policy/command_vocabulary.rsindex 12b16e0649..b36e093294 100644--- a/crates/openhuman-core/src/security/policy/command_vocabulary.rs+++ b/crates/openhuman-core/src/security/policy/command_vocabulary.rs@@ -287,6 +287,8 @@ pub(super) fn is_command_executor(base: &str) -> bool {| "mawk"| "nawk"| "perl"+ | "php"+ | "lua"| "ruby"| "bash"| "sh"@@ -312,10 +314,25 @@ pub(super) fn is_command_executor(base: &str) -> bool {)}-/// The program name a shell runs for `word`: quotes removed (the shell joins-/// `c''url` into `curl`), basename only, lowercase, `.exe` stripped.+/// `word` as the shell passes it on: syntactic quotes removed (`c''url` is+/// `curl`), a quote character inside the other kind of quotes kept+/// (`"l's"` is `l's`).+pub(super) fn shell_unquote(word: &str) -> String {+ let (mut out, mut quote) = (String::with_capacity(word.len()), None);+ for c in word.chars() {+ match (quote, c) {+ (None, '\'' | '"') => quote = Some(c),+ (Some(open), _) if c == open => quote = None,+ _ => out.push(c),+ }+ }+ out+}++/// The program name a shell runs for `word`: quotes removed, basename only,+/// lowercase, `.exe` stripped.pub(super) fn normalized_command_name(word: &str) -> String {- let unquoted = word.replace(['\'', '"'], "");+ let unquoted = shell_unquote(word);let base = unquoted.rsplit(['/', '\\']).next().unwrap_or_default();let base = base.to_ascii_lowercase();base.strip_suffix(".exe").unwrap_or(&base).to_owned()@@ -395,7 +412,7 @@ pub(super) fn classify_segment_source(source: &str) -> CommandClass {let (base, args) = effective_command(&words);let args = args.iter()- .map(|word| word.replace(['\'', '"'], "").to_ascii_lowercase())+ .map(|word| shell_unquote(word).to_ascii_lowercase()).collect::<Vec<_>>();let joined = source.replace(['\'', '"'], "").to_ascii_lowercase();let class = classify_host_command(&base, &args, &joined);@@ -481,11 +498,42 @@ pub(super) fn classify_host_command(base: &str, args: &[String], joined: &str) -};}if base == "git" {+ // `git remote add|remove|set-url|update …` and `git reflog+ // expire|delete` change the repository; their inspecting forms read.+ let sub = args.get(1).map(String::as_str);+ let mutates = match args.first().map(String::as_str) {+ Some("remote") => {+ sub.is_some_and(|s| !matches!(s, "-v" | "--verbose" | "show" | "get-url"))+ }+ Some("reflog") => matches!(sub, Some("expire" | "delete")),+ _ => false,+ };+ if mutates {+ return CommandClass::Write;+ }return verb_class(args, GIT_READ_VERBS);}if matches!(base, "npm" | "pnpm" | "yarn") {+ // `npm audit fix` installs remediations.+ if args.first().is_some_and(|a| a == "audit") && args.iter().any(|a| a == "fix") {+ return CommandClass::Write;+ }return verb_class(args, NODE_PKG_READ_VERBS);}+ // Read-only bases with a flag that runs a command or writes a file.+ let writes_via_flag = match base {+ "rg" => args.iter().any(|a| a == "--pre" || a.starts_with("--pre=")),+ "tree" => args.iter().any(|a| a == "-o"),+ // `hostname NAME`, `hostname -F FILE` and `--file=FILE` set the host+ // name; every display form is flags only.+ "hostname" => args+ .iter()+ .any(|a| !a.starts_with('-') || a.starts_with("--file")),+ _ => false,+ };+ if writes_via_flag {+ return CommandClass::Write;+ }if base == "cargo" {return verb_class(args, CARGO_READ_VERBS);}diff --git a/crates/openhuman-core/src/security/policy/policy_classifier_parity_tests.rs b/crates/openhuman-core/src/security/policy/policy_classifier_parity_tests.rsindex e9872f5b1b..a31b401331 100644--- a/crates/openhuman-core/src/security/policy/policy_classifier_parity_tests.rs+++ b/crates/openhuman-core/src/security/policy/policy_classifier_parity_tests.rs@@ -1,20 +1,20 @@-//! Production and test classifiers must agree. Production gates a shell-//! command through TinyBox's segment facts and-//! `CommandAnalysis::from_shell_analysis`; most unit tests call the test-only-//! `check_gated_command`. When the two drift, a test passes while production-//! classifies differently. This corpus runs through both paths and checks each-//! against the expected class (`None` = refused for a protected path).-#![allow(deprecated)]-use super::*;use crate::security::policy::CommandAnalysis;use tinybox_core::shell::scan;use crate::security::policy::CommandClass::{Destructive, Install, Network, Read, Write};+// Production and test classifiers must agree. Production gates a shell+// command through TinyBox's segment facts and+// `CommandAnalysis::from_shell_analysis`; most unit tests call the test-only+// `check_gated_command`. When the two drift, a test passes while production+// classifies differently. This corpus runs through both paths and checks each+// against the expected class (`None` = refused for a protected path).+/// The production path: the facts TinyBox's `analyze_shell` returns, through/// the host analysis and gate. The policy is disabled so the result is the/// classification itself (plus the protected-path floor, which still applies).+#[allow(deprecated)] // TinyBox's scan helpers, the same calls `analyze_shell` makesfn production(policy: &SecurityPolicy, command: &str) -> Option<CommandClass> {let facts = tinybox_bus::ShellAnalysis {segments: scan::split_unquoted_segments(&scan::strip_quoted_heredoc_bodies(command)),@@ -129,6 +129,23 @@ const CORPUS: &[(&str, Option<CommandClass>)] = &[("'curl' x", Some(Network)),("\"cu\"rl x", Some(Network)),("su''do ls", Some(Destructive)),+ // Read-only bases and verbs whose other forms run code or change state.+ ("rg --pre ./x pat", Some(Write)),+ ("rg pat src", Some(Read)),+ ("tree -o out.txt", Some(Write)),+ ("hostname", Some(Read)),+ ("hostname -f", Some(Read)),+ ("hostname new-name", Some(Write)),+ ("git remote -v", Some(Read)),+ ("git remote add origin u", Some(Write)),+ ("git remote set-url origin u", Some(Write)),+ ("git reflog", Some(Read)),+ ("git reflog expire --all", Some(Write)),+ ("npm audit", Some(Read)),+ ("npm audit fix", Some(Write)),+ // A quote inside the other kind of quotes is part of the name.+ ("./\"l's\"", Some(Write)),+ ("'l\"s'", Some(Write)),// Protected paths inside option values.("cat /etc/shadow", None),("tool --input=/etc/shadow", None),