The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(vault): a plugin backend returning malformed data only breaks itself
Tekniumd39883cf8c43
diff --git a/agent/vault_backends/plugin.py b/agent/vault_backends/plugin.pyindex 0b1eafd8f2d..69331a4833d 100644--- a/agent/vault_backends/plugin.py+++ b/agent/vault_backends/plugin.py@@ -18,11 +18,21 @@ from contextlib import contextmanagerfrom typing import Any, Callable, Optionalfrom agent.vault_backends.base import LoginBackend-from agent.vault_store import VaultItemMeta+from agent.vault_store import VAULT_KINDS, VaultItemMeta_FAILED = object()+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))++class PluginBackendError(RuntimeError):"""A plugin login backend failed or broke its contract (fixed text: never the plugin's own message)."""@@ -56,13 +66,15 @@ class PluginLoginBackend(LoginBackend):def list_items(self) -> list[VaultItemMeta]:items = self._call(lambda: list(self._plugin.list_items()))- return [m for m in items if isinstance(m, VaultItemMeta) and self.owns(m.id)]+ self._require(all(_well_formed(m) 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 Nonemeta = self._call(lambda: self._plugin.get_meta(handle))- return meta if isinstance(meta, VaultItemMeta) and meta.id == handle else None+ self._require(meta is None or _well_formed(meta))+ return meta if meta is not None and meta.id == handle else Nonedef resolve_password(self, handle: str) -> str:self._require_own(handle)@@ -86,8 +98,8 @@ class PluginLoginBackend(LoginBackend):@contextmanagerdef fill_context(self):"""The plugin's own context around one of ITS fills; it never sees the core's exception."""- context = self._call(self._plugin.fill_context)- self._call(context.__enter__)+ context = self._call(lambda: self._plugin.fill_context())+ self._call(lambda: context.__enter__())try:yieldfinally:diff --git a/tests/tools/test_browser_vault_plugin_isolation.py b/tests/tools/test_browser_vault_plugin_isolation.pyindex 69e36ac04e6..dbfab462fad 100644--- a/tests/tools/test_browser_vault_plugin_isolation.py+++ b/tests/tools/test_browser_vault_plugin_isolation.py@@ -90,6 +90,29 @@ class Backend(LoginBackend):'''+# Contract-breaking returns: a meta whose fields have the wrong types, and a non-context-manager fill_context.+_MALFORMED_BACKEND = '''+from agent.vault_backends.base import LoginBackend+from agent.vault_store import VaultItemMeta++class Backend(LoginBackend):+ name, prefix, display_name = "broken", "broken:", "Broken"++ def list_items(self):+ return [VaultItemMeta(id="broken:1", kind="login", label="x", origin="https://example.com",+ created_at="2026-01-01T00:00:00Z", allowed_origins=None)]++ def get_meta(self, handle):+ return self.list_items()[0]++ def fill_context(self):+ return None++ def resolve_password(self, handle):+ return "unused"+'''++def _write_plugin(home, dirname, body, register):plugin = home / "plugins" / dirnameplugin.mkdir(parents=True)@@ -317,3 +340,15 @@ def test_plugin_secrets_never_reach_tool_results_or_logs(vault_home, page, caploassert SECRET not in result and LEAK not in result, resultassert SECRET not in caplog.text and LEAK not in caplog.textassert SECRET not in redact_registered_vault_values(f"page echoed {SECRET}")+++def test_a_plugin_breaking_its_contract_only_breaks_itself(vault_home, page):+ home, local, load = vault_home+ _write_plugin(home, "broken_vault", _MALFORMED_BACKEND, " ctx.register_login_backend(Backend())\n")+ load(["broken_vault"], {"broken": "true"})++ listed = json.loads(_vault({"action": "list"}))+ assert [i["handle"] for i in listed["items"]] == [local.id]+ assert listed["errors"] == [{"backend": "broken", "error": "The broken login backend returned an invalid value."}]+ out = json.loads(_vault({"action": "fill", "handle": "broken:1"}))+ assert out["error_type"] == "backend_unavailable" and page.secret_evals == []