The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(plugin-catalog): refuse desktop plugins that step outside the SDK surface
teknium172f55062d24d
diff --git a/hermes_cli/plugin_validate.py b/hermes_cli/plugin_validate.pyindex 77d1f04f7c6..47b5f0617ac 100644--- a/hermes_cli/plugin_validate.py+++ b/hermes_cli/plugin_validate.py@@ -23,6 +23,8 @@ from dataclasses import dataclass, fieldfrom pathlib import Pathfrom typing import Any, Dict, List, Optional, Tuple+from hermes_cli.plugin_validate_desktop import check_desktop_surface+_UPPER_SNAKE_RE = re.compile(r"^[A-Z][A-Z0-9_]*$")_CONFIG_TYPES = {"str", "string", "int", "integer", "float", "number",@@ -513,6 +515,7 @@ def validate_plugin_dir(plugin_dir: Path) -> ValidationReport:recorded = _check_capabilities(report, manifest, plugin_dir)_check_builtin_collisions(report, manifest, recorded)_check_security_scan(report, plugin_dir)+ check_desktop_surface(report, plugin_dir)return report@@ -611,4 +614,5 @@ def _validate_portable_plugin(report: ValidationReport, plugin_dir: Path) -> Val"name present" if name else "plugin.json missing required 'name'",)_check_security_scan(report, plugin_dir)+ check_desktop_surface(report, plugin_dir)return reportdiff --git a/hermes_cli/plugin_validate_desktop.py b/hermes_cli/plugin_validate_desktop.pynew file mode 100644index 00000000000..177bc6f33cb--- /dev/null+++ b/hermes_cli/plugin_validate_desktop.py@@ -0,0 +1,62 @@+"""Static admission lint for a plugin's Desktop surface (``desktop/plugin.js``).++A ``plugin.js`` is evaluated as ESM in the Electron renderer realm with the app's full authority+(``apps/desktop/src/contrib/runtime-loader.ts`` says so in its header: error isolation only, no+capability boundary). The loader accepts that for files the user put on disk; a catalog install is a+remote source, so listed plugins must stay inside the SDK surface. This lint refuses the moves that+step outside it. It is a tripwire for review, not a sandbox.+"""++from __future__ import annotations++import re+from pathlib import Path+from typing import List, Tuple++# (rule, regex) applied to comment-stripped source; every hit fails the "desktop surface" check.+_FORBIDDEN: Tuple[Tuple[str, "re.Pattern[str]"], ...] = (+ ("prototype patching",+ re.compile(r"\b[A-Za-z_$][\w$]*\.prototype\.[\w$]+\s*=[^=]")),+ ("prototype patching",+ re.compile(r"\bObject\.definePropert(?:y|ies)\(\s*[\w$.]+\.prototype\b")),+ ("prototype patching",+ re.compile(r"\b(?:Reflect|Object)\.setPrototypeOf\(|\.__proto__\s*=")),+ ("dynamic code evaluation",+ re.compile(r"(?<![\w$.])eval\(|\bnew\s+Function\(")),+ ("dynamic import outside the SDK",+ re.compile(r"\bimport\(\s*(?(?:/[\w/-]*)?['\"]\s*\))")),+ ("script injection",+ re.compile(r"createElement\(\s*['\"]script['\"]\s*\)|<script\b")),+)++_COMMENT = re.compile(r"/\*.*?\*/|(?<![:\w])//[^\n]*", re.S)+++def desktop_surface_findings(source: str) -> List[Tuple[str, int]]:+ """Return ``[(rule, line)]`` for every forbidden construct in a plugin.js source."""+ stripped = _COMMENT.sub(lambda m: "\n" * m.group(0).count("\n"), source)+ findings: List[Tuple[str, int]] = []+ for rule, pattern in _FORBIDDEN:+ for match in pattern.finditer(stripped):+ findings.append((rule, stripped.count("\n", 0, match.start()) + 1))+ return sorted(findings, key=lambda f: f[1])+++def check_desktop_surface(report, plugin_dir: Path) -> None:+ """Fail the report when ``desktop/*.js`` steps outside the SDK surface; silent when there is none."""+ desktop = Path(plugin_dir) / "desktop"+ if not desktop.is_dir():+ return+ hits: List[str] = []+ for js in sorted(desktop.rglob("*.js")):+ try:+ source = js.read_text(encoding="utf-8", errors="replace")+ except OSError:+ continue+ rel = js.relative_to(plugin_dir).as_posix()+ hits.extend(f"{rule} ({rel}:{line})" for rule, line in desktop_surface_findings(source))+ report.add(+ "desktop surface", not hits,+ "; ".join(hits[:8]) + (f" (+{len(hits) - 8} more)" if len(hits) > 8 else "")+ if hits else "stays inside the plugin SDK surface",+ )diff --git a/plugin-catalog/README.md b/plugin-catalog/README.mdindex 9841a590f74..dc13cd0ce51 100644--- a/plugin-catalog/README.md+++ b/plugin-catalog/README.md@@ -44,6 +44,16 @@ meaningful:appear as warnings in the CI log and the reviewer reads them before merging.In exchange, installs at the pinned SHA accept `caution` without a prompt(`dangerous` still blocks). Review the warnings; do not merge past them.+8. **Desktop plugins stay inside the SDK surface.** A `desktop/plugin.js` runs+ in the Desktop renderer with the app's full authority (the loader isolates+ errors, not capabilities), so a listed one may only use the plugin SDK:+ no prototype patching (`X.prototype.y =`, `Object.defineProperty(...prototype`),+ no `eval`/`new Function`, no `import()` of anything but `@hermes/plugin-sdk`+ / `react` (app bundle chunks, blob or http URLs included), no script-tag+ injection, no reaching into the app's internal stores. `hermes plugins+ validate` refuses these at admission (`desktop surface` check); a plugin+ that needs a capability the SDK lacks asks for an SDK hook instead of+ patching around it.## Entry schemadiff --git a/tests/hermes_cli/test_plugin_validate.py b/tests/hermes_cli/test_plugin_validate.pyindex 4753ae9a9f0..8c67a8d075e 100644--- a/tests/hermes_cli/test_plugin_validate.py+++ b/tests/hermes_cli/test_plugin_validate.py@@ -201,3 +201,37 @@ class TestRequiresHermesSpec:"requires_hermes" in f and "does not parse" in f for f in report.failures), report.failures++class TestDesktopSurface:+ """Catalog-listed desktop plugins must stay inside the SDK surface: the renderer loader gives+ plugin.js full app authority, so prototype patching / app-chunk imports are refused at admission."""++ def _desktop_plugin(self, tmp_path, js: str) -> Path:+ d = tmp_path / "desk"+ (d / "desktop").mkdir(parents=True)+ (d / "plugin.yaml").write_text(yaml.safe_dump(dict(BASE_MANIFEST, name="desk")), encoding="utf-8")+ (d / "desktop" / "plugin.js").write_text(js, encoding="utf-8")+ return d++ def test_sdk_only_plugin_passes(self, tmp_path):+ d = self._desktop_plugin(tmp_path, (+ "import { definePlugin } from '@hermes/plugin-sdk'\n"+ "// Storage.prototype.setItem = noop (comments are not code)\n"+ "export default definePlugin({ id: 'desk', register(ctx) { ctx.storage.set('k', 1) } })\n"+ ))+ report = validate_plugin_dir(d)+ assert ("desktop surface", True, "stays inside the plugin SDK surface") in report.checks++ def test_prototype_patch_and_chunk_import_fail(self, tmp_path):+ d = self._desktop_plugin(tmp_path, (+ "const raw = Storage.prototype.setItem\n"+ "Storage.prototype.setItem = function (k, v) { return raw.call(this, k, v) }\n"+ "const mod = await import(/* @vite-ignore */ new URL('./chunk.js', base).href)\n"+ "const sdk = await import('@hermes/plugin-sdk')\n"+ ))+ report = validate_plugin_dir(d)+ failed = {name: detail for name, ok, detail in report.checks if not ok}+ assert "desktop surface" in failed+ assert "prototype patching (desktop/plugin.js:2)" in failed["desktop surface"]+ assert "dynamic import outside the SDK (desktop/plugin.js:3)" in failed["desktop surface"]+ assert ":4)" not in failed["desktop surface"]diff --git a/website/docs/user-guide/features/plugin-catalog.md b/website/docs/user-guide/features/plugin-catalog.mdindex 8caf7fba6fd..003ef218501 100644--- a/website/docs/user-guide/features/plugin-catalog.md+++ b/website/docs/user-guide/features/plugin-catalog.md@@ -62,6 +62,12 @@ The catalog is designed so you know exactly what you're installing:catalog install checked out at exactly the pinned SHA does not stop to askabout `caution` again; `dangerous` still blocks, and anything installed froma raw URL or at another revision gets the normal prompt.+- **Desktop plugins stay inside the SDK.** A plugin's `desktop/plugin.js` runs+ inside the Desktop app with the app's own authority, so listed ones may only+ use the plugin SDK: no patching of built-in prototypes, no `eval`, no+ importing the app's own bundle chunks or remote scripts. Admission refuses+ these (`desktop surface` check) so a marketplace install cannot quietly+ rewire the app around you.- **Capability declarations.** Entries state up front which tools, hooks, andmiddleware the plugin provides and which environment variables (API keysetc.) it needs, so you can judge its blast radius before installing.