The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(review): validate the logsRoot owner name; scope the whole palette and fail 4064 on an unknown profile
teknium1485979ddf4fa
diff --git a/apps/desktop/electron/fs-ipc.test.ts b/apps/desktop/electron/fs-ipc.test.tsindex eb09acc9a3c..76f33cec01e 100644--- a/apps/desktop/electron/fs-ipc.test.ts+++ b/apps/desktop/electron/fs-ipc.test.ts@@ -95,4 +95,16 @@ describe('hermes:fs:logsRoot', () => {it('falls back to the active Desktop profile when no owner is named', async () => {await expect(logsRoot()).resolves.toBe(path.join(scratch, 'profiles', 'launch-profile', 'logs'))})++ // The owner is renderer data (from a remote backend in remote mode): a+ // traversal or absolute value must never leave hermesHome, let alone be+ // created and revealed. Bad names route like an unnamed owner.+ it('never leaves hermesHome for an owner that is not a profile name', async () => {+ for (const bad of ['../../x', '/etc', 'a/b', 'Upper', '.hidden']) {+ const root = (await logsRoot(bad)) as string++ expect(path.relative(scratch, root).startsWith('..')).toBe(false)+ expect(root).toBe(path.join(scratch, 'profiles', 'launch-profile', 'logs'))+ }+ })})diff --git a/apps/desktop/electron/fs-ipc.ts b/apps/desktop/electron/fs-ipc.tsindex 9e44d17328c..9a4cb972130 100644--- a/apps/desktop/electron/fs-ipc.ts+++ b/apps/desktop/electron/fs-ipc.ts@@ -15,6 +15,7 @@ import {migrateProfileScopedDesktopPlugins,reconcileUnifiedDesktopHalves} from './desktop-plugins-root'+import { DESKTOP_PROFILE_NAME_RE } from './desktop-profile'import { readDirForIpc } from './fs-read-dir'import { gitRootForIpc } from './git-root'@@ -98,9 +99,15 @@ export function registerFsIpc({// so it stays valid in every connection mode. Created on demand, like openDir.// Profile-scoped roots (agent plugins, logs) live under profiles/<name>/ for a// named Desktop profile — they belong to THAT agent. 'default'/unset pins the- // global root.+ // global root. The owner is renderer-supplied (in remote mode it comes from+ // the remote backend's session record), so only a profile NAME may reach the+ // join: anything else would escape profiles/ and be created + revealed.async function localPluginsRoot(dirName: string, owner?: unknown): Promise<string> {- const profile = (typeof owner === 'string' && owner.trim()) || readActiveDesktopProfile()+ const named = typeof owner === 'string' ? owner.trim() : ''++ const profile =+ named && (named === 'default' || DESKTOP_PROFILE_NAME_RE.test(named)) ? named : readActiveDesktopProfile()+const base = profile && profile !== 'default' ? path.join(hermesHome, 'profiles', profile) : hermesHomereturn ensureDir(path.join(base, dirName))diff --git a/tests/hermes_cli/test_resume_model_restore.py b/tests/hermes_cli/test_resume_model_restore.pyindex 4f919a49131..101f7ce6108 100644--- a/tests/hermes_cli/test_resume_model_restore.py+++ b/tests/hermes_cli/test_resume_model_restore.py@@ -417,6 +417,18 @@ def test_session_gateway_runtime_explicit_provider_wins_over_billing():assert runtime == {"provider": "nous"}+def test_session_gateway_runtime_billing_provider_fills_top_level_route_without_provider():+ """A TUI row with top-level base_url/api_mode but no provider keeps that endpoint AND takes the+ provider the session was billed to — the same merge the TUI gateway always did (#125942); a bare+ bucket still contributes nothing."""+ meta = _row(model_config={"base_url": "https://f/v1", "api_mode": "chat_completions"})+ meta["billing_provider"] = "minimax"+ assert SessionDB.session_gateway_runtime(meta) == {+ "provider": "minimax", "base_url": "https://f/v1", "api_mode": "chat_completions"}+ meta["billing_provider"] = "custom"+ assert SessionDB.session_gateway_runtime(meta) == {"base_url": "https://f/v1", "api_mode": "chat_completions"}++def test_restore_session_model_restores_billing_provider_fallback():"""End-to-end: _restore_session_model uses billing_provider fallback."""stub = _make_stub()diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex 87852708a9c..a6355f23208 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -1265,7 +1265,9 @@ def test_slash_exec_scopes_skill_lookup_to_session_profile(server, tmp_path):def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monkeypatch):"""A Desktop draft has no session yet: ``commands.catalog`` / ``complete.slash`` must scan the- named ``profile``'s home, not the launch profile's — A→B→A under multiplexing (#124651)."""+ named ``profile``'s home, not the launch profile's — A→B→A under multiplexing (#124651). The+ palette's quick_commands are that profile's too, and an unknown profile is 4064, not a+ launch-profile palette."""import agent.skill_commands as sc_modfrom agent.secret_scope import is_multiplex_active, set_multiplex_active@@ -1276,7 +1278,8 @@ def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monke(skill_dir / "SKILL.md").write_text(f"---\nname: {name}-only\ndescription: Only in {name}.\n---\n\n# x\n")(root / "profiles" / name).mkdir(parents=True)(root / "profiles" / name / "config.yaml").write_text(- f"skills:\n external_dirs:\n - {skill_dir.parent}\n")+ f"skills:\n external_dirs:\n - {skill_dir.parent}\n"+ f"quick_commands:\n {name}-qc:\n type: exec\n command: echo {name}\n")monkeypatch.setenv("HERMES_HOME", str(root))monkeypatch.setattr(server, "_hermes_home", str(root))@@ -1285,7 +1288,8 @@ def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monketyped = server.handle_request({"id": "r2", "method": "complete.slash", "params": {"text": "/s6probe", "profile": profile}})assert "result" in catalog and "result" in typed, (catalog, typed)- return set(catalog["result"]["skills"]), {item["text"].strip("/") for item in typed["result"]["items"]}+ quick = {key for key, _ in catalog["result"]["pairs"] if key.endswith("-qc")}+ return set(catalog["result"]["skills"]), {item["text"].strip("/") for item in typed["result"]["items"]}, quickprevious = is_multiplex_active()set_multiplex_active(True)@@ -1296,9 +1300,12 @@ def test_sessionless_slash_palette_follows_profile_param(server, tmp_path, monkepatch.object(sc_mod, "_skill_commands_platform", None),patch.object(sc_mod, "_skill_commands_home", None),):- assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"})- assert palette("s6probe-b") == ({"/s6probe-b-only"}, {"s6probe-b-only"})- assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"})+ assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"}, {"/s6probe-a-qc"})+ assert palette("s6probe-b") == ({"/s6probe-b-only"}, {"s6probe-b-only"}, {"/s6probe-b-qc"})+ assert palette("s6probe-a") == ({"/s6probe-a-only"}, {"s6probe-a-only"}, {"/s6probe-a-qc"})+ for method in ("commands.catalog", "skills.reload"):+ bad = server.handle_request({"id": "r3", "method": method, "params": {"profile": "../x"}})+ assert bad.get("error", {}).get("code") == 4064, (method, bad)finally:set_multiplex_active(previous)diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex 2e3d02a40f2..04de37b13aa 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -66,6 +66,8 @@ def _profile_scoped_rpc(try:with scope:return body(*args)+ except ProfileUnavailableError:+ raise # a body that binds ``profile`` itself (_session_home_scope) reports 4064 via dispatchexcept Exception as e:return _err(rid, fail_code, f"{prefix}{e}")handler.__doc__ = body.__doc__@@ -488,29 +490,31 @@ def _catalog_skills(cat: _Catalog, skills: dict[str, dict]) -> str:def _(rid, params: dict) -> dict:"""Registry-backed slash metadata, categorized, no aliases. Discovery failures land in ``warning``(skills' message wins, then quick commands', then plugins'); only with no failure does it carry- the built-in-name collision notice for skills that have no ``/<name>`` (empty when none). Skill- discovery is bound to the calling session's profile and workspace (``_completion_cwd``: its record,- else the cwd a new session would be seeded with) so project-local skills register for the repo the- session is actually in (#114359); a session-less draft is bound to ``params['profile']`` (#124651)."""+ the built-in-name collision notice for skills that have no ``/<name>`` (empty when none). Quick+ command, plugin command and skill discovery are all home-keyed, so every loader runs bound to the+ calling session's profile and workspace (``_completion_cwd``: its record, else the cwd a new+ session would be seeded with) so project-local skills register for the repo the session is+ actually in (#114359); a session-less draft is bound to ``params['profile']`` (#124651), and an+ unknown profile is 4064 like ``complete.slash`` — never a launch-profile palette."""cat = _Catalog()_catalog_registry(cat)warning = ""- try:- _catalog_quick_commands(cat)- except Exception as e:- warning = f"quick_commands discovery unavailable: {e}"- try:- _catalog_plugin_commands(cat)- except Exception as e:- warning = warning or f"plugin command discovery unavailable: {e}"skills: dict[str, dict] = {}- try:- with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params),- profile=params.get("profile")):+ with _session_home_scope(_sessions.get(params.get("session_id", "")), cwd=_completion_cwd(params),+ profile=params.get("profile")):+ try:+ _catalog_quick_commands(cat)+ except Exception as e:+ warning = f"quick_commands discovery unavailable: {e}"+ try:+ _catalog_plugin_commands(cat)+ except Exception as e:+ warning = warning or f"plugin command discovery unavailable: {e}"+ try:collision_note = _catalog_skills(cat, skills) # always runs: skills must list even when a loader failed- warning = warning or collision_note- except Exception as e:- warning = f"skill discovery unavailable: {e}"+ warning = warning or collision_note+ except Exception as e:+ warning = f"skill discovery unavailable: {e}"return _ok(rid, {"pairs": cat.pairs, "sub": {k: v[:] for k, v in _tools_mod("hermes_cli.commands").SUBCOMMANDS.items()},"canon": cat.canon,