The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): follow symlinked desktop plugin folders like native Desktop
Adolaniumd276f0c0c18d
diff --git a/apps/desktop/src/contrib/runtime-loader.ts b/apps/desktop/src/contrib/runtime-loader.tsindex d1d17d2e5ff..c8a17280577 100644--- a/apps/desktop/src/contrib/runtime-loader.ts+++ b/apps/desktop/src/contrib/runtime-loader.ts@@ -27,7 +27,10 @@* and for catalog installs the trust comes from admission (human review of* an exact pinned SHA + the static lint in hermes_cli/plugin_validate_desktop.py),* not from this loader. The import allowlist below is the one runtime tripwire:- * a plugin cannot pull a second stage from a URL. A remote source (https ++ * a plugin cannot pull a second stage from a URL. The Webapp's HTTP door+ * (`/api/desktop-plugins/*`, browser-desktop-plugins.ts) counts as local: it is+ * same-origin, reads the serving host's own disk, and runs in a tab that holds no+ * more authority than that host already grants it. A remote source (https +* allowlist) must NOT reuse this pipeline as-is: it needs a real boundary* (iframe/worker + CSP + capability gating) before it can land.*/diff --git a/hermes_cli/web_routers/desktop_plugins.py b/hermes_cli/web_routers/desktop_plugins.pyindex cfc1f64d479..ae374204db6 100644--- a/hermes_cli/web_routers/desktop_plugins.py+++ b/hermes_cli/web_routers/desktop_plugins.py@@ -5,9 +5,10 @@ Native Desktop reads that folder from its own disk (``desktopPluginsRoot`` in Elbrowser bridge asks here instead, and the same runtime loader scans, loads and polls it.The routes answer only what the loader reads: the root, its plugin folders, and each folder's-``plugin.js`` and ``.hermes-package.json``, resolved through symlinks to inside the root. They never-go through ``/api/fs``, which follows the profile's SSH workspace and truncates at the preview cap.-Webapp only (``SurfacePolicy.desktop_plugins``; 404 elsewhere).+``plugin.js`` and ``.hermes-package.json``. Containment is checked on the path as written, then+symlinks are followed as Electron's ``readDir`` does, so ``desktop-plugins/foo -> ~/src/foo`` loads+here too. They never go through ``/api/fs``, which follows the profile's SSH workspace and truncates+at the preview cap. Webapp only (``SurfacePolicy.desktop_plugins``; 404 elsewhere)."""from __future__ import annotations@@ -37,14 +38,17 @@ def desktop_plugins_root() -> Path:def _inside_root(raw: str) -> tuple[Path, tuple[str, ...]]:- """*raw* resolved, and its parts below the root. Anything that resolves outside is a 404."""+ """*raw* and its parts below the root, judged as written: no ``..``, at most a folder and a file.+ Links are not resolved here; a linked plugin folder is followed like native Desktop follows it.+ The link buys nothing the tab cannot already reach through ``/api/fs`` or the host terminal."""root = desktop_plugins_root()try:- target = Path(raw).resolve(strict=True)- parts = target.relative_to(root).parts- except (OSError, RuntimeError, ValueError):+ parts = Path(raw).relative_to(root).parts+ except ValueError:raise HTTPException(status_code=404, detail="Not a desktop plugin path") from None- return target, parts+ if len(parts) > 2 or ".." in parts:+ raise HTTPException(status_code=404, detail="Not a desktop plugin path")+ return root.joinpath(*parts), partsdef _list(raw: str) -> dict:diff --git a/tests/hermes_cli/test_webapp_desktop_plugins.py b/tests/hermes_cli/test_webapp_desktop_plugins.pyindex 87517224ee3..f3a56bb8df3 100644--- a/tests/hermes_cli/test_webapp_desktop_plugins.py+++ b/tests/hermes_cli/test_webapp_desktop_plugins.py@@ -89,6 +89,29 @@ def test_webapp_reads_nothing_but_plugin_entries_and_markers(webapp, hermes_rootassert webapp.get("/api/desktop-plugins/list", params={"path": str(path)}).status_code == 404, path+def test_a_linked_plugin_folder_loads_like_native_desktop(webapp, hermes_root, tmp_path):+ # `desktop-plugins/foo -> ~/src/foo` is how plugins get developed; Electron follows the link.+ checkout = tmp_path / "src" / "foo"+ checkout.mkdir(parents=True)+ (checkout / "plugin.js").write_text("export default { id: 'foo' }", encoding="utf-8")+ (checkout / "notes.txt").write_text("private", encoding="utf-8")+ plugins = hermes_root / "desktop-plugins"+ plugins.mkdir()+ try:+ (plugins / "foo").symlink_to(checkout, target_is_directory=True)+ except OSError:+ pytest.skip("symlinks need privileges here")+ link = plugins.resolve() / "foo"++ listed = webapp.get("/api/desktop-plugins/list", params={"path": str(link)})+ assert listed.status_code == 200+ assert {e["name"] for e in listed.json()["entries"]} == {"plugin.js", "notes.txt"}+ read = webapp.get("/api/desktop-plugins/read", params={"path": str(link / "plugin.js")}).json()+ assert read["text"] == "export default { id: 'foo' }"+ # The link opens the folder, not the rest of the checkout's files.+ assert webapp.get("/api/desktop-plugins/read", params={"path": str(link / "notes.txt")}).status_code == 404++@pytest.mark.parametrize("surface", ["gateway", "dashboard", "serve"])def test_only_the_webapp_serves_desktop_plugins(monkeypatch, hermes_root, surface):_install(hermes_root, "notes", "export default {}")