diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-12-05 01:28:49 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-12-05 01:28:49 +0000 |
| commit | 84c51d1c787bd8289712d0f6742f3817b6dd0964 (patch) | |
| tree | 4735eb6d4f293b8186506bb1da9557e18546b9b3 | |
| parent | c30174872ca76ac08123b38c30b87beeae8b5e50 (diff) | |
security-guidance: do not repeat a private key the model quotesmhegazy/sg-key-scan
Co-authored-by: mhegazy <mhegazy@anthropic.com>
| -rw-r--r-- | plugins/security-guidance/hooks/key_scan.py | 3 | ||||
| -rw-r--r-- | plugins/security-guidance/tests/test_key_scan.py | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/key_scan.py b/plugins/security-guidance/hooks/key_scan.py index cef61373..afacad00 100644 --- a/plugins/security-guidance/hooks/key_scan.py +++ b/plugins/security-guidance/hooks/key_scan.py @@ -80,7 +80,8 @@ def _is_placeholder(key): def quotes_a_key(text): - return any(pattern.search(str(text or "")) for _, pattern in _FORMATS) + text = str(text or "") + return bool(_KEY_START.search(text)) or any(pattern.search(text) for _, pattern in _FORMATS) class KeyScan: diff --git a/plugins/security-guidance/tests/test_key_scan.py b/plugins/security-guidance/tests/test_key_scan.py index ab40c5b0..73f35413 100644 --- a/plugins/security-guidance/tests/test_key_scan.py +++ b/plugins/security-guidance/tests/test_key_scan.py @@ -394,3 +394,12 @@ def test_said_once_where_the_model_found_it_too(env, gateway, workspace): rc, m, se, _ = commit(repo, env, {"app.py": f"T = '{GITHUB}'\n" + VULN_PY}) assert rc == 2 and m["vulns_found"] == 4 and "PASSWORD = 'x'" in se and "Missing Token Verification" in se and m["keys_found"] == 1 assert "GitHub token on line 1" in se and "T = '" not in se and "Command Injection" in se + + +def test_private_key_quoted_by_the_model_is_not_repeated(env, gateway, workspace): + _, repo = workspace + line = json.dumps({"private_key": pem()}) + gateway.reply = json.dumps({"hasVulnerabilities": True, "vulnerabilities": [ + {**STUB_VULN, "filePath": "sa.json", "category": "Hardcoded Secrets", "vulnerableCode": line[:60]}]}) + rc, m, se, _ = commit(repo, env, {"sa.json": line}) + assert rc == 2 and m["keys_found"] == 1 and "Private key on line 1" in se and "BEGIN" not in se |
