Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: enforce host tool withholding in named scopes

Steven Enamakel8cb8cd9aaf95
diff --git a/app/test/playwright/specs/tool-shell-git-flow.spec.ts b/app/test/playwright/specs/tool-shell-git-flow.spec.ts
index 536f644c72..742f8b32c2 100644
--- a/app/test/playwright/specs/tool-shell-git-flow.spec.ts
+++ b/app/test/playwright/specs/tool-shell-git-flow.spec.ts
@@ -1,6 +1,7 @@
import * as path from 'node:path';
import { expect, test } from '@playwright/test';
import { spawn } from 'node:child_process';
+import { randomUUID } from 'node:crypto';
import { promises as fs } from 'node:fs';
import { bootAuthenticatedPage, callCoreRpc } from '../helpers/core-rpc';
@@ -131,6 +132,20 @@ test.describe('System tools - Shell + Git', () => {
).rejects.toThrow(/exactly one of `path` or `text`/i);
});
+ test('workspace file writes reject traversal and absolute paths without writing outside the workspace', async () => {
+ const escapedFile = path.resolve(workspaceDir(), '..', `e2e-escape-967-${randomUUID()}.txt`);
+ const traversalName = path.relative(workspaceDir(), escapedFile);
+ for (const filename of [traversalName, escapedFile]) {
+ await expect(
+ callCoreRpc('openhuman.workspace_file_write', {
+ filename,
+ contents: 'must stay inside the workspace',
+ })
+ ).rejects.toThrow();
+ }
+ await expect(fs.readFile(escapedFile, 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
+ });
+
test('fixture git repo inside OPENHUMAN_WORKSPACE supports read ops', async () => {
const repoDir = path.join(workspaceDir(), FIXTURE_REPO_REL);
const status = await runLocal('git', ['status', '--porcelain=2', '--branch'], repoDir);
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs
index e8594b224b..36d273e0f6 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs
@@ -36,6 +36,49 @@ fn definition() -> crate::agent::harness::definition::AgentDefinition {
super::wildcard_probe_def()
}
+#[test]
+fn host_scope_additions_respect_named_and_withheld_tools() {
+ let mut definition = definition();
+ definition.tools = crate::agent::harness::definition::ToolScope::Named(vec![
+ "base".into(),
+ "already_withheld".into(),
+ ]);
+ definition.extra_tools = vec!["already_withheld".into(), "base".into()];
+ let host_tools = super::super::host_tools::MergedHostTurnTools {
+ policy: None,
+ withheld: std::collections::HashSet::from(["already_withheld".into(), "hidden".into()]),
+ permanent: std::collections::HashSet::new(),
+ scope_additions: std::collections::HashSet::from(["host_visible".into()]),
+ };
+
+ let resolved = super::super::host_tools::scope_def(Some(&definition), &host_tools).unwrap();
+ assert!(matches!(
+ &resolved.tools,
+ crate::agent::harness::definition::ToolScope::Named(names)
+ if names.len() == 1 && names[0] == "base"
+ ));
+ assert_eq!(resolved.extra_tools, vec!["base", "host_visible"]);
+}
+
+#[test]
+fn host_scope_additions_leave_wildcard_definitions_unchanged() {
+ let mut definition = definition();
+ definition.extra_tools = vec!["existing".into()];
+ let host_tools = super::super::host_tools::MergedHostTurnTools {
+ policy: None,
+ withheld: std::collections::HashSet::from(["existing".into()]),
+ permanent: std::collections::HashSet::new(),
+ scope_additions: std::collections::HashSet::from(["host_visible".into()]),
+ };
+
+ let resolved = super::super::host_tools::scope_def(Some(&definition), &host_tools).unwrap();
+ assert_eq!(resolved.extra_tools, vec!["existing"]);
+ assert!(matches!(
+ resolved.tools,
+ crate::agent::harness::definition::ToolScope::Wildcard
+ ));
+}
+
/// The whole point: a name the host supplied is callable, and the model is
/// told about it. Advertised-but-absent is a call that fails; present-but-
/// unadvertised is a tool the model never reaches for.
diff --git a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
index 5fc7876ad8..2485b164db 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
@@ -201,10 +201,11 @@ pub(super) fn scope_def(
host_tools: &MergedHostTurnTools,
) -> Option<crate::agent::harness::definition::AgentDefinition> {
let mut definition = definition.cloned()?;
- if matches!(
- definition.tools,
- crate::agent::harness::definition::ToolScope::Named(_)
- ) {
+ if let crate::agent::harness::definition::ToolScope::Named(names) = &mut definition.tools {
+ names.retain(|name| !host_tools.withheld.contains(name));
+ definition
+ .extra_tools
+ .retain(|name| !host_tools.withheld.contains(name));
definition
.extra_tools
.extend(host_tools.scope_additions.iter().cloned());