diff options
| author | Mohamed Hegazy <8000722+mhegazy@users.noreply.github.com> | 2026-10-20 13:27:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-20 13:27:39 -0700 |
| commit | f61e6d15fc03feb474d6df219e37b46f9c14565b (patch) | |
| tree | 6cea63791adb42373558751d56c62c6c1aae1b13 /plugins | |
| parent | 7bcf8f3757d158e023b98c151d8091cbf130db91 (diff) | |
| parent | c7608894ec1ec29ae176b0ca60ef239e57f6e776 (diff) | |
Merge pull request #6721 from anthropics/mhegazy/sg-claude-code-credential-files
security-guidance: keep Claude Code's own credential files out of reviews
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/security-guidance/hooks/gitutil.py | 5 | ||||
| -rw-r--r-- | plugins/security-guidance/tests/test_secret_shaped_paths.py | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py index a2402d1e..8702e4da 100644 --- a/plugins/security-guidance/hooks/gitutil.py +++ b/plugins/security-guidance/hooks/gitutil.py @@ -931,9 +931,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 == [] |
