The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): read the Portal env override through the profile scope
kshitijk4poor9366f595330d
diff --git a/hermes_cli/auth_nous.py b/hermes_cli/auth_nous.pyindex c5320b8264f..cf7567bbcb0 100644--- a/hermes_cli/auth_nous.py+++ b/hermes_cli/auth_nous.py@@ -157,11 +157,18 @@ def _nous_portal_env_override() -> Optional[str]:Documented dev/staging escape hatch (e.g. hosted agents on the staging Portal). Trusted envsource: must NOT be gated by ``_NOUS_PORTAL_ALLOWED_HOSTS``, which rejects untrusted- NETWORK-provided values persisted to auth.json, not operator config.+ NETWORK-provided values persisted to auth.json, not operator config. Read through the+ profile secret scope like ``_nous_inference_env_override``: it is reached on every routed+ turn (``_nous_effective_routing``), and a raw environ read would POST a multiplexed+ secondary's refresh token to the DEFAULT profile's Portal."""from hermes_cli.auth import _optional_base_url- return _optional_base_url(- os.getenv("HERMES_PORTAL_BASE_URL") or os.getenv("NOUS_PORTAL_BASE_URL"))+ from agent.secret_scope import UnscopedSecretError, get_secret+ try:+ override = get_secret("HERMES_PORTAL_BASE_URL") or get_secret("NOUS_PORTAL_BASE_URL")+ except UnscopedSecretError:+ override = os.getenv("HERMES_PORTAL_BASE_URL") or os.getenv("NOUS_PORTAL_BASE_URL") # unscoped default-profile/CLI path: environ IS its own value+ return _optional_base_url(override)def _scope_values(raw_scope: Any) -> set[str]:@@ -793,9 +800,7 @@ def _nous_effective_routing(state: Dict[str, Any]) -> tuple[str, str, str, str]:layers the runtime-only ``NOUS_INFERENCE_BASE_URL`` override on top and is never persisted."""from hermes_cli.auth import _NOUS_PORTAL_ALLOWED_HOSTS, _optional_base_url- portal_url = (- _optional_base_url(state.get("portal_base_url")) or os.getenv("HERMES_PORTAL_BASE_URL")- or os.getenv("NOUS_PORTAL_BASE_URL") or DEFAULT_NOUS_PORTAL_URL).rstrip("/")+ portal_url = (_optional_base_url(state.get("portal_base_url")) or DEFAULT_NOUS_PORTAL_URL).rstrip("/")# A persisted/stale portal_base_url is where the refresh token gets POSTed — reject any host# outside the allowlist so a poisoned value can't exfiltrate the bearer, healing to the# default. Trusted operator env overrides bypass this network-value gate.diff --git a/tests/hermes_cli/test_nous_nonproduction_inference_host.py b/tests/hermes_cli/test_nous_nonproduction_inference_host.pynew file mode 100644index 00000000000..276c7a895e5--- /dev/null+++ b/tests/hermes_cli/test_nous_nonproduction_inference_host.py@@ -0,0 +1,47 @@+"""Nous inference-host validation for operators pointed at a non-production Portal.++Portal-returned inference URLs go through a host allowlist before the user's bearer is sent+there. The Portal override (``HERMES_PORTAL_BASE_URL``) is a per-profile ``.env`` value, so it+is read through the profile secret scope; and when that trusted override names a Portal outside+the production allowlist, the Portal's own inference host is accepted as long as it is a Nous+host — instead of being refused and healed onto the production gateway, which 401s a token the+production Portal never issued. No environment is named in code: the rule is "operator-trusted+non-production Portal ⇒ any ``*.nousresearch.com`` inference host", nothing narrower.+"""+from __future__ import annotations++import pytest++from hermes_cli import auth_nous++PROD_PORTAL = "https://portal.nousresearch.com"+NONPROD_PORTAL = "https://portal.example-env.nousresearch.com"+PROD_INFERENCE = "https://inference-api.nousresearch.com/v1"+NONPROD_INFERENCE = "https://inference.example-env.nousresearch.com/v1"+++def test_portal_env_override_is_read_through_the_profile_scope(monkeypatch):+ """Under multiplexing a routed turn resolves the Portal override from its own profile scope:+ the scoped value wins over the process env and a scoped miss stays a miss (the default+ profile's Portal is never borrowed). Unscoped (CLI / multiplex off) keeps reading the+ environment — the contract ``_nous_inference_env_override`` already has."""+ from agent import secret_scope as ss++ monkeypatch.setenv("HERMES_PORTAL_BASE_URL", NONPROD_PORTAL)+ monkeypatch.delenv("NOUS_PORTAL_BASE_URL", raising=False)+ assert auth_nous._nous_portal_env_override() == NONPROD_PORTAL # unscoped: environ++ ss.set_multiplex_active(True)+ try:+ token = ss.set_secret_scope({"HERMES_PORTAL_BASE_URL": "https://portal.other.example"})+ try:+ assert auth_nous._nous_portal_env_override() == "https://portal.other.example"+ finally:+ ss.reset_secret_scope(token)+ token = ss.set_secret_scope({})+ try:+ assert auth_nous._nous_portal_env_override() is None, "scoped miss must not read environ"+ finally:+ ss.reset_secret_scope(token)+ finally:+ ss.set_multiplex_active(False)