fix(dashboard): scope cron listing and @-mentions to the isolated launch profile
GET /api/cron/jobs (all) and @profile completion still enumerated every profile on an isolated named-profile serve; filter them through scope_to_launch_profile like the other listings. _cron_profile_dicts() stays unscoped: the external-provider fail-closed count and job-id resolution must see every profile. SECURITY.md §3.2 gains the sibling-profile bullet §2.6 refers reporters to. Co-authored-by: BearHuddleston <bear@bearhuddleston.dev>
This commit is contained in:
@@ -283,6 +283,11 @@ private-disclosure channel and don't receive advisories.
|
||||
isolation that only sandboxes shell; reports whose preconditions
|
||||
require pre-existing write access to operator-owned configuration
|
||||
or credential files (those are already inside the trust envelope).
|
||||
- **Sibling-profile reach from a dashboard/`serve` caller.** Profiles
|
||||
under one OS user share one trust envelope (§2.6 rule 4); an
|
||||
`--isolated` server or a `?profile=` selector reaching a sibling
|
||||
profile's files is not a vulnerability. Separate users need separate
|
||||
OS users or containers (§2.2).
|
||||
- **Documented break-glass settings.** Operator-selected trade-offs
|
||||
that explicitly disable protections: `--insecure` and equivalent
|
||||
flags on the dashboard or other components, disabled approvals,
|
||||
|
||||
@@ -20,6 +20,7 @@ from fastapi.responses import JSONResponse
|
||||
|
||||
from hermes_cli.web_deps import late
|
||||
from hermes_cli.config import cfg_get
|
||||
from hermes_cli.isolated_scope import scope_to_launch_profile
|
||||
from hermes_cli.web_server_cron import (
|
||||
_create_cron_job_sync, _cron_optional_text, _cron_string_list, _mutate_cron_for_profile, _normalize_dashboard_cron_script, _raise_if_cron_registration_error, _run_cron_dashboard_io, _validate_dashboard_cron_context_from, _validate_dashboard_cron_effective_job,
|
||||
)
|
||||
@@ -125,7 +126,7 @@ def _list_cron_jobs_sync(profile: str = "all"):
|
||||
# then resolve duplicates by id with default-profile priority, rather than
|
||||
# keeping whichever copy happened to be seen first during the profile loop.
|
||||
all_jobs: list[dict[str, Any]] = []
|
||||
for item in _cron_profile_dicts():
|
||||
for item in scope_to_launch_profile(_cron_profile_dicts(), lambda row: row.get("name")):
|
||||
name = str(item.get("name") or "")
|
||||
if not name:
|
||||
continue
|
||||
|
||||
@@ -52,6 +52,17 @@ def _seed(home, session_id):
|
||||
db.close()
|
||||
|
||||
|
||||
def _seed_cron(home, job_id):
|
||||
(home / "cron").mkdir(exist_ok=True)
|
||||
job = {"id": job_id, "name": job_id, "prompt": "hi", "enabled": True,
|
||||
"schedule": {"kind": "interval", "minutes": 60, "display": "every 60m"}}
|
||||
(home / "cron" / "jobs.json").write_text(json.dumps({"jobs": [job]}), encoding="utf-8")
|
||||
|
||||
|
||||
def _cron_ids(client):
|
||||
return {job["id"] for job in client.get("/api/cron/jobs").json()}
|
||||
|
||||
|
||||
def _launch_in(monkeypatch, home, *, isolated=True, desktop_owned=False):
|
||||
monkeypatch.setenv("HERMES_HOME", str(home))
|
||||
return isolated_scope.record_launch_scope(isolated=isolated, desktop_owned=desktop_owned)
|
||||
@@ -76,6 +87,8 @@ def _sidebar_ids(client):
|
||||
def test_isolated_named_profile_lists_only_itself(client, homes, monkeypatch):
|
||||
_seed(homes["default"], "default-chat")
|
||||
_seed(homes["worker"], "worker-chat")
|
||||
_seed_cron(homes["default"], "default-job")
|
||||
_seed_cron(homes["worker"], "worker-job")
|
||||
assert _launch_in(monkeypatch, homes["worker"]) == "worker"
|
||||
|
||||
assert [p["name"] for p in client.get("/api/profiles").json()["profiles"]] == ["worker"]
|
||||
@@ -83,11 +96,14 @@ def test_isolated_named_profile_lists_only_itself(client, homes, monkeypatch):
|
||||
assert status["profiles"] == ["worker"]
|
||||
assert status["isolated_profile"] == "worker"
|
||||
assert _sidebar_ids(client) == {"worker-chat"}
|
||||
assert _cron_ids(client) == {"worker-job"}
|
||||
|
||||
import tui_gateway.server as srv
|
||||
from tui_gateway.methods_complete import _profile_mention_items
|
||||
|
||||
rows = srv._methods["profiles.list"](1, {"include_sessions": False})["result"]["profiles"]
|
||||
assert [row["name"] for row in rows] == ["worker"]
|
||||
assert [item["text"] for item in _profile_mention_items("")] == ["@worker"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("launch", [
|
||||
@@ -97,11 +113,16 @@ def test_isolated_named_profile_lists_only_itself(client, homes, monkeypatch):
|
||||
def test_unscoped_backends_still_list_every_profile(client, homes, monkeypatch, launch):
|
||||
_seed(homes["default"], "default-chat")
|
||||
_seed(homes["worker"], "worker-chat")
|
||||
_seed_cron(homes["default"], "default-job")
|
||||
_seed_cron(homes["worker"], "worker-job")
|
||||
assert _launch_in(monkeypatch, homes["worker"], **launch) is None
|
||||
|
||||
assert {p["name"] for p in client.get("/api/profiles").json()["profiles"]} == {"default", "worker"}
|
||||
assert client.get("/api/status").json()["isolated_profile"] is None
|
||||
assert _sidebar_ids(client) == {"default-chat", "worker-chat"}
|
||||
assert _cron_ids(client) == {"default-job", "worker-job"}
|
||||
from tui_gateway.methods_complete import _profile_mention_items
|
||||
assert {item["text"] for item in _profile_mention_items("")} == {"@default", "@worker", "@hermes"}
|
||||
|
||||
|
||||
def test_isolated_root_home_stays_unscoped(homes, monkeypatch):
|
||||
|
||||
@@ -57,16 +57,17 @@ def _profile_mention_items(prefix: str) -> list[dict]:
|
||||
is also offered as 'hermes' when no real profile claims that name."""
|
||||
out: list[dict] = []
|
||||
try:
|
||||
from hermes_cli.isolated_scope import isolated_launch_profile, scope_to_launch_profile
|
||||
from hermes_cli.profiles import list_profiles
|
||||
seen: set[str] = set()
|
||||
# Per keystroke: only name/description are read, so never walk skill trees in-request (#114041).
|
||||
for p in list_profiles(lazy_skill_count=True):
|
||||
for p in scope_to_launch_profile(list_profiles(lazy_skill_count=True), lambda info: info.name):
|
||||
if not (name := (p.name or "").strip()):
|
||||
continue
|
||||
seen.add(name.lower())
|
||||
if name.lower().startswith(prefix.lower()):
|
||||
out.append(_item(f"@{name}", (getattr(p, "description", "") or "").strip() or "agent profile"))
|
||||
if "hermes".startswith(prefix.lower()) and "hermes" not in seen:
|
||||
if "hermes".startswith(prefix.lower()) and "hermes" not in seen and isolated_launch_profile() is None:
|
||||
out.append(_item("@hermes", "agent profile (primary)"))
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user