Skip to content

The agent that grows with you

fix(agent): the agent's file tools and profile clones leave the Webapp's sign-in files alone

emozilla9d2519a6140d
diff --git a/.gitignore b/.gitignore
index 47aac96cd9d..80d58fef4c8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -250,6 +250,7 @@ docs/superpowers/*
/profiles/
/credentials/
/mcp-tokens/
+/webapp/
/pairing/
/platforms/
/backups/
diff --git a/agent/file_safety.py b/agent/file_safety.py
index 31bd2c8f0f9..3c3ed7db604 100644
--- a/agent/file_safety.py
+++ b/agent/file_safety.py
@@ -242,11 +242,13 @@ def build_write_approval_paths(home: str) -> set[str]:
# HERMES_HOME / root subpaths that the agent's generic file tools must not
# rewrite. Session transcripts (state.db, sessions/) are application-owned
# state whose rewrite can falsify history and break resume/compression;
-# mcp-tokens/, pairing/, vault/ (key + ciphertext side by side) and
-# browser-profile/ (copied cookies / Login Data) hold credential material.
+# mcp-tokens/, pairing/, vault/ (key + ciphertext side by side),
+# browser-profile/ (copied cookies / Login Data) and webapp/ (the Webapp's
+# browser credential and its grants to native apps) hold credential material.
# Control files (auth.json, config.yaml, webhook_subscriptions.json) are
# deliberately NOT here (#45947): read-denied, but the user may ask to edit them.
-_HERMES_PROTECTED_SUBPATHS = ("state.db", "sessions", "mcp-tokens", "pairing", "vault", "browser-profile")
+_HERMES_PROTECTED_SUBPATHS = (
+ "state.db", "sessions", "mcp-tokens", "pairing", "vault", "browser-profile", "webapp")
def _classify_write_denial(path: str, *, entry: bool = False) -> Optional[str]:
@@ -362,6 +364,11 @@ _READ_DENIED_DIRS = (
("vault",
"is the Hermes credential vault directory and cannot be read directly (secrets are filled server-side by browser_vault).",
"is inside the Hermes credential vault (encrypted secrets + local key) and cannot be read directly (browser_vault resolves them server-side)."),
+ # session-token is the Webapp's browser credential (a bare token no redaction pattern masks); the
+ # rest are its grants to native apps and its Web Access registration.
+ ("webapp",
+ "is the Hermes Webapp sign-in directory and cannot be read directly.",
+ "is a Hermes Webapp sign-in file (the browser credential or its sign-in records) and cannot be read directly."),
)
@@ -370,7 +377,7 @@ def get_read_block_error(path: str) -> Optional[str]:
Blocked: internal skill-hub caches (prompt-injection carriers), credential
stores under HERMES_HOME and the global root (exact files, plus anything
- under ``mcp-tokens/`` and ``browser-profile/``), and project-local ``.env``
+ under ``mcp-tokens/``, ``browser-profile/``, ``vault/`` and ``webapp/``), and project-local ``.env``
files anywhere on disk (``.env.example`` is the documented-shape substitute).
Callers that resolve relative paths against a non-process cwd (e.g.
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py
index f746f5bdaf5..d609c49b1b0 100644
--- a/gateway/platforms/base.py
+++ b/gateway/platforms/base.py
@@ -784,12 +784,12 @@ def _sqlite_files(name: str) -> tuple[str, ...]:
# Credential stores at the HERMES_HOME root, denied per-file so skills/, logs/ and agent-written
# files stay deliverable (cache subdirs are allowlisted BEFORE this). A superset of the
# agent/file_safety.py read+write denies so exfil never trails the read guard. google_token.json's mtime bumps every turn (defeats the
-# recency window); pairing/ and mcp-tokens/ (live OAuth tokens) are denied as whole trees.
+# recency window); pairing/, mcp-tokens/ (live OAuth tokens) and webapp/ (the Webapp's credential) are whole trees.
_ROOT_CREDENTIAL_PATHS = (
".env", "auth.json", "auth.lock", "credentials", "config.yaml", ".anthropic_oauth.json",
"google_token.json", "google_oauth_pending.json", os.path.join("auth", "google_oauth.json"),
"webhook_subscriptions.json", os.path.join("cache", "bws_cache.json"),
- os.path.join("cache", "bws_cache.enc.json"), "pairing", "mcp-tokens",
+ os.path.join("cache", "bws_cache.enc.json"), "pairing", "mcp-tokens", "webapp",
# Whole conversation history (every secret ever pasted into a chat) and the copied browser
# cookie/login store; sessions/ is the legacy transcript dir. SQLite sidecars are listed
# too: WAL mode touches state.db-wal on every write, so recency trust alone would leak them.
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index 472a4576a01..759bae387cc 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -40,10 +40,10 @@ _CLONE_CONFIG_FILES = ["config.yaml", ".env", "SOUL.md"]
# identity, as important as SOUL.md for continuity.
_CLONE_SUBDIR_FILES = ["memories/MEMORY.md", "memories/USER.md"]
-# Runtime files stripped after --clone-all, the Webapp's browser credential among them (each gateway
-# mints its own). A post-copy step: they are created dynamically and may be absent at copy time.
+# Runtime files stripped after --clone-all. A post-copy step rather than an ignore filter
+# because they are created dynamically and may be absent at copy time.
_CLONE_ALL_STRIP: list[str] = [
- "gateway.pid", "gateway_state.json", "processes.json", "webapp/session-token",
+ "gateway.pid", "gateway_state.json", "processes.json",
# Bot Desktop runtime identity: pid + create_time of the SOURCE's launcher, its DISPLAY/XAUTHORITY and
# lease. Copied verbatim, `screen stop` on the clone would kill the source's X server. Browser user data
# stays, but Chromium's process markers must not let the clone attach to the source's live browser.
@@ -85,7 +85,7 @@ _CLONE_ALL_DEFAULT_EXCLUDE_ROOT: frozenset[str] = frozenset({
# duplicate deliveries) the moment its gateway starts. The empty dir is recreated below.
_CLONE_ALL_HISTORY_EXCLUDE_ROOT: frozenset[str] = frozenset({
"state.db", "state.db-wal", "state.db-shm", "sessions", "backups", "state-snapshots", "checkpoints",
- "cron",
+ "cron", "webapp", # webapp/: the source gateway's sign-in state (credential, native grants, Portal callback)
})
# Marker written by `hermes profile create --no-skills`. When present at a profile root,
diff --git a/tests/agent/test_file_safety_credentials.py b/tests/agent/test_file_safety_credentials.py
index 0fbca17ea67..6a6dc4c55fa 100644
--- a/tests/agent/test_file_safety_credentials.py
+++ b/tests/agent/test_file_safety_credentials.py
@@ -282,3 +282,26 @@ def test_profile_mode_blocks_root_credentials(tmp_path, monkeypatch):
root_tok.parent.mkdir(parents=True, exist_ok=True)
root_tok.write_text("x")
assert "MCP token" in (get_read_block_error(str(root_tok)) or "")
+
+
+ "rel", ["webapp/session-token", "webapp/native-sign-in-tokens.json", "webapp/sign-in-registration.json"])
+def test_the_webapps_sign_in_files_are_neither_read_nor_written(tmp_path, monkeypatch, rel):
+ """``webapp/`` holds the Webapp's browser credential (a bare token no redaction pattern masks; it opens
+ host shells and files on the loopback Webapp until ``hermes webapp --sign-out``), the record of the
+ provider tokens its listener gave native apps and the Portal callback its Web Access registered. The
+ agent's file tools neither read nor write anything there, in the profile's home or at the root: a
+ write could plant a credential or a grant that the gateway then honours."""
+ import agent.file_safety as fs
+ from agent.file_safety import get_read_block_error, is_write_denied
+
+ root = tmp_path / "hermes"
+ profile = root / "profiles" / "coder"
+ monkeypatch.setattr(fs, "_hermes_home_path", lambda: profile)
+ monkeypatch.setattr(fs, "_hermes_root_path", lambda: root)
+ for home in (profile, root):
+ stored = _create(home, rel)
+ assert get_read_block_error(str(stored)) is not None, f"read_file hands the agent {stored}"
+ assert get_read_block_error(str(stored.parent)) is not None
+ assert is_write_denied(str(stored)), f"write_file may replace {stored}"
+ assert is_write_denied(str(stored.parent / "planted.json"))
diff --git a/tests/gateway/test_platform_base.py b/tests/gateway/test_platform_base.py
index da9b27dbd7d..f43a1085aab 100644
--- a/tests/gateway/test_platform_base.py
+++ b/tests/gateway/test_platform_base.py
@@ -662,6 +662,23 @@ class TestMediaDeliveryDefaultMode:
assert BasePlatformAdapter.validate_media_delivery_path(str(secret)) is None
+ @pytest.mark.parametrize("rel", ["webapp/session-token", "webapp/native-sign-in-tokens.json"])
+ def test_denylist_blocks_the_webapps_sign_in_files(self, tmp_path, monkeypatch, rel):
+ """The Webapp's browser credential and its listener's grants to native apps under
+ ``~/.hermes/webapp/`` never deliver as native media, as the agent's file tools never read them."""
+ self._patch_roots(monkeypatch)
+
+ fake_home = tmp_path / "home"
+ hermes_dir = fake_home / ".hermes"
+ (hermes_dir / "webapp").mkdir(parents=True)
+ secret = hermes_dir / rel
+ secret.write_text("t" * 43 + "\n")
+ monkeypatch.setenv("HOME", str(fake_home))
+ monkeypatch.setattr("gateway.platforms.base._HERMES_HOME", hermes_dir)
+ monkeypatch.setattr("gateway.platforms.base._HERMES_ROOT", hermes_dir)
+
+ assert BasePlatformAdapter.validate_media_delivery_path(str(secret)) is None
+
def test_denylist_blocks_google_token_default_mode(self, tmp_path, monkeypatch):
"""Integration credentials at the HERMES_HOME root (google_token.json)
diff --git a/tests/hermes_cli/test_profile_export_credentials.py b/tests/hermes_cli/test_profile_export_credentials.py
index b5697851aa2..cced7bac84f 100644
--- a/tests/hermes_cli/test_profile_export_credentials.py
+++ b/tests/hermes_cli/test_profile_export_credentials.py
@@ -39,6 +39,8 @@ _EXTRA_STORES = {
"mcp-tokens/srv.json", "vault/vault.key", "platforms/pairing/approved.json", "slack_tokens.json",
"webhook_subscriptions.json", ".ssh/id_rsa", ".aws/credentials", ".gnupg/x", ".kube/config", ".envrc",
"webapp/session-token", # the Webapp browser's credential (gateway.webapp_listener.TOKEN_PATH)
+ "webapp/native-sign-in-tokens.json", # its listener's grants to native apps (webapp_sign_in.RECORD_PATH)
+ "webapp/sign-in-registration.json", # the Portal callback its Web Access registered (webapp_access)
}
# Single-file stores whose name has no dot; every other dotless store is a token directory.
_DOTLESS_FILES = {"npmrc", "webapp/session-token"}
@@ -313,3 +315,26 @@ def test_clone_all_does_not_share_the_source_webapp_browser_credential(profile_e
assert not (profile_dir / TOKEN_PATH).exists()
assert browser_session_token(profile_dir) != source_token
assert browser_session_token(default_home) == source_token
+
+
+def test_clone_all_leaves_the_source_gateways_webapp_sign_in_state_behind(profile_env):
+ """Everything in ``webapp/`` belongs to the source's gateway: besides its browser credential, the
+ record of the provider tokens its listener gave native apps (which its gated Webapp accepts on their
+ own) and the Portal callback its Web Access registered for its own address. A ``--clone-all`` clone
+ gets none of it, so the clone's gated Webapp honours no native sign-in made on the source, and the
+ clone's Web Access registers its own callback."""
+ from hermes_cli.profiles import create_profile
+ from hermes_cli.webapp_sign_in import RECORD_PATH
+
+ default_home = profile_env / ".hermes"
+ (default_home / "config.yaml").write_text("model: test", encoding="utf-8")
+ (default_home / RECORD_PATH).parent.mkdir(parents=True)
+ (default_home / RECORD_PATH).write_text('{"' + "d" * 64 + '": 4102444800}\n', encoding="utf-8")
+ (default_home / "webapp" / "sign-in-registration.json").write_text(
+ '{"portal": "https://portal.example.test", "client_id": "c1", '
+ '"callback": "http://192.168.1.50:9120/auth/callback"}\n', encoding="utf-8")
+
+ profile_dir = create_profile("coder", clone_all=True, no_alias=True)
+
+ assert not (profile_dir / "webapp").exists(), sorted(p.name for p in (profile_dir / "webapp").iterdir())
+ assert (default_home / RECORD_PATH).exists()
diff --git a/tests/hermes_cli/test_update_flat_install_state_gitignore.py b/tests/hermes_cli/test_update_flat_install_state_gitignore.py
index 9e7d8e5bc0b..b2ba09a7ef9 100644
--- a/tests/hermes_cli/test_update_flat_install_state_gitignore.py
+++ b/tests/hermes_cli/test_update_flat_install_state_gitignore.py
@@ -90,6 +90,7 @@ FLAT_INSTALL_RUNTIME_STATE = (
"profiles/work/config.yaml",
"credentials/github_token",
"mcp-tokens/server.json",
+ "webapp/session-token",
"pairing/telegram.json",
"platforms/pairing/x.json",
"backups/2026-09-14T06-00-00-pre-update/state.db",