The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(vault): copy plugin metadata inside the guarded call
Teknium67ea21b293a8
diff --git a/agent/vault_backends/plugin.py b/agent/vault_backends/plugin.pyindex 69331a4833d..5a2ac0e6a2b 100644--- a/agent/vault_backends/plugin.py+++ b/agent/vault_backends/plugin.py@@ -9,7 +9,9 @@ rules hold however the plugin implements ``LoginBackend``:- It is handed the handle and nothing else: no page, CDP session, task id, other entries or masterpassword. ``needs_unlock`` is always False, so Hermes' master-password prompt never runs for it.- Its exceptions are replaced by a fixed-text ``PluginBackendError`` raised outside the ``except``, so a- secret in a plugin's error text reaches no tool result, log line or exception chain.+ secret in a plugin's error text reaches no tool result, log line or exception chain. Returned values+ are validated and copied into core-owned objects inside the same guard: reading a field of a+ plugin-owned object (a property, ``__getattribute__``, a ``str`` subclass) can run plugin code too."""from __future__ import annotations@@ -21,16 +23,31 @@ from agent.vault_backends.base import LoginBackendfrom agent.vault_store import VAULT_KINDS, VaultItemMeta_FAILED = object()+_INVALID = object()+_TEXT_FIELDS = ("id", "kind", "label", "created_at")+_OPTIONAL_TEXT_FIELDS = ("origin", "identifier", "identifier_type")-def _well_formed(meta: Any) -> bool:- """``VaultItemMeta`` does not type-check its fields; the vault tool reads them outside any plugin guard."""- return (isinstance(meta, VaultItemMeta) and meta.kind in VAULT_KINDS- and all(isinstance(getattr(meta, f), str) for f in ("id", "label", "created_at"))- and all(getattr(meta, f) is None or isinstance(getattr(meta, f), str)- for f in ("origin", "identifier", "identifier_type"))- and isinstance(meta.has_otp, bool) and isinstance(meta.allowed_origins, tuple)- and all(isinstance(o, str) for o in meta.allowed_origins))+def _text(value: Any) -> Any:+ """An exact ``str`` copy (a subclass's methods never run outside the guard), or ``_INVALID``."""+ return str.__str__(value) if isinstance(value, str) else _INVALID+++def _materialize(meta: Any) -> Any:+ """A core-owned ``VaultItemMeta`` copied from the plugin's, or ``_INVALID`` when a field has the wrong type."""+ if not isinstance(meta, VaultItemMeta):+ return _INVALID+ fields = {f: _text(getattr(meta, f)) for f in _TEXT_FIELDS}+ for f in _OPTIONAL_TEXT_FIELDS:+ value = getattr(meta, f)+ fields[f] = None if value is None else _text(value)+ has_otp, origins = meta.has_otp, meta.allowed_origins+ if not isinstance(origins, tuple) or type(has_otp) is not bool:+ return _INVALID+ fields["allowed_origins"] = tuple(_text(o) for o in origins)+ if _INVALID in fields.values() or _INVALID in fields["allowed_origins"] or fields["kind"] not in VAULT_KINDS:+ return _INVALID+ return VaultItemMeta(has_otp=has_otp, **fields)class PluginBackendError(RuntimeError):@@ -65,35 +82,52 @@ class PluginLoginBackend(LoginBackend):raise PluginBackendError(f"The {self.name} login backend returned an invalid value.")def list_items(self) -> list[VaultItemMeta]:- items = self._call(lambda: list(self._plugin.list_items()))- self._require(all(_well_formed(m) for m in items))+ items = self._call(lambda: [_materialize(m) for m in self._plugin.list_items()])+ self._require(all(m is not _INVALID for m in items))return [m for m in items if self.owns(m.id)]def get_meta(self, handle: str) -> Optional[VaultItemMeta]:if not self.owns(handle):return None- meta = self._call(lambda: self._plugin.get_meta(handle))- self._require(meta is None or _well_formed(meta))++ def fetch() -> Any:+ meta = self._plugin.get_meta(handle)+ return None if meta is None else _materialize(meta)++ meta = self._call(fetch)+ self._require(meta is not _INVALID)return meta if meta is not None and meta.id == handle else Nonedef resolve_password(self, handle: str) -> str:self._require_own(handle)- value = self._call(lambda: self._plugin.resolve_password(handle))- self._require(isinstance(value, str))+ value = self._call(lambda: _text(self._plugin.resolve_password(handle)))+ self._require(value is not _INVALID)return valuedef resolve_otp(self, handle: str) -> Optional[str]:self._require_own(handle)- value = self._call(lambda: self._plugin.resolve_otp(handle))- self._require(value is None or isinstance(value, str))++ def fetch() -> Any:+ value = self._plugin.resolve_otp(handle)+ return None if value is None else _text(value)++ value = self._call(fetch)+ self._require(value is not _INVALID)return valuedef resolve_secret(self, handle: str) -> dict[str, str]:self._require_own(handle)- value = self._call(lambda: self._plugin.resolve_secret(handle))- self._require(isinstance(value, dict) and all(isinstance(k, str) and isinstance(v, str)- for k, v in value.items()))- return dict(value)++ def fetch() -> Any:+ value = self._plugin.resolve_secret(handle)+ if not isinstance(value, dict):+ return _INVALID+ copied = {_text(k): _text(v) for k, v in value.items()}+ return _INVALID if _INVALID in copied or _INVALID in copied.values() else copied++ value = self._call(fetch)+ self._require(value is not _INVALID)+ return value@contextmanagerdef fill_context(self):diff --git a/tests/tools/test_browser_vault_plugin_isolation.py b/tests/tools/test_browser_vault_plugin_isolation.pyindex c03859d0680..59ad4bfed8e 100644--- a/tests/tools/test_browser_vault_plugin_isolation.py+++ b/tests/tools/test_browser_vault_plugin_isolation.py@@ -429,3 +429,39 @@ def test_plugin_otp_is_minted_and_written_inside_the_backends_fill_context(vaultassert backend.calls == ["enter", "resolve_otp", "write", "exit"]assert code in page.secret_evals[0] and code not in json.dumps(out)++_LAZY_META_BACKEND = '''+from agent.vault_backends.base import LoginBackend+from agent.vault_store import VaultItemMeta++class LazyMeta(VaultItemMeta):+ def __getattribute__(self, field):+ if field == "allowed_origins":+ raise RuntimeError("manager said {leak}")+ return super().__getattribute__(field)++class Backend(LoginBackend):+ name, prefix, display_name = "lazy", "lazy:", "Lazy"++ def list_items(self):+ return [self.get_meta("lazy:1")]++ def get_meta(self, handle):+ return LazyMeta(id=handle, kind="login", label="Lazy", origin="https://example.com",+ created_at="2026-01-01T00:00:00Z")++ def resolve_password(self, handle):+ return "unused"+'''+++def test_errors_reading_plugin_metadata_get_the_fixed_message(vault_home, page):+ home, _local, load = vault_home+ _write_plugin(home, "lazy_vault", _LAZY_META_BACKEND.format(leak=LEAK), " ctx.register_login_backend(Backend())\n")+ load(["lazy_vault"], {"lazy": "true"})++ listed, filled = _vault({"action": "list"}), _vault({"action": "fill", "handle": "lazy:1"})+ assert LEAK not in listed and LEAK not in filled+ assert json.loads(listed)["errors"] == [{"backend": "lazy", "error": "The lazy login backend failed."}]+ assert json.loads(filled)["error_type"] == "backend_unavailable" and page.secret_evals == []+diff --git a/website/docs/developer-guide/browser-vault-plugin.md b/website/docs/developer-guide/browser-vault-plugin.mdindex bf93baf1866..e428c30c1c7 100644--- a/website/docs/developer-guide/browser-vault-plugin.md+++ b/website/docs/developer-guide/browser-vault-plugin.md@@ -87,7 +87,7 @@ hold however the plugin implements its class:| **Off by default** | Only `vault.<name>.enabled: true` turns a backend on. || **In-process only** | `ctx.register_login_backend` is refused under `plugins.isolation: host`, because `fill_context()` is a server-local context manager. || **Same fill path** | Plugin items go through the same exact-origin pre-check, in-page origin re-assertion, supervisor CDP secret evaluation (never argv) and payment confirmation as built-in items. |-| **Secrets stay out of the conversation** | Values you return are registered with the browser-result redaction boundary before they reach the page. Any exception your backend raises is replaced by a fixed message (`The <name> login backend failed.`) before it can reach a tool result, a log line or an exception chain, so a secret in your error text cannot reach the model. A value of the wrong type is refused the same way. |+| **Secrets stay out of the conversation** | Values you return are registered with the browser-result redaction boundary before they reach the page. Any exception your backend raises is replaced by a fixed message (`The <name> login backend failed.`) before it can reach a tool result, a log line or an exception chain, so a secret in your error text cannot reach the model. A value of the wrong type is refused the same way. Hermes copies what you return (metadata fields, passwords, codes) into its own plain objects inside that same guard, so an error raised while a field is read gets the fixed message too. |An in-process plugin is ordinary Python running inside Hermes, so these rules are an API contract,not a sandbox. They guarantee that Hermes never hands your backend another backend's data; they do not