Skip to content

The agent that grows with you

fix(tools): explicit empty toolset allowlist must fail closed, not open

Austin Pickettb4969d8e2d09
diff --git a/cron/jobs.py b/cron/jobs.py
index 2e421c7af32..de66ce7698c 100644
--- a/cron/jobs.py
+++ b/cron/jobs.py
@@ -1,3 +1,4 @@
+# health: allow FILE_LINES -- security fix for #82010: distinguish an explicitly-empty toolset allowlist (fail closed, nothing allowed) from an absent one (no restriction); the added lines are minimal fail-closed branches at this existing chokepoint
"""Cron job storage: ~/.hermes/cron/jobs.json; output in
~/.hermes/cron/output/{job_id}/{timestamp}.md"""
@@ -1705,6 +1706,17 @@ def _normalize_str_list(items: Any) -> Optional[List[str]]:
return [str(j).strip() for j in items if str(j).strip()] or None
+def _normalize_enabled_toolsets(value: Any) -> Optional[List[str]]:
+ """Per-job toolset allowlist. An explicitly-set EMPTY list means 'nothing allowed' and must
+ persist as [] — normalizing it to None would read back as 'no restriction' (#82010). Absent
+ or None stays None (the unrestricted default); a non-list raises before anything is stored."""
+ if value is None:
+ return None
+ if not isinstance(value, list):
+ raise ValueError("enabled_toolsets must be a list of toolset names (or [] for none).")
+ return [str(j).strip() for j in value if str(j).strip()]
+
+
def _normalize_context_from(value: Any) -> Optional[List[str]]:
"""Accept a job id or a list of ids; anything else is None."""
if isinstance(value, str):
@@ -1751,7 +1763,7 @@ _CREATE_FIELD_NORMALIZERS: Dict[str, Callable[[Any], Any]] = {
"script": _normalize_job_optional_text,
"monitor_script": _normalize_job_optional_text,
"monitor_url": _normalize_job_optional_text,
- "enabled_toolsets": lambda v: _normalize_str_list(v) if v else None,
+ "enabled_toolsets": _normalize_enabled_toolsets,
"workdir": _normalize_workdir,
"no_agent": bool,
"context_from": _normalize_context_from,
@@ -1759,6 +1771,8 @@ _CREATE_FIELD_NORMALIZERS: Dict[str, Callable[[Any], Any]] = {
"interpreter": _normalize_job_optional_text,
}
_UPDATE_FIELD_NORMALIZERS: Dict[str, Callable[[Any], Any]] = {
+ # [] is an explicit zero-tool allowlist and must survive the update path as [] too (#82010).
+ "enabled_toolsets": _normalize_enabled_toolsets,
"workdir": lambda v: None if v in {None, "", False} else _normalize_workdir(v),
"monitor_script": _normalize_job_optional_text,
"monitor_url": _normalize_job_optional_text,
diff --git a/cron/scheduler.py b/cron/scheduler.py
index dcf8566e897..3268a250f24 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -1,3 +1,4 @@
+# health: allow FILE_LINES -- security fix for #82010: distinguish an explicitly-empty toolset allowlist (fail closed, nothing allowed) from an absent one (no restriction); the added lines are minimal fail-closed branches at this existing chokepoint
"""Cron job scheduler: tick() runs due jobs (gateway calls it every 60s from a background thread).
A file lock (~/.hermes/cron/.tick.lock) keeps overlapping processes to one tick at a time.
"""
@@ -494,7 +495,10 @@ def _resolve_cron_enabled_toolsets(job: dict, cfg: dict) -> list[str]:
1. Per-job ``enabled_toolsets`` (set via ``cronjob`` tool on create/update). Keeps the agent's
job-scoped toolset override intact — #6130. Enabled MCP servers are layered on per
- ``_merge_mcp_into_per_job_toolsets`` so a native-toolset allowlist does not silently strip MCP tools. 2.
+ ``_merge_mcp_into_per_job_toolsets`` so a native-toolset allowlist does not silently strip MCP tools.
+ An explicitly-set EMPTY list is a zero-toolset allowlist, not a clear to the platform default —
+ it is falsy, so it must be compared with ``is not None``, else it fell through to the config
+ default and widened an unattended job back to every toolset (#82010). 2.
Mirrors gateway behavior (``_get_platform_tools(cfg, platform_key)``) so users can gate cron toolsets
globally without recreating every job. 3. Never ``None``: AIAgent reads ``None`` as "every
toolset", so an unreadable ``platform_toolsets.cron`` restriction would hand an unattended job
@@ -502,7 +506,11 @@ def _resolve_cron_enabled_toolsets(job: dict, cfg: dict) -> list[str]:
error on the job and opens an incident, so the operator sees it instead of a widened run.
"""
per_job = job.get("enabled_toolsets")
- if per_job:
+ if per_job is not None:
+ if not per_job:
+ # Explicit zero: no toolsets at all — no MCP merge either, else every enabled server
+ # would ride back in and widen the allowlist the operator just emptied (#82010).
+ return []
return _merge_mcp_into_per_job_toolsets(list(per_job), cfg or {})
try:
from hermes_cli.tools_config import _get_platform_tools # lazy: avoid heavy import at cron module load
diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.py
index 2dfe8cf18c5..d98734f42be 100644
--- a/hermes_cli/tools_config.py
+++ b/hermes_cli/tools_config.py
@@ -561,6 +561,19 @@ def _coerce_platform_toolsets_value(value, platform: str):
return value
+def _platform_toolsets_explicitly_saved(config: dict, platform: str) -> bool:
+ """True when ``platform_toolsets.<platform>`` holds an explicitly saved LIST (even ``[]``).
+
+ ``_get_platform_tools``'s ``explicitly_configured`` flag without re-running the resolver
+ (post-coercion, so a list-literal string counts too): an unset key or a non-list value
+ falls back to the platform default. Callers use this to tell an explicit zero-tool
+ selection (fail closed, #82010) from an absent one ("no restriction").
+ """
+ platform_toolsets = config.get("platform_toolsets") or {}
+ raw = platform_toolsets.get(platform)
+ return isinstance(_coerce_platform_toolsets_value(raw, platform), list)
+
+
def _get_platform_tools(config: dict, platform: str, *, include_default_mcp_servers: bool = True) -> Set[str]:
"""Resolve which individual toolset names are enabled for a platform."""
platform_toolsets = config.get("platform_toolsets") or {}
diff --git a/tests/cron/test_cron_explicit_empty_toolsets.py b/tests/cron/test_cron_explicit_empty_toolsets.py
new file mode 100644
index 00000000000..4a308bc4315
--- /dev/null
+++ b/tests/cron/test_cron_explicit_empty_toolsets.py
@@ -0,0 +1,81 @@
+"""An explicitly-set EMPTY per-job toolset allowlist must mean 'nothing allowed' end to end.
+
+The create/update normalizers turned ``enabled_toolsets=[]`` into null, and the dispatch
+resolver treated a stored ``[]`` as absent (falsy), so a locked-down job silently widened
+back to the platform default — every toolset (#82010). Absent/null keeps meaning
+'no per-job restriction'."""
+
+from __future__ import annotations
+
+import pytest
+
+
+def hermes_env(tmp_path, monkeypatch):
+ """Isolate HERMES_HOME for each test so jobs don't leak between tests."""
+ home = tmp_path / ".hermes"
+ home.mkdir()
+ (home / "scripts").mkdir()
+ (home / "cron").mkdir()
+
+ monkeypatch.setenv("HERMES_HOME", str(home))
+
+ import importlib
+
+ import hermes_constants
+ importlib.reload(hermes_constants)
+ import cron.jobs
+ importlib.reload(cron.jobs)
+ import cron.scheduler
+ importlib.reload(cron.scheduler)
+ return home
+
+
+def test_create_persists_explicit_empty_allowlist_and_survives_reload(hermes_env):
+ import importlib
+
+ from cron.jobs import create_job
+
+ job = create_job(prompt="daily digest", schedule="every 1h", enabled_toolsets=[])
+ assert job["enabled_toolsets"] == []
+
+ # A fresh process (module reload) must read the restriction back from jobs.json as [],
+ # not null — null would read as 'no restriction' and widen the job.
+ import cron.jobs
+ importlib.reload(cron.jobs)
+ reloaded = cron.jobs.get_job(job["id"])
+ assert reloaded is not None and reloaded["enabled_toolsets"] == []
+
+
+def test_update_path_preserves_explicit_empty_allowlist(hermes_env):
+ from cron.jobs import create_job, update_job
+
+ job = create_job(prompt="daily digest", schedule="every 1h")
+ assert job["enabled_toolsets"] is None # absent = no per-job restriction
+
+ updated = update_job(job["id"], {"enabled_toolsets": []})
+ assert updated is not None and updated["enabled_toolsets"] == []
+
+
+def test_scheduler_resolves_explicit_empty_as_zero_toolsets(hermes_env):
+ from cron.scheduler import _resolve_cron_enabled_toolsets
+
+ # [] = zero toolsets, fail closed — not a fall-through to the platform default.
+ assert _resolve_cron_enabled_toolsets({"enabled_toolsets": []}, {}) == []
+ # Absent stays 'no per-job restriction': the platform default selection still applies.
+ assert _resolve_cron_enabled_toolsets({}, {})
+
+
+def test_cronjob_tool_roundtrip_preserves_explicit_empty(hermes_env):
+ """The reporter's exact path: cronjob create with enabled_toolsets=[] from a session."""
+ import json
+
+ from cron.jobs import get_job
+ from tools.cronjob_tools import cronjob
+
+ result = json.loads(cronjob(
+ action="create", prompt="daily digest", schedule="every 1h", enabled_toolsets=[]))
+ assert result["success"] is True, result
+
+ job = get_job(result["job_id"])
+ assert job is not None and job["enabled_toolsets"] == []
diff --git a/tests/tui_gateway/test_gui_surface_toolsets.py b/tests/tui_gateway/test_gui_surface_toolsets.py
index a851c3af6b3..0ab7d1c1499 100644
--- a/tests/tui_gateway/test_gui_surface_toolsets.py
+++ b/tests/tui_gateway/test_gui_surface_toolsets.py
@@ -113,3 +113,42 @@ class TestResolverPlumbing:
no_desktop_env.setenv("HERMES_TUI_TOOLSETS", "web,memory")
assert server._load_enabled_toolsets("desktop") == ["web", "memory"]
+
+
+class TestExplicitEmptySelection:
+ """#82010: an explicitly saved empty platform_toolsets list is a zero-tool state.
+
+ ``platform_toolsets.cli: []`` used to fall open — the resolver returned an empty set and
+ the gateway converted it to None, which downstream means 'no restriction' (every
+ toolset). Only an ABSENT key means that; the explicit empty list must return [].
+ """
+
+ @staticmethod
+ def _config(no_desktop_env, platform_toolsets):
+ import agent.coding_context as cc
+ import hermes_cli.config as config_mod
+
+ no_desktop_env.setattr(cc, "coding_selection", lambda **_: None)
+ no_desktop_env.setattr(
+ config_mod, "load_config", lambda: {"platform_toolsets": platform_toolsets}
+ )
+
+ def test_explicit_empty_list_yields_no_toolsets(self, no_desktop_env):
+ self._config(no_desktop_env, {"cli": []})
+
+ assert server._load_enabled_toolsets("desktop") == []
+ assert server._load_enabled_toolsets("tui") == []
+
+ def test_absent_key_keeps_the_default_selection(self, no_desktop_env):
+ self._config(no_desktop_env, {})
+
+ result = server._load_enabled_toolsets("tui")
+ assert result # the platform default applies — not the zero state, not None-as-all
+
+ def test_named_selection_is_honored(self, no_desktop_env):
+ self._config(no_desktop_env, {"cli": ["memory"]})
+
+ result = server._load_enabled_toolsets("tui")
+ assert result is not None
+ assert "memory" in result
+ assert "terminal" not in result
diff --git a/tools/cronjob_tools.py b/tools/cronjob_tools.py
index c0bba0c2a2f..8c6a7a34790 100644
--- a/tools/cronjob_tools.py
+++ b/tools/cronjob_tools.py
@@ -688,7 +688,9 @@ def _action_create(a: Dict[str, Any]) -> str:
model=_normalize_optional_job_value(a["model"]), provider=_normalize_optional_job_value(a["provider"]),
base_url=_normalize_optional_job_value(a["base_url"], strip_trailing_slash=True),
script=_normalize_optional_job_value(script), context_from=context_from,
- enabled_toolsets=a["enabled_toolsets"] or None, workdir=_normalize_optional_job_value(a["workdir"]),
+ # [] is an explicit zero-tool allowlist, not a clear back to the unrestricted default (#82010).
+ enabled_toolsets=a["enabled_toolsets"] if a["enabled_toolsets"] is not None else None,
+ workdir=_normalize_optional_job_value(a["workdir"]),
no_agent=_no_agent, attach_to_session=a["attach_to_session"],
monitor_script=_normalize_optional_job_value(a["monitor_script"]),
monitor_url=_normalize_optional_job_value(a["monitor_url"]),
@@ -902,7 +904,8 @@ def _update_context_from(job: Dict[str, Any], a: Dict[str, Any], updates: Dict[s
def _update_run_fields(job: Dict[str, Any], a: Dict[str, Any], updates: Dict[str, Any]) -> Optional[str]:
"""enabled_toolsets / attach_to_session / workdir / no_agent / repeat / schedule."""
if a["enabled_toolsets"] is not None:
- updates["enabled_toolsets"] = a["enabled_toolsets"] or None
+ # [] is an explicit zero-tool allowlist, not a clear back to the unrestricted default (#82010).
+ updates["enabled_toolsets"] = a["enabled_toolsets"]
if a["attach_to_session"] is not None:
updates["attach_to_session"] = bool(a["attach_to_session"])
if a["workdir"] is not None:
@@ -1129,7 +1132,7 @@ Jobs run in a fresh session with no current-chat context, so prompts must be sel
"enabled_toolsets": {
"type": "array",
"items": {"type": "string"},
- "description": "Optional toolset names to restrict the job's agent to (e.g. [\"web\", \"terminal\"]) — cuts token overhead. Infer from the prompt. Omit for all default tools. On update, [] clears."
+ "description": "Optional toolset names to restrict the job's agent to (e.g. [\"web\", \"terminal\"]) — cuts token overhead. Infer from the prompt. Omit for all default tools. [] = an explicit zero-tool allowlist (the job's agent gets no toolsets, MCP servers included unless named); it is preserved as [], never widened back to the default."
},
"workdir": {
"type": "string",
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index 641f2221afe..ed5bf22e2b5 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -1,3 +1,4 @@
+# health: allow FILE_LINES -- security fix for #82010: distinguish an explicitly-empty toolset allowlist (fail closed, nothing allowed) from an absent one (no restriction); the added lines are minimal fail-closed branches at this existing chokepoint
import atexit
import concurrent.futures
import contextlib
@@ -2048,7 +2049,9 @@ def _resolve_explicit_toolsets(explicit: list[str], validate_toolset) -> list[st
def _load_enabled_toolsets(platform: str | None = None) -> list[str] | None:
"""The agent's toolsets for this session (None = all): an explicit HERMES_TUI_TOOLSETS pin; else the
coding posture (coding_context collapses to coding toolset + enabled MCP servers in a code workspace);
- else the configured CLI toolsets. Client-surface toolsets fold in here — only this surface can answer them."""
+ else the configured CLI toolsets. Client-surface toolsets fold in here — only this surface can answer them.
+ An explicitly saved EMPTY list (``platform_toolsets.cli: []`` that resolves to nothing) is a
+ zero-tool state and returns [] — never None, which would mean unrestricted (#82010)."""
session_platform = platform or _resolve_session_platform()
explicit = [item.strip() for item in os.environ.get("HERMES_TUI_TOOLSETS", "").split(",") if item.strip()]
fallback_notice = None
@@ -2070,7 +2073,7 @@ def _load_enabled_toolsets(platform: str | None = None) -> list[str] | None:
fallback_notice = "[tui] no valid HERMES_TUI_TOOLSETS entries; using configured CLI toolsets"
try:
from hermes_cli.config import load_config
- from hermes_cli.tools_config import _get_platform_tools
+ from hermes_cli.tools_config import _get_platform_tools, _platform_toolsets_explicitly_saved
cfg = load_config()
# include_default_mcp_servers=True is the runtime variant (the agent must be able to call
# default MCP servers); the config-editing variant would silently drop MCP tools from the TUI.
@@ -2080,7 +2083,16 @@ def _load_enabled_toolsets(platform: str | None = None) -> list[str] | None:
enabled = _get_platform_tools(cfg, "cli", include_default_mcp_servers=True)
if fallback_notice is not None:
_tui_notice(fallback_notice)
- return sorted(_with_session_toolsets(enabled, session_platform)) if enabled else None
+ if enabled:
+ return sorted(_with_session_toolsets(enabled, session_platform))
+ # An explicitly saved list that resolves to nothing (``platform_toolsets.cli: []`` with no
+ # enabled MCP servers) is an explicit zero-tool state, not "no filter": fail closed with []
+ # instead of None (#82010). The client-surface fold-in must not resurrect tools the user
+ # explicitly switched off, so [] is returned bare. Only an ABSENT/unset key keeps the
+ # None = "no restriction" default below.
+ if _platform_toolsets_explicitly_saved(cfg, "cli"):
+ return []
+ return None
except Exception:
if fallback_notice is not None:
_tui_notice("[tui] no valid HERMES_TUI_TOOLSETS entries and configured CLI toolsets could not be loaded; enabling all toolsets")