diff options
| author | Bryan Thompson <238056179+bryan-anthropic@users.noreply.github.com> | 2026-08-20 14:50:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-20 14:50:15 -0500 |
| commit | 240c4b2c17b19868e880f2bfdd909144d67224e1 (patch) | |
| tree | 9deddb18cf7c137cd56c93b25763eba0946a7ad6 /plugins/claude-security/scripts/lib/secret.py | |
| parent | 81182783dc1c15ae70e8a489b1edee5450b1434d (diff) | |
| parent | cbe94d02bc8ea7375e13b39cc400e17eeabfcbee (diff) | |
Merge branch 'main' into add-unleashadd-unleash
Diffstat (limited to 'plugins/claude-security/scripts/lib/secret.py')
| -rw-r--r-- | plugins/claude-security/scripts/lib/secret.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/claude-security/scripts/lib/secret.py b/plugins/claude-security/scripts/lib/secret.py new file mode 100644 index 00000000..9bf90a3a --- /dev/null +++ b/plugins/claude-security/scripts/lib/secret.py @@ -0,0 +1,32 @@ +"""The snippet of a hard-coded credential finding, withheld from what the products carry. + +The line such a finding quotes is the credential itself, and the JSONL and +SARIF files exist to leave the machine (a code scanning upload, a CI +artifact), so neither file quotes it: the finding's file, line and symbol +still locate the code, and the SARIF result's message says why no line is +quoted. Only the emitted copy changes: the finding is still placed on the +snippet as the researcher quoted it, and its fingerprint hashes no text of +the file (see sarif.fingerprint). +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from . import cwe + +if TYPE_CHECKING: + from .finding import Finding + +# CWE's Simplified Mapping entry Use of Hard-coded Credentials; CWE-259, 321 and 671 roll up to it. +CREDENTIALS = 798 + + +def is_credential(finding: Finding) -> bool: + """Whether the finding's CWE rolls up to Use of Hard-coded Credentials.""" + return cwe.catalog.category_of.get(cwe.id_number(finding["cwe_id"])) == CREDENTIALS + + +def withheld(finding: Finding) -> Finding: + """`finding` as the products carry it: a hard-coded credential's snippet is empty.""" + return {**finding, "snippet": ""} if is_credential(finding) else finding |
