diff options
Diffstat (limited to 'plugins/claude-security/scripts/lib/secret.py')
| -rw-r--r-- | plugins/claude-security/scripts/lib/secret.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/plugins/claude-security/scripts/lib/secret.py b/plugins/claude-security/scripts/lib/secret.py index 67f4d0f4..df061c2e 100644 --- a/plugins/claude-security/scripts/lib/secret.py +++ b/plugins/claude-security/scripts/lib/secret.py @@ -1,12 +1,15 @@ -"""The snippet of a hard-coded credential finding, withheld from what the products carry. +"""A hard-coded credential finding's snippet and link to the change, withheld from the products. 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 neither its id nor that of a -finding placed near it hashes the credential's line. +quoted. A change scan's link to the change (via_change) describes that same +line in the researcher's words, so it goes with the snippet: here for the +credential finding, in sarif.placed for a finding near the credential's line +or whose link opens there. Only the emitted copy changes: the finding is still +placed on the snippet as the researcher quoted it, and neither its id nor that +of a finding placed near it hashes the credential's line. """ from __future__ import annotations @@ -28,10 +31,13 @@ def is_credential_cwe(number: int) -> bool: def is_credential(finding: Finding) -> bool: - """Whether the finding's CWE rolls up to Use of Hard-coded Credentials.""" - return is_credential_cwe(cwe.id_number(finding["cwe_id"])) + """Whether any CWE the finding carries rolls up to Use of Hard-coded Credentials.""" + ids = (finding["cwe_id"], *finding["other_cwe_ids"]) + return any(is_credential_cwe(cwe.id_number(cwe_id)) for cwe_id in ids) def withheld(finding: Record) -> Record: - """`finding` as the products carry it: a hard-coded credential's snippet is empty.""" - return {**finding, "snippet": ""} if is_credential(finding) else finding + """`finding` as the products carry it: a hard-coded credential's snippet and link withheld.""" + if not is_credential(finding): + return finding + return {**finding, "snippet": "", "via_change": None} |
