Skip to content

The agent that grows with you

fix(approval): widen webhook exclusion to all unattended platforms, deny by default

Tekniumef71f2cad8b4
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.py
index aeb98a8375f..0fabb458847 100644
--- a/hermes_cli/config_defaults.py
+++ b/hermes_cli/config_defaults.py
@@ -2521,6 +2521,16 @@ DEFAULT_CONFIG = {
# safe; mirrors cron_mode deny)
# approve — auto-approve all dangerous commands in single-query mode
#
+ # unattended_mode — what to do when a session on an unattended
+ # programmatic platform (webhook, msgraph_webhook, api_server) hits a
+ # dangerous command. These surfaces bind a session platform like chat
+ # gateways do, but have no send_exec_approval and no /approve channel —
+ # a pending approval there just blocks for the full timeout with nobody
+ # to answer (#37284, #87509):
+ # deny — block the command instantly and let the agent find another
+ # way (default, safe; mirrors cron_mode deny)
+ # approve — auto-approve all dangerous commands on unattended platforms
+ #
# timeout — seconds to wait for the user's approve/deny before failing
# closed (deny). Shared by the CLI prompt and gateway/messaging waits.
# Messaging approvals arrive as a push notification the user may not see
@@ -2531,6 +2541,7 @@ DEFAULT_CONFIG = {
"timeout": 300,
"cron_mode": "deny",
"single_query_mode": "deny",
+ "unattended_mode": "deny",
# Operator-customizable policy text for smart approvals. When
# non-empty, this is appended to the smart-approval guardian's
# SYSTEM prompt (trusted channel) as additional rules — e.g.
diff --git a/tests/tools/test_approval.py b/tests/tools/test_approval.py
index 683337bc7f1..0d0a666bcbb 100644
--- a/tests/tools/test_approval.py
+++ b/tests/tools/test_approval.py
@@ -705,15 +705,17 @@ class TestGatewayProtection:
class TestWebhookApprovalExclusion:
- """Webhook sessions must NOT be treated as gateway approval contexts.
+ """Unattended platform sessions must NOT be treated as gateway approval contexts.
- The webhook adapter has no ``send_exec_approval`` method and no way to
- receive ``/approve`` replies. If a webhook session triggers a dangerous
- command and falls through to the gateway approval branch, the session
- blocks for the full timeout (60-300 s) with no human who can resolve it.
+ The webhook / msgraph_webhook / api_server adapters have no
+ ``send_exec_approval`` method and no way to receive ``/approve`` replies.
+ If such a session triggers a dangerous command and falls through to the
+ gateway approval branch, the session blocks for the full timeout
+ (60-300 s) with no human who can resolve it (#37284, #87509).
- Fix: ``_is_gateway_approval_context()`` returns ``False`` when the
- session platform is ``"webhook"``.
+ Fix: ``_is_gateway_approval_context()`` returns ``False`` for platforms
+ in ``_UNATTENDED_APPROVAL_PLATFORMS``; the decision is governed by
+ ``approvals.unattended_mode`` (default deny) instead.
"""
def test_webhook_platform_returns_false(self, monkeypatch):
@@ -726,6 +728,19 @@ class TestWebhookApprovalExclusion:
assert _is_gateway_approval_context() is False
+ def test_all_unattended_platforms_return_false(self, monkeypatch):
+ """Every unattended programmatic platform is excluded, not just webhook."""
+ from tools.approval import (
+ _UNATTENDED_APPROVAL_PLATFORMS,
+ _is_gateway_approval_context,
+ )
+
+ monkeypatch.delenv("HERMES_CRON_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
+ for platform in _UNATTENDED_APPROVAL_PLATFORMS:
+ monkeypatch.setenv("HERMES_SESSION_PLATFORM", platform)
+ assert _is_gateway_approval_context() is False, platform
+
def test_non_webhook_gateway_session_returns_true(self, monkeypatch):
"""Non-webhook gateway sessions (e.g. Telegram) are still gateway contexts."""
from tools.approval import _is_gateway_approval_context
@@ -755,15 +770,24 @@ class TestWebhookApprovalExclusion:
assert _is_gateway_approval_context() is False
- def test_webhook_dangerous_command_auto_approves(self, monkeypatch):
- """Webhook sessions that trigger dangerous commands auto-approve with a warning.
+ def _isolate(self, monkeypatch):
+ """Neutralize host leakage: yolo frozen at import time + real config."""
+ import tools.approval as approval_mod
+
+ monkeypatch.setattr(approval_mod, "_YOLO_MODE_FROZEN", False)
+ monkeypatch.setattr(approval_mod, "_get_approval_mode", lambda: "smart")
+
+ def test_webhook_dangerous_command_denies_by_default(self, monkeypatch):
+ """Webhook sessions that trigger dangerous commands DENY instantly.
- This is the non-interactive, non-gateway path - safe because the
- command does not execute in an interactive context where the user
- could be tricked.
+ Deny-by-default (approvals.unattended_mode: deny) mirrors cron: an
+ unattended session must never silently execute a flagged command,
+ and must never block waiting for an approval nobody can answer.
+ The deny message tells the agent how the operator can opt in.
"""
from tools.approval import check_all_command_guards
+ self._isolate(monkeypatch)
monkeypatch.delenv("HERMES_CRON_SESSION", raising=False)
monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
@@ -771,9 +795,72 @@ class TestWebhookApprovalExclusion:
monkeypatch.setenv("HERMES_SESSION_KEY", "test-webhook-session")
result = check_all_command_guards("sudo systemctl restart nginx", "local")
- # Should auto-approve (non-interactive, non-gateway path)
+ assert result["approved"] is False
+ assert "unattended platform" in result["message"]
+ assert "approvals.unattended_mode" in result["message"]
+
+ def test_webhook_dangerous_command_approves_when_opted_in(self, monkeypatch):
+ """approvals.unattended_mode: approve restores the old auto-approve path."""
+ import tools.approval as approval_mod
+ from tools.approval import check_all_command_guards
+
+ self._isolate(monkeypatch)
+ monkeypatch.delenv("HERMES_CRON_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
+ monkeypatch.setenv("HERMES_SESSION_PLATFORM", "webhook")
+ monkeypatch.setenv("HERMES_SESSION_KEY", "test-webhook-session")
+ monkeypatch.setattr(
+ approval_mod, "_get_unattended_approval_mode", lambda: "approve"
+ )
+
+ result = check_all_command_guards("sudo systemctl restart nginx", "local")
assert result["approved"] is True
+ def test_webhook_safe_command_still_approves(self, monkeypatch):
+ """Non-dangerous commands on unattended platforms are unaffected."""
+ from tools.approval import check_all_command_guards
+
+ monkeypatch.delenv("HERMES_CRON_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
+ monkeypatch.setenv("HERMES_SESSION_PLATFORM", "webhook")
+ monkeypatch.setenv("HERMES_SESSION_KEY", "test-webhook-session")
+
+ result = check_all_command_guards("ls -la /tmp", "local")
+ assert result["approved"] is True
+
+ def test_api_server_dangerous_command_denies_by_default(self, monkeypatch):
+ """api_server sessions get the same instant deny (#87509)."""
+ from tools.approval import check_all_command_guards
+
+ self._isolate(monkeypatch)
+ monkeypatch.delenv("HERMES_CRON_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
+ monkeypatch.setenv("HERMES_SESSION_PLATFORM", "api_server")
+ monkeypatch.setenv("HERMES_SESSION_KEY", "test-api-session")
+
+ result = check_all_command_guards("sudo systemctl restart nginx", "local")
+ assert result["approved"] is False
+ assert "api_server" in result["message"]
+
+ def test_execute_code_denied_on_unattended_platform(self, monkeypatch):
+ """execute_code is denied instantly on unattended platforms (parity with cron)."""
+ from tools.approval import check_execute_code_guard
+
+ self._isolate(monkeypatch)
+ monkeypatch.delenv("HERMES_CRON_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_GATEWAY_SESSION", raising=False)
+ monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
+ monkeypatch.delenv("HERMES_EXEC_ASK", raising=False)
+ monkeypatch.setenv("HERMES_SESSION_PLATFORM", "webhook")
+ monkeypatch.setenv("HERMES_SESSION_KEY", "test-webhook-session")
+
+ result = check_execute_code_guard("import os", "local")
+ assert result["approved"] is False
+ assert "approvals.unattended_mode" in result["message"]
+
class TestNormalizationBypass:
"""Obfuscation techniques must not bypass dangerous command detection."""
diff --git a/tools/approval.py b/tools/approval.py
index b0e6661e5cb..c84730f4117 100644
--- a/tools/approval.py
+++ b/tools/approval.py
@@ -265,6 +265,32 @@ def _is_cron_approval_context() -> bool:
return env_var_enabled("HERMES_CRON_SESSION")
+#: Gateway platforms that are programmatic/unattended: no human is on the
+#: other end to answer an approval prompt, and the adapter has no
+#: ``send_exec_approval`` / ``/approve`` surface. Approval decisions for
+#: these sessions are governed by ``approvals.unattended_mode`` config
+#: (default deny), mirroring ``approvals.cron_mode`` — never by an
+#: interactive round-trip that would block for the full approval timeout
+#: with nobody to answer (#37284, #87509).
+_UNATTENDED_APPROVAL_PLATFORMS = frozenset({
+ "webhook",
+ "msgraph_webhook",
+ "api_server",
+})
+
+
+def _is_unattended_platform_approval_context() -> bool:
+ """True when the session platform is a programmatic/unattended surface.
+
+ Webhook, msgraph_webhook, and api_server sessions bind
+ ``HERMES_SESSION_PLATFORM`` like chat gateways do, but there is no human
+ who can resolve a pending approval. Treating them as gateway approval
+ contexts blocks the session for the full approval timeout (60-300s) and
+ then fails closed anyway — the deadlock in #37284/#87509.
+ """
+ return _get_session_platform() in _UNATTENDED_APPROVAL_PLATFORMS
+
+
def _is_single_query_approval_context() -> bool:
"""True when the current approval decision is from a single-query (-q) session.
@@ -304,22 +330,21 @@ def _is_gateway_approval_context() -> bool:
fall through to the gateway branch would submit a pending approval
with no listener and block the job indefinitely.
- Webhook sessions are excluded for the same reason: the webhook adapter
- has no ``send_exec_approval`` and no way to receive ``/approve``
- replies. Submitting a pending approval in a webhook context blocks
- the session for the full approval timeout (60-300 s) with no human
- who can resolve it. Webhook dangerous-command handling falls through
- to the non-interactive path (auto-approve with warning, or deny if
- running inside a cron context).
+ Unattended programmatic platforms (webhook, msgraph_webhook, api_server)
+ are excluded for the same reason: those adapters have no
+ ``send_exec_approval`` and no way to receive ``/approve`` replies.
+ Submitting a pending approval there blocks the session for the full
+ approval timeout (60-300 s) with no human who can resolve it (#37284,
+ #87509). Their dangerous-command handling is governed by
+ ``approvals.unattended_mode`` config (default deny), mirroring cron.
"""
if _is_cron_approval_context():
return False
- platform = _get_session_platform()
- if platform == "webhook":
+ if _is_unattended_platform_approval_context():
return False
if env_var_enabled("HERMES_GATEWAY_SESSION"):
return True
- return bool(platform)
+ return bool(_get_session_platform())
def _resolve_cli_approval_callback(approval_callback=None):
@@ -3522,6 +3547,25 @@ def _get_single_query_approval_mode() -> str:
return "deny"
+def _get_unattended_approval_mode() -> str:
+ """Read the unattended-platform approval mode from config.
+
+ Governs webhook / msgraph_webhook / api_server sessions (the
+ ``_UNATTENDED_APPROVAL_PLATFORMS`` set). Returns 'deny' or 'approve';
+ default deny — an unattended programmatic session should never silently
+ run a flagged action unless the operator explicitly trusts it.
+ """
+ try:
+ from hermes_cli.config import load_config_readonly
+ config = load_config_readonly()
+ mode = str(cfg_get(config, "approvals", "unattended_mode", default="deny")).lower().strip()
+ if mode in {"approve", "off", "allow", "yes"}:
+ return "approve"
+ return "deny"
+ except Exception:
+ return "deny"
+
+
def _strip_shell_comments(command: str) -> str:
"""Strip shell-style comments from a command before LLM assessment.
@@ -3711,6 +3755,7 @@ def _run_approval_gate(
approval_callback=None,
cron_deny_message: str,
single_query_deny_message: str,
+ unattended_deny_message: str = "",
autoapprove_log_prefix: str,
fail_closed_when_no_human: bool = False,
no_human_block_message: str = "",
@@ -3810,6 +3855,26 @@ def _run_approval_gate(
"description": description,
}
# cron_mode: approve — fall through to auto-approve below.
+ elif _is_unattended_platform_approval_context():
+ # Unattended programmatic platforms (webhook/msgraph_webhook/
+ # api_server): respect unattended_mode config. Resolves instantly
+ # — never a pending approval nobody can answer (#37284, #87509).
+ if _get_unattended_approval_mode() == "deny":
+ return {
+ "approved": False,
+ "message": unattended_deny_message or (
+ f"BLOCKED: approval required ({description}) but this "
+ "session runs on an unattended platform "
+ f"({_get_session_platform()}) with no user present to "
+ "approve it. Find an alternative approach that avoids "
+ "this action. To allow flagged actions on unattended "
+ "platforms, set approvals.unattended_mode: approve in "
+ "config.yaml."
+ ),
+ "pattern_key": pattern_key,
+ "description": description,
+ }
+ # unattended_mode: approve — fall through to auto-approve below.
elif fail_closed_when_no_human:
# Non-cron, non-interactive, no gateway: no human can answer.
# The plugin-escalation path opts in to fail-closed here so a
@@ -4859,6 +4924,66 @@ def check_all_command_guards(command: str, env_type: str,
),
}
# else: tirith_fail_open is True — allow as before
+ # Unattended programmatic platforms (webhook/msgraph_webhook/
+ # api_server): respect unattended_mode config (#37284, #87509).
+ # Mirrors the cron branch above, tirith parity included.
+ if _is_unattended_platform_approval_context() and not _is_cron_approval_context():
+ if _get_unattended_approval_mode() == "deny":
+ _ua_platform = _get_session_platform()
+ is_dangerous, _pk, description = detect_dangerous_command(command)
+ if is_dangerous:
+ return {
+ "approved": False,
+ "message": (
+ f"BLOCKED: Command flagged as dangerous ({description}) "
+ f"but this session runs on an unattended platform "
+ f"({_ua_platform}) with no user present to approve it. "
+ "Find an alternative approach that avoids this command. "
+ "To allow dangerous commands on unattended platforms, "
+ "set approvals.unattended_mode: approve in config.yaml."
+ ),
+ }
+ # Tirith parity with the cron branch: content-level threats
+ # are caught even when pattern detection misses.
+ try:
+ from tools.tirith_security import check_command_security
+ _ua_tirith = check_command_security(command)
+ if _ua_tirith.get("action") in ("block", "warn"):
+ _ua_desc = _format_tirith_description(_ua_tirith)
+ return {
+ "approved": False,
+ "message": (
+ f"BLOCKED: {_ua_desc} "
+ f"but this session runs on an unattended platform "
+ f"({_ua_platform}) with no user present to approve it. "
+ "Find an alternative approach that avoids this command. "
+ "To allow dangerous commands on unattended platforms, "
+ "set approvals.unattended_mode: approve in config.yaml."
+ ),
+ }
+ except ImportError:
+ _ua_fail_open = True # safe default if config is unreadable
+ try:
+ from hermes_cli.config import load_config_readonly as _load_cfg
+ _sec = (_load_cfg() or {}).get("security", {}) or {}
+ if _sec.get("tirith_enabled", True):
+ _ua_fail_open = _sec.get("tirith_fail_open", True)
+ except Exception:
+ pass
+ if not _ua_fail_open:
+ return {
+ "approved": False,
+ "message": (
+ "BLOCKED: the Tirith security scanner could not be "
+ "imported and security.tirith_fail_open is false, "
+ "so this command cannot be silently allowed — and "
+ f"this session runs on an unattended platform "
+ f"({_ua_platform}) with no user present to approve it. "
+ "Find an alternative approach, install tirith, or set "
+ "approvals.unattended_mode: approve in config.yaml."
+ ),
+ }
+ # else: tirith_fail_open is True — allow as before
return {"approved": True, "message": None}
# --- Phase 1: Gather findings from both checks ---
@@ -5388,6 +5513,29 @@ def check_execute_code_guard(code: str, env_type: str,
}
return {"approved": True, "message": None}
+ # Unattended programmatic platforms (webhook/msgraph_webhook/api_server):
+ # no user is present to approve arbitrary code either. Mirrors the cron
+ # branch above; governed by approvals.unattended_mode (#37284, #87509).
+ if _is_unattended_platform_approval_context():
+ if _get_unattended_approval_mode() == "deny":
+ return {
+ "approved": False,
+ "message": (
+ "BLOCKED: execute_code runs arbitrary local Python "
+ "(including subprocess calls that bypass shell-string "
+ "approval checks). This session runs on an unattended "
+ f"platform ({_get_session_platform()}) with no user "
+ "present to approve it. Use normal tools instead, or set "
+ "approvals.unattended_mode: approve only if sessions on "
+ "this surface are intentionally trusted."
+ ),
+ "pattern_key": pattern_key,
+ "description": description,
+ "outcome": "blocked",
+ "user_consent": False,
+ }
+ return {"approved": True, "message": None}
+
# Only gateway/ask contexts get the one-shot whole-script approval.
# * CLI interactive: the script's terminal() calls are guarded per-call
# (context now propagates into the RPC thread, #33057); a whole-script
diff --git a/website/docs/user-guide/security.md b/website/docs/user-guide/security.md
index e63199af0b5..4397fcac6bb 100644
--- a/website/docs/user-guide/security.md
+++ b/website/docs/user-guide/security.md
@@ -35,6 +35,7 @@ approvals:
timeout: 300 # seconds to wait for user response (default: 300)
cron_mode: deny # deny | approve — what cron jobs do when they hit a dangerous command
single_query_mode: deny # deny | approve — what single-query (-q) sessions do on a dangerous command
+ unattended_mode: deny # deny | approve — what webhook/API sessions do on a dangerous command
mcp_reload_confirm: true # /reload-mcp asks before invalidating the MCP tool cache
destructive_slash_confirm: true # /clear, /new, /reset, /undo prompt before discarding state
```
@@ -47,6 +48,7 @@ The full set of keys:
| `timeout` | `300` | Seconds Hermes waits for an approval reply before timing out. |
| `cron_mode` | `deny` | How [cron jobs](./features/cron.md) behave headlessly when they trigger a dangerous-command prompt. `deny` blocks the command (the agent must find another path); `approve` auto-approves everything in cron context. |
| `single_query_mode` | `deny` | How one-shot [`hermes chat -q`](./cli.md) sessions behave when they trigger a dangerous-command prompt. A `-q` session runs a single turn and exits with no user waiting to answer prompts; `deny` blocks the command (the agent must find another path), `approve` auto-approves everything in single-query context. Mirrors `cron_mode`. |
+| `unattended_mode` | `deny` | How sessions on unattended programmatic platforms (webhook, msgraph_webhook, api_server) behave when they trigger a dangerous-command prompt. These surfaces have no human who can answer `/approve`, so instead of blocking for the full approval timeout, `deny` blocks the command instantly (the agent must find another path) and `approve` auto-approves everything in unattended context. Mirrors `cron_mode`. |
| `mcp_reload_confirm` | `true` | When true, `/reload-mcp` asks before rebuilding the MCP tool set. Rebuilding invalidates the provider prompt cache (tool schemas live in the system prompt), so the next message re-sends full input tokens. Users who click **Always Approve** flip this key to `false`. |
| `destructive_slash_confirm` | `true` | When true, destructive session slash commands (`/clear`, `/new`, `/reset`, `/undo`) prompt before discarding conversation state. Three-option dialog (Approve Once / Always Approve / Cancel) routed through native yes/no buttons on Telegram, Discord, and Slack; text fallback elsewhere. Users who click **Always Approve** flip this key to `false`. The TUI also honors this setting for its `/clear`, `/new`, and `/reset` modal; `HERMES_TUI_NO_CONFIRM=1` force-skips that modal regardless of the configured value. |