summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-10-19 16:36:23 +0000
committerClaude <noreply@anthropic.com>2026-10-19 16:36:23 +0000
commitdc6c4e2470abdd65ffec47b11fa8273deeed2efe (patch)
treef81c8f65cc18720ddcfb68ee52db459798ae7c5d /plugins/security-guidance/hooks
parentea10b213686c90bb1984b2016937310e05336cf3 (diff)
security-guidance: count secret-named data files in the Stop review setmhegazy/sg-secret-named-telemetry
Data files named like secrets.yml or client_secret.json are reviewed like any other file. The Stop hook now reports how many are in its review set, as a count only (secret_named_reviewed, emitted when nonzero), so the share of reviews that include one can be read from telemetry. No change to what is reviewed. Refs anthropics/claude-code#96276
Diffstat (limited to 'plugins/security-guidance/hooks')
-rw-r--r--plugins/security-guidance/hooks/gitutil.py36
-rwxr-xr-xplugins/security-guidance/hooks/security_reminder_hook.py3
2 files changed, 39 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py
index bc4d753b..c2750afa 100644
--- a/plugins/security-guidance/hooks/gitutil.py
+++ b/plugins/security-guidance/hooks/gitutil.py
@@ -934,6 +934,42 @@ def _is_secret_shaped(file_path):
return False
+# Data files whose name says they hold secrets (`secrets.yml`,
+# `client_secret.json`). They are reviewed like any other data file; the Stop
+# hook only counts how many are in its review set (never the names), to show
+# how common they are.
+_SECRET_NAMED_STEMS = frozenset((
+ 'secret', 'secrets', 'credential', 'credentials',
+ 'client_secret', 'client_secrets', 'client-secret', 'client-secrets',
+ 'service-account', 'service_account', 'serviceaccount',
+ 'service-account-key', 'service_account_key', 'serviceaccountkey',
+))
+_SECRET_NAMED_DATA_EXTENSIONS = frozenset((
+ '.json', '.yaml', '.yml', '.toml', '.properties', '.tfvars',
+))
+# `secrets.example.yml` is a placeholder and `secrets.enc.yaml` is ciphertext.
+_NOT_SECRET_NAME_PARTS = frozenset((
+ 'example', 'sample', 'template', 'tmpl', 'dist', 'schema',
+ 'enc', 'encrypted', 'sops',
+))
+
+
+def _is_secret_named(file_path):
+ base = os.path.basename(file_path.replace("\\", "/")).lower()
+ parts = base.lstrip('.').split('.')
+ if len(parts) < 2 or '.' + parts[-1] not in _SECRET_NAMED_DATA_EXTENSIONS:
+ return False
+ if _NOT_SECRET_NAME_PARTS.intersection(parts[1:-1]):
+ return False
+ stem = parts[0]
+ # Google's OAuth download is `client_secret_<client id>.json`.
+ return stem in _SECRET_NAMED_STEMS or stem.startswith('client_secret_')
+
+
+def count_secret_named(diff_files):
+ return sum(1 for file_path, _ in diff_files if _is_secret_named(file_path))
+
+
# Path tokens that bump a file's review priority when a commit exceeds
# MAX_DIFF_FILES and we have to pick a subset. These are exactly the surfaces
# single-shot and agentic reviews disagree on most (auth, routing, IPC,
diff --git a/plugins/security-guidance/hooks/security_reminder_hook.py b/plugins/security-guidance/hooks/security_reminder_hook.py
index ea5bab18..9573a35c 100755
--- a/plugins/security-guidance/hooks/security_reminder_hook.py
+++ b/plugins/security-guidance/hooks/security_reminder_hook.py
@@ -2323,6 +2323,9 @@ def handle_stop_hook(input_data):
diff_files = filter_preexisting_from_diff(diff_files, cwd, baseline_sha)
debug_log(f"Stop hook: reviewing {len(diff_files)} changed files (standard diff)")
+ secret_named = gitutil.count_secret_named(diff_files)
+ if secret_named:
+ _TAIL_METRICS["secret_named_reviewed"] = secret_named
import time as _time
stop_review_start = _time.time()