test(security): cover legacy credential-store layouts; profile export reuses the store list

A home that predates platforms/ keeps pairing, whatsapp/session and
matrix/store at the legacy paths (get_hermes_dir), so dropping one of those
from CREDENTIAL_STORE_DIRS must fail a test. PROFILE_CREDENTIAL_PATHS now
unpacks CREDENTIAL_STORE_DIRS and HOME_ENV_FILES instead of a second copy;
the frozenset is unchanged (61 entries).

Refs #128812

Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
This commit is contained in:
Maciej Lisiewski
2026-11-14 14:31:37 +01:00
Unverified
parent 71d1f9e70e
commit 2e8614eeb7
2 changed files with 15 additions and 7 deletions
+5 -7
View File
@@ -20,7 +20,7 @@ from agent.file_safety import HOME_CREDENTIAL_DIRS
from hermes_cli.archive_safe import archive_root_dirs, make_targz, normalize_archive_parts, safe_extract_targz
from hermes_cli import config_backend as _config_backend
from hermes_cli.profiles_config import _migrate_profile_config_if_outdated
from hermes_cli.home_data_layout import PM_RUNTIME_ROOT_DIRS, SECRET_CACHE_STORES
from hermes_cli.home_data_layout import CREDENTIAL_STORE_DIRS, HOME_ENV_FILES, PM_RUNTIME_ROOT_DIRS, SECRET_CACHE_STORES
from hermes_cli.profiles_remove import _rmtree_make_writable, _rmtree_with_retry, wait_profile_unowned
from hermes_cli.profiles_export_scrub import (
GATEWAY_CONNECTION_STORE_RE as _GATEWAY_CONNECTION_STORE_RE, GATEWAY_CONNECTION_STORES as _GATEWAY_CONNECTION_STORES,
@@ -162,8 +162,8 @@ _OS_CREDENTIAL_STORES = (*HOME_CREDENTIAL_DIRS, ".envrc")
# keeps recovery copies of them. Never shipped in a profile export, and user-owned (never
# overwritten) on a distribution install. Add a store here when a writer or loader starts using one.
PROFILE_CREDENTIAL_PATHS = frozenset({
"auth.json", ".env", "auth/google_oauth.json",
".op.env", # 1Password service-account token (env_loader)
"auth.json", "auth/google_oauth.json",
*HOME_ENV_FILES, # .env + the 1Password service-account token (env_loader)
"npmrc", # npm registry auth (source_build)
".anthropic_oauth.json", # Anthropic OAuth tokens (credential_sources)
"google_token.json", "google_oauth_pending.json", "google_client_secret.json",
@@ -174,12 +174,10 @@ PROFILE_CREDENTIAL_PATHS = frozenset({
"mem0.json", # Mem0 api_key (self-hosted server key) next to its settings
"webhook_subscriptions.json", # per-route HMAC secrets
"teams_pipeline_store.json", # Graph subscription client_state (webhook shared secret)
"mcp-tokens", # MCP OAuth tokens
"vault", # vault.key + vault.json.enc
*CREDENTIAL_STORE_DIRS, # MCP OAuth tokens, vault, pairing, messaging sessions (both layouts)
"browser-profile", "browser_auth", "bot-desktop", "webapp", # browser cookies / logins, Webapp sign-in
"browser-profiles", "browser_profiles", # live CDP profiles, Browser Use CLI dir (Cookies, Login Data)
"pairing", "platforms/pairing", "feishu_comment_pairing.json",
"whatsapp/session", "platforms/whatsapp/session", "matrix/store", "platforms/matrix/store",
"feishu_comment_pairing.json",
*SECRET_CACHE_STORES, # Bitwarden / 1Password value caches, Photon sidecar token
"workspace/meetings/node_token.json", # google_meet node RPC secret
"weixin/accounts", # WeChat bot tokens + per-peer context tokens
@@ -76,6 +76,16 @@ def _assert_refused_everywhere(home, monkeypatch, paths):
assert leaks == []
def test_legacy_layout_stores_are_refused(home, monkeypatch):
"""A home that predates ``platforms/`` keeps its stores at the old paths (get_hermes_dir)."""
for legacy in ("pairing", "whatsapp/session", "matrix/store"):
(home / legacy).mkdir(parents=True)
(home / legacy / "seed").write_text("x", encoding="utf-8")
paths = _written_stores(home)
assert not any("platforms" in path.relative_to(home).parts for path in paths), paths
_assert_refused_everywhere(home, monkeypatch, paths)
@pytest.mark.platforms("macos", "windows")
def test_case_variants_of_the_stores_are_refused(home, monkeypatch):
"""Case-insensitive filesystems open ``PLATFORMS/PAIRING/`` and ``.OP.ENV`` for the real stores."""