fix(security): expand default allowed_commands and auto_approve (#2486)
Summary
- Expands
default_allowed_commandsfrom 18 → 40 entries: adds build tools (pnpm,yarn,make,cmake), read-only inspection tools (sort,uniq,diff,which,uname,basename,dirname,tr,cut,realpath,readlink,stat,file), and workspace mutation tools (mkdir,touch,cp,mv,ln). - Expands
default_auto_approvefrom 5 → 9 tools: addsglob,grep(read-only search),file_write,edit_file(workspace-scoped writes). - Adds schema v3→v4 migration that merges new commands/tools into existing user configs (additive-only, preserves customizations). Also bumps
max_actions_per_hourfrom the old hard-coded20tou32::MAXfor users still on that default (code default was changed to unlimited in #2500 but persisted configs kept20).
No high-risk commands (python, node, bash, curl, sed, awk, xargs) were added. Filesystem mutation commands (mkdir, touch, cp, mv, ln) are classified as medium-risk and require approval in Supervised mode.
Test plan
- [x]
cargo test --lib openhuman::security::policy— 112 pass - [x]
cargo test --lib openhuman::migrations— 51 pass - [x]
cargo fmt --check— clean - [x] RPC-verified:
openhuman.security_policy_infoshowsallowed_cmds=40,max_actions/hr=4294967295 - [x] RPC-verified:
openhuman.config_getshows migration applied to real user config (commands_added=28 tools_added=4 max_actions_bumped=true) - [x] Confirmed high-risk commands (python, curl, bash) remain blocked
Closes #2486
Summary by CodeRabbit
-
New Features
- Expanded default security policy to allow more package/build tools, additional read/inspection utilities, and select filesystem mutation commands; auto-approve list extended with workspace-scoped search/read tools.
-
Configuration Updates
- On upgrade, existing workspaces are migrated to merge these expanded defaults and advance the schema while preserving user customizations.
-
Behavior Changes
- Default action rate limit raised from a small cap to effectively unlimited unless overridden.
-
Tests
- Added unit and integration tests for migrations, defaults, preservation, and idempotency.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Expands default allowed commands and auto-approve lists, raises default max_actions_per_hour to unlimited, adds a v3→v4 migration to merge new defaults and conditionally bump the action limit, adds a v4→v5 migration to remove write tools from auto-approve, updates migration runner to CURRENT_SCHEMA_VERSION = 5, and adds tests.
Changes
Autonomy defaults expansion and migration
| Layer / File(s) | Summary |
|---|---|
Expanded autonomy schema defaults src/openhuman/config/schema/autonomy.rs, src/openhuman/security/policy.rs, src/openhuman/security/policy_tests.rs |
Adds package/build tool basenames (pnpm, yarn, make, cmake), inspection utilities (sort,uniq,diff,which,uname,basename,dirname,tr,cut,realpath,readlink,stat,file), and selected filesystem mutations (mkdir,touch,cp,mv,ln) to default_allowed_commands; expands default_auto_approve with workspace-scoped tools (glob,grep,file_write,edit_file); updates tests to assert defaults and risk levels; changes policy default max_actions_per_hour from 20 to u32::MAX. |
Migration implementation: expand_autonomy_defaults (v3→v4) src/openhuman/migrations/expand_autonomy_defaults.rs |
New migration that additively merges fixed command and auto-approve lists into persisted configs when missing, conditionally bumps max_actions_per_hour from 20 → u32::MAX only if the persisted value equals the legacy sentinel, logs MigrationStats, and contains unit tests for insertion, preservation, deduplication, idempotency, and conditional bumping. |
Migration orchestration and schema upgrades src/openhuman/migrations/mod.rs |
Registers expand_autonomy_defaults and remove_write_auto_approve, bumps CURRENT_SCHEMA_VERSION to 5, and adds gated run_pending steps: v3→run expand → persist v4 (rollback on save failure), then v4→run remove → persist v5 (rollback on save failure). |
Migration tests and runner expectations src/openhuman/migrations/mod_tests.rs |
Adds simulate_v3_autonomy helper, updates run_pending tests to expect CURRENT_SCHEMA_VERSION persisted (5), strengthens idempotency assertions (file mtime unchanged), and adds integration tests verifying v3→current expansion (including max_actions bump), preservation of custom max_actions_per_hour, and v4→v5 auto_approve removals while preserving always_ask. |
Migration: remove_write_auto_approve (v4→v5) src/openhuman/migrations/remove_write_auto_approve.rs |
New migration that removes file_write and edit_file from persisted config.autonomy.auto_approve, returns removed-count stats, and includes unit tests validating removals and preservation of always_ask. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- tinyhumansai/openhuman#2399: Overlapping allowlist extension work touching
default_allowed_commandsandSecurityPolicyallowlists. - tinyhumansai/openhuman#2534: Related default allowlist update (adds
date) and adjustments to argument safety checks. - tinyhumansai/openhuman#2500: Changes affecting
max_actions_per_hourdefaults which interact with UI/RPC assumptions about default limits.
Suggested reviewers
- senamakel
- graycyrus
🐰 I hopped through defaults under moonlit code,
I added tools and commands along the road.
A two-step migration — bump then prune — done neat,
Tests guard the hop, so configs stay complete.
🥕✨ The rabbit’s migration dance is sweet.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and concisely summarizes the main change: expanding default allowed_commands and auto_approve security policy allowlists. |
| Linked Issues check | ✅ Passed | The PR comprehensively addresses all coding-related requirements from issue #2486: expands allowed_commands with 22 new entries (build tools, inspection tools, filesystem mutations), broadens auto_approve with new tools, bumps max_actions_per_hour to u32::MAX via migration, and implements additive-only migration logic that preserves user customizations. |
| Out of Scope Changes check | ✅ Passed | All changes are directly scoped to expanding autonomy defaults and implementing the required migration infrastructure; no unrelated modifications to other systems or features are present. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Comment @coderabbitai help to get the list of available commands and usage tips.
Solid migration work and good test coverage overall. One security-design decision needs explicit maintainer sign-off before merge; a couple of smaller items to address.
Security concern —
file_writeandedit_fileinauto_approve
ApprovalManager::needs_approval()(src/openhuman/approval/ops.rs:92) is the gating function:// ReadOnly blocks everything — handled elsewhere; no prompt needed. if self.autonomy_level == AutonomyLevel::ReadOnly { return false; } // auto_approve skips the prompt. if self.auto_approve.contains(tool_name) { return false; } // Default: supervised mode requires approval. trueAdding
file_writeandedit_filetoauto_approvemeans Supervised mode no longer prompts for file writes. ReadOnly mode is unaffected (writes are blocked at the tool layer, not the approval gate — the comment on line 82 confirms this). But Supervised mode's documented contract is "ask before edit" — that contract is broken for these two tools.The PR description explicitly argues this is acceptable ("workspace boundary already constrains the blast radius"), but that's a design decision that changes user-visible behaviour for everyone in Supervised mode. It deserves explicit maintainer sign-off in the PR, not just a comment in the diff.
Suggested resolution: either (a) keep
file_write/edit_fileoffauto_approvefor now and file a separate PR documenting the change to Supervised mode semantics, or (b) add a note to the PR body confirming the intentional Supervised-mode behaviour change and have a maintainer explicitly approve it.
makeinallowed_commands
makeis a command runner, not just a build tool — amaketarget can shell out to anything. On the allowed list it isn't classified asInstall, so a compromised or malicious Makefile can run arbitrary commands (including network calls) without triggering the always-ask Install gate. This is qualitatively different frompnpm/yarn/cmake, which install packages or configure build graphs.Not a blocker, but worth a doc comment next to the
makeentry explaining the deliberate trade-off (e.g. "common development workflow; targets must be approved in Supervised mode as medium-risk writes").Minor —
cp/mv/lnclassification confirmed correct
policy.rs:536already has"touch" | "mkdir" | "mv" | "cp" | "ln" => truefor medium-risk. Thecommand_risk_leveltest inpolicy_tests.rspins that. ✓Minor —
NEW_COMMANDScomment inaccuracy/// These were added to the code default in PR #2500 but are absent from any /// `config.toml` written before that change. const NEW_COMMANDS: &[&str] = &[ ..., "date", "dir", "type", "where", "findstr", "more", ];
date,dir,type,where,findstr,moreappear without+in theautonomy.rsdiff, meaning they were present before this PR. If they pre-date PR #2500 too, the comment is inaccurate. Functionally harmless (the additive guard prevents duplicates), but the comment will mislead future readers. Worth a quickgit log -S '"date".into()'to verify — if they were there before PR #2500, update the comment to name the correct PR or say "may already be present in older configs; merge is a no-op if so."What's correct
- Migration is additive-only (contains-check before every push) and fully idempotent. ✓
- Save-failure rollback (
config.schema_version = previous_version; return;) prevents a half-applied migration from persisting a bumped version. ✓max_actions_per_hourbump is gated on exact equality withOLD_DEFAULT_MAX_ACTIONS_PER_HOUR = 20, so any deliberate customisation is preserved. ✓no_op_on_fresh_install_defaultscorrectly fires!stats.max_actions_bumpedbecauseConfig::default()now initialisesmax_actions_per_hour = u32::MAX, not 20. ✓- Migration integration tests (
run_pending_expands_autonomy_defaults_from_v3,run_pending_v3_to_v4_preserves_custom_max_actions) confirm the end-to-end path includingconfig.save(). ✓supervised_still_enforces_command_allowlistupdated to reflectmkdirnow being allow-listed. ✓- CI green, no merge conflicts.
Resolve the
file_write/edit_fileauto-approve question and this is ready.
Resolved the issue : https://github.com/tinyhumansai/openhuman/pull/2673/commits/9922974df07a4e8f1146b8abb95c92f1bfad7e56