summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-10-16 16:36:35 +0000
committerClaude <noreply@anthropic.com>2026-10-16 16:36:35 +0000
commitc7608894ec1ec29ae176b0ca60ef239e57f6e776 (patch)
tree2b26cd4c26a40ca181c9070831a45c4e531b4946 /plugins
parentea10b213686c90bb1984b2016937310e05336cf3 (diff)
security-guidance: keep Claude Code's own credential files out of reviewsmhegazy/sg-claude-code-credential-files
When the Claude Code config directory is a git repo, .credentials.json and .claude.json show up as changed files each time Claude Code rewrites them, and their contents (sign-in tokens, a saved API key, MCP server secrets) were sent to the Stop review. Treat both names as secret-shaped, like .netrc and .npmrc. Refs anthropics/claude-code#90010
Diffstat (limited to 'plugins')
-rw-r--r--plugins/security-guidance/hooks/gitutil.py5
-rw-r--r--plugins/security-guidance/tests/test_secret_shaped_paths.py20
2 files changed, 24 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py
index bc4d753b..de9642fb 100644
--- a/plugins/security-guidance/hooks/gitutil.py
+++ b/plugins/security-guidance/hooks/gitutil.py
@@ -874,9 +874,12 @@ _SSH_PRIVATE_KEY_BASENAMES = frozenset((
'id_ed25519_sk', 'id_xmss',
))
_PRIVATE_KEY_NAME_SUFFIXES = ('_rsa', '_dsa', '_ecdsa', '_ed25519')
+# `.credentials.json` and `.claude.json` are Claude Code's own files: sign-in
+# tokens, a saved API key, MCP server secrets. Claude Code rewrites them as it
+# runs, so they show up as changed when its config directory is a git repo.
_CREDENTIAL_BASENAMES = frozenset((
'credentials', '.netrc', '.pgpass', '.npmrc', '.pypirc',
- '.git-credentials', '.dockercfg',
+ '.git-credentials', '.dockercfg', '.credentials.json', '.claude.json',
))
# chezmoi encodes a target file's attributes as stacked name prefixes
# (`private_dot_netrc`, `encrypted_private_token`); `dot_` stands for a
diff --git a/plugins/security-guidance/tests/test_secret_shaped_paths.py b/plugins/security-guidance/tests/test_secret_shaped_paths.py
index bfd5180d..b20beef3 100644
--- a/plugins/security-guidance/tests/test_secret_shaped_paths.py
+++ b/plugins/security-guidance/tests/test_secret_shaped_paths.py
@@ -25,6 +25,11 @@ import gitutil
"private_dot_netrc",
"dot_aws/credentials",
"Deploy_RSA",
+ ".credentials.json",
+ ".claude/.credentials.json",
+ "private_dot_claude/private_dot_credentials.json",
+ ".claude.json",
+ "dot_claude.json",
])
def test_secret_shaped_names_are_not_reviewable(path):
assert gitutil._is_secret_shaped(path)
@@ -44,6 +49,8 @@ def test_secret_shaped_names_are_not_reviewable(path):
"bin/deploy",
"Dockerfile.dev",
"executable_backup.sh",
+ "config/credentials.json",
+ "src/claude.json",
])
def test_ordinary_source_stays_reviewable(path):
assert not gitutil._is_secret_shaped(path)
@@ -93,3 +100,16 @@ def test_stop_hook_reports_how_many_files_it_left_out(tmp_path, hook_env, stub_a
_rc, stdout, _err = run_hook(stop_payload(repo), hook_env)
assert metrics_of(stdout).get("secret_shaped_skipped") == 2
assert stub_api.calls == []
+
+
+@pytest.mark.parametrize("name", [".credentials.json", ".claude.json"])
+def test_claude_code_files_rewritten_during_the_turn_are_not_sent(tmp_path, hook_env, stub_api, name):
+ repo = make_repo(tmp_path / "repo")
+ (repo / name).write_text('{"accessToken": "old"}\n')
+ run_hook(ups_payload(repo), hook_env)
+ (repo / name).write_text('{"accessToken": "new-and-longer"}\n')
+ later = (repo / name).stat().st_mtime + 5
+ os.utime(repo / name, (later, later))
+ _rc, stdout, _err = run_hook(stop_payload(repo), hook_env)
+ assert metrics_of(stdout).get("secret_shaped_skipped") == 1
+ assert stub_api.calls == []