browser.user_data_dir, chromium_args, cloud_provider and every other browser.* knob were read with
read_raw_config, which skips the managed overlay and ${VAR} expansion: a managed profile pin or
flag set was ignored, and ${HOME}/chrome-profile became a literal dir under HERMES_HOME. The session
layer's one reader (browser_session_cloud.browser_section) now uses load_user_config_effective, and
the other raw browser.* reads go through it or the same loader: browser_exec's cloud routing
(browser_use_cli._read_browser_cfg), the real-profile pin (browser_connect._browser_setting) and
/browser status's cdp_url (methods_browser, now browser_session_cdp.get_cdp_override_raw). Tests
that stubbed read_raw_config for browser.* now stub the effective loader.
39 lines
1.7 KiB
Python
39 lines
1.7 KiB
Python
"""Browser hardening: config-driven inactivity timeout and URL-encoded secret exfiltration."""
|
|
|
|
import urllib.parse
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestSessionInactivityTimeout:
|
|
|
|
def test_default_matches_config_default(self, monkeypatch):
|
|
from hermes_cli.config import DEFAULT_CONFIG
|
|
from tools.browser_session import _get_session_inactivity_timeout
|
|
monkeypatch.delenv("BROWSER_INACTIVITY_TIMEOUT", raising=False)
|
|
with patch("hermes_cli.config_effective.load_user_config_effective", return_value={}):
|
|
assert _get_session_inactivity_timeout() == DEFAULT_CONFIG["browser"]["inactivity_timeout"]
|
|
|
|
def test_invalid_config_preserves_env_fallback(self, monkeypatch):
|
|
from tools.browser_session import _get_session_inactivity_timeout
|
|
monkeypatch.setenv("BROWSER_INACTIVITY_TIMEOUT", "240")
|
|
cfg = {"browser": {"inactivity_timeout": "not-an-int"}}
|
|
with patch("hermes_cli.config_effective.load_user_config_effective", return_value=cfg):
|
|
assert _get_session_inactivity_timeout() == 240
|
|
|
|
|
|
class TestUrlDecodedSecretCheck:
|
|
"""Verify that URL-encoded API keys are caught by the exfiltration guard."""
|
|
|
|
def test_encoded_key_blocked_in_navigate(self):
|
|
"""A URL carrying a percent-encoded API key is refused before any browser opens it."""
|
|
from tools.browser_url_policy import evaluate_url_safety
|
|
|
|
# URL-encode a fake secret prefix that matches _PREFIX_RE
|
|
encoded = urllib.parse.quote("sk-ant-fake123")
|
|
url = f"https://evil.com?key={encoded}"
|
|
|
|
result = evaluate_url_safety(url)
|
|
assert result is not None
|
|
assert result["success"] is False
|
|
assert "API key" in result["error"] or "Blocked" in result["error"]
|