feat: tighten runtime policy + transport guards v2
Summary
- Follow-up to #2331. Three additional tightening commits on the action-tool / sandbox / embedded-webview permission surface.
- Action-tool autonomy:
node_exec+npm_execnow honour thecan_act()gate that every other action tool already enforces. - Sandbox policy:
find -execdir/-okdirjoin the existing-exec/-okblock; inline env-var prefixes that mutate downstream subprocess execution (pager / editor / SSH / diff hooks + dynamic-loader overrides + shell-eval vars) are rejected at allowlist time. - Embedded-webview perms:
displayCaptureremoved from theBrowser.grantPermissionsset for Meet + Slack so Chromium's gesture gate ongetDisplayMediastays in force.
Problem
The shipped sandbox + action-tool surface had three remaining gaps that the earlier transport tightening (#2331) did not cover:
-
Autonomy bypass on script-runner tools.
file_write,edit_file,apply_patch,curl,http_request,pushover,csv_export, and friends all short-circuit onAutonomyLevel::ReadOnlyviaself.security.can_act().node_execandnpm_execdid not — they only consulted the per-hour rate limiter. An agent configured for read-only operation (e.g. a Slack / iMessage / Discord assistant where the expected guarantee is "observe only, never act") could still run arbitrary JavaScript viainline_code, and through it arbitrary OS commands. Single prompt-injected message in a watched channel = full code execution on the host. -
findarg blocklist incomplete.is_args_safe("find")blocked-execand-ok. The semantically identical-execdirand-okdir(same per-match command execution, just with cwd set to the match's parent) were not blocked.findis in the default allowlist, so the gap was directly reachable. -
Inline env-var prefix bypass.
skip_env_assignments()stripped leadingKEY=valuetokens before the allowlist check. The bare command after the prefix (git log,git diff,cat, etc.) was allowlisted, but the prefix at exec time mutated the downstream binary's behaviour to spawn the assigned value as a subprocess:GIT_PAGER=<cmd> git log,GIT_SSH_COMMAND=<cmd> git fetch,LESSOPEN=<cmd> cat,LD_PRELOAD=<lib> any-allowed-binary,BASH_ENV=<rc> any-shell-call, etc. -
Browser.grantPermissions(displayCapture)bypassed Chromium's gesture gate. The embedded Meet + Slack Huddles webviews haddisplayCapturein their auto-grant set. Pre-granting it via CDP defeats the transient-activation requirement Chromium normally enforces onnavigator.mediaDevices.getDisplayMedia. A page inside the embedded origin could initiate a desktop capture programmatically — no click, no screen-picker. Auto-grant was originally added (#1022 / #1054) to skip the cam/mic consent dialog; that justification holds foraudioCapture/videoCapturebut never applied todisplayCapture, which has its own native screen-picker flow that should run on user gesture.
Solution
Three commits, scoped per-fix so each can be reverted independently:
-
feat(security/tools): require can_act for node_exec and npm_exec— three-line guard at the top of each tool'sexecute(), mirroring the pattern fromfile_write.rs:56-59. Fires before the existing rate-limit check so the autonomy-block error message is not masked by an unrelated rate-limit error. -
feat(security/policy): block find -execdir/-okdir and dangerous env prefixes— extends thefindblocklist with the two missing flags; addsDANGEROUS_ENV_PREFIXES(~30 names: pager / editor / SSH / diff hooks,BASH_ENV,ENV,PROMPT_COMMAND,PS1–PS4,PYTHONSTARTUP,PYTHONPATH,LD_PRELOAD,LD_AUDIT,LD_LIBRARY_PATH,DYLD_INSERT_LIBRARIES,DYLD_LIBRARY_PATH,DYLD_FORCE_FLAT_NAMESPACE,PATH,SHELL,IFS);has_dangerous_env_prefix()rejects the segment if any of those names appear. Benign prefixes (TZ,LANG,LC_ALL, arbitrary user-named) still pass. Allowlist intentionally enumerates hooks known to spawn subprocesses or alter binary resolution — no attempt to enumerate every env var ever assigned. Case-insensitive matcher sogit_pager=...andLd_PrElOaD=...are also rejected. -
fix(cdp/session): drop displayCapture from origin auto-grants— removes"displayCapture"from the Meet + Slack pre-grant arrays inapp/src-tauri/src/cdp/session.rs.audioCapture/videoCapture/clipboardReadWritestay pre-granted (these are load-bearing for greenroom cam/mic auto-grant per #1022 / #1054 and don't compromise the gesture gate the same way). User-visible flow on click is unchanged: clicking Meet's "Present" / Slack's huddle share button still firesgetDisplayMedia, Chrome's native screen-picker shows on the click, the user picks a source, the stream lands. Only blocked path: the page callinggetDisplayMediaprogrammatically without a gesture.
Submission Checklist
- [x] Tests added or updated — new
dangerous_env_var_prefix_blockedcovers every blocked env name plus the benign-prefix passthrough; existingcommand_argument_injection_blockedextended to cover-execdirand-okdir. 111 / 111 pass oncargo test --lib openhuman::security::policy::tests::. - [x] Diff coverage ≥ 80% — every changed line in
policy.rsand the policy module is covered by the extended + new tests;node_exec/npm_execguards mirror the existingcan_act()pattern that the surrounding tools already cover via their own ReadOnly tests;cdp/session.rschange is a deletion of three string literals from two arrays (no coverable code path added). - [ ] Coverage matrix updated — N/A: behaviour-only tightening of existing surfaces; no new feature row to add to
docs/TEST-COVERAGE-MATRIX.md. - [ ] All affected feature IDs from the matrix are listed in
## Related— N/A: same reason as above. - [x] No new external network dependencies introduced — three internal-only files touched.
- [ ] Manual smoke checklist updated if this touches release-cut surfaces — N/A: no new release-cut surfaces. Adding a one-line note to
docs/RELEASE-MANUAL-SMOKE.mdto smoke Meet "Present" + Slack huddle screen-share after this change is queued as a follow-up. - [x] Linked issue closed via
Closes #NNNin the## Relatedsection — N/A: no public tracking issue (security-internal). Sentry / GHSA dashboard tracks the items off-PR.
Impact
- Security: tightens three independent bypass classes in the action-tool / sandbox / embedded-webview perm surface. Lowers blast radius of prompt-injection-driven attacks against channel-bot ReadOnly deployments, allowlist-allowed binaries that hook env vars, and pages inside embedded Meet / Slack webviews.
- Behaviour:
node_exec/npm_execnow refuse cleanly in ReadOnly (same error string as the other tools);find -execdir/-okdirnow refuse with the same code path as-exec/-ok; commands carrying a dangerous env prefix now refuse the same way an unallowlisted binary refuses;getDisplayMediafrom Meet + Slack pages now requires a click (matches Chromium's default for non-pre-granted origins). - Performance: nil. Three constant-time checks added to existing per-segment validation; one shorter array on the CDP call.
- Compatibility: dev tools, agent harness, and end-user UX paths are intentionally untouched. Tests cover both the new rejections and the benign passthroughs that must still work.
Related
- Follows: #2331 (initial transport + memory + channels tightening, merged 2026-05-21)
- Closes:
- Follow-up PR(s)/TODOs:
- Append a smoke line to
docs/RELEASE-MANUAL-SMOKE.mdfor Meet "Present" + Slack huddle screen-share post-displayCapture-drop - Revisit
DANGEROUS_ENV_PREFIXESwhen adding new allowlisted commands insrc/openhuman/security/policy.rs
- Append a smoke line to
AI Authored PR Metadata
Linear Issue
- Key: N/A
- URL: N/A
Commit & Branch
- Branch:
feat/runtime-policy-tightening-v2 - Commit SHA:
bf2b8bf0(tip; 3 commits in the series)
Validation Run
- [x]
pnpm --filter openhuman-app format:check— N/A: no TypeScript or app-workspace files touched (Rust core + Tauri shell only). - [x]
pnpm typecheck— N/A: same reason. - [x] Focused tests:
cargo test --lib openhuman::security::policy::tests::— 111 passed / 0 failed, including newdangerous_env_var_prefix_blockedand the extendedcommand_argument_injection_blocked. - [x] Rust fmt/check:
cargo check --manifest-path Cargo.tomlclean (pre-existing warnings onslack-backfillbinary unchanged);cargo fmt --checkclean on touched files. - [x] Tauri fmt/check:
cargo check --manifest-path app/src-tauri/Cargo.tomlclean aftergit submodule update --init --recursive.
Validation Blocked
command:N/Aerror:N/Aimpact:N/A
Behavior Changes
- Intended behavior change: three previously-reachable bypass paths now reject cleanly. No change to the legitimate dev / agent / end-user paths.
- User-visible effect: ReadOnly-mode agents that previously could still spawn JS via
node_exec/npm_execnow refuse with the standard "Action blocked: autonomy is read-only" error.getDisplayMediainside Meet / Slack now requires a user gesture (matches Chromium default).
Parity Contract
- Legacy behavior preserved: yes for every valid path. Cam/mic auto-grant on Meet + Slack unchanged. Benign env prefixes (
TZ,LANG,LC_ALL, etc.) still pass the allowlist.findwith legitimate args (-name,-type,-maxdepth, etc.) still passes. - Guard/fallback/dispatch parity checks: the new
can_act()guards mirror the existing pattern fromfile_write/edit_file/curl/http_requestexactly; reviewers can diff the new lines against any of those for visual parity.
Duplicate / Superseded PR Handling
- Duplicate PR(s): none
- Canonical PR: this PR
- Resolution: N/A — clean follow-up to #2331.
Summary by CodeRabbit
- Bug Fixes
- Improved command validation to prevent dangerous environment variable injection attacks.
- Blocked additional execution pathways that could bypass safety checks.
- Added authorization checks for Node.js and npm command execution.
- Adjusted permissions for Google Meet and Slack to enhance privacy and clipboard functionality.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cde45e0f-393a-4d75-b7a1-24d9d0c66abe
📥 Commits
Reviewing files that changed from the base of the PR and between efa9b5d0f1f41fd07ab618c0aff4813782060afd and 12c8d488f1a6bb795d1e506093fdd1eebaf4b18f.
📒 Files selected for processing (1)
src/openhuman/memory_tools/tools/put.rs
✅ Files skipped from review due to trivial changes (1)
- src/openhuman/memory_tools/tools/put.rs
📝 Walkthrough
Walkthrough
This PR blocks dangerous inline env-prefix command forms and additional find execution flags, updates per-origin CDP permission pre-grants to remove desktop-capture for Meet/Slack while keeping media/clipboard, and serializes two MemoryTools tests with a global test lock.
Changes
Command Execution Security Hardening
| Layer / File(s) | Summary |
|---|---|
Dangerous environment-variable prefix detection src/openhuman/security/policy.rs, src/openhuman/security/policy_tests.rs |
Adds DANGEROUS_ENV_PREFIXES and has_dangerous_env_prefix to detect leading NAME=... env assignments and denies segments with dangerous names inside SecurityPolicy::is_command_allowed. Tests assert rejection for high-risk prefixes and allow benign forms. |
Find command-execution pathway blocking src/openhuman/security/policy.rs, src/openhuman/security/policy_tests.rs |
Extends find argument validation to reject -execdir and -okdir in addition to -exec/-ok. Regression tests assert these variants are blocked. |
Browser Permission Configuration
| Layer / File(s) | Summary |
|---|---|
Embedded provider permission grants app/src-tauri/src/cdp/session.rs |
For meet.google.com and app.slack.com, remove displayCapture from Browser.grantPermissions pre-grants and add/adjust comments to document gesture-gate and clipboard/media intent; add clipboardReadWrite for Meet pre-grants. |
Test synchronization
| Layer / File(s) | Summary |
|---|---|
MemoryTools test lock acquisition src/openhuman/memory_tools/tools/put.rs |
Two async tests now acquire and await GLOBAL_MEMORY_TEST_LOCK before creating temp workspaces and running the tool to prevent concurrent test interference. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- tinyhumansai/openhuman#2013: Both PRs modify
src/openhuman/security/policy.rsto harden command validation and block execution pathways.
Suggested reviewers
- senamakel
- sanil-23
Poem
🐰 I sniff the env and guard the gate,
No sneaky PREFIX gets to dictate.
Find's secret doors are barred and shut,
No desktop-capture in Meet or Huddles — what's up?
Tests now wait their turn, neat and small,
A rabbit hops in, keeping safe for all.
🚥 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 'feat: tighten runtime policy + transport guards v2' directly and accurately summarizes the main security-focused changes across all modified files: enhanced sandbox policy, action-tool autonomy guards, and embedded-webview permission restrictions. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ 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.