Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(security): ignore uppercase identifier values (#3420)
Kumar Abhimanyua06f2af3965f
diff --git a/packages/core/src/repowise/core/analysis/security_scan.py b/packages/core/src/repowise/core/analysis/security_scan.pyindex a415fcab0..3c91e2c14 100644--- a/packages/core/src/repowise/core/analysis/security_scan.py+++ b/packages/core/src/repowise/core/analysis/security_scan.py@@ -744,6 +744,10 @@ _SCHEME_TEMPLATE_VALUE = re.compile(_OWN_NAME_VALUE = re.compile(r"[A-Za-z_-]+")_CONSTANT_NAME = re.compile(r"[A-Z][A-Z0-9_]*")_KEY_NAME_VALUE = re.compile(r"[a-z]+(?:[_-][a-z]+)+|[a-z_]*_[a-z_]*")+# Uppercase env-var names and sentinels can have short version numbers. Four+# consecutive digits are credential-shaped, so keep those values reportable.+_UPPER_KEY_NAME_VALUE = re.compile(r"[A-Z_][A-Z0-9_]*")+_LONG_DIGIT_RUN = re.compile(r"[0-9]{4,}")def _is_own_name_value(value: str, name: str) -> bool:@@ -782,7 +786,14 @@ def _is_secret_value(kind: str, val: str, name: str = "") -> bool:if kind not in _KEYWORD_KINDS:return Truevalue = val.strip()- if kind == "hardcoded_secret" and _KEY_NAME_VALUE.fullmatch(value):+ if kind == "hardcoded_secret" and (+ _KEY_NAME_VALUE.fullmatch(value)+ or (+ "_" in value+ and _UPPER_KEY_NAME_VALUE.fullmatch(value)+ and not _LONG_DIGIT_RUN.search(value)+ )+ ):return Falseif _is_own_name_value(value, name):return Falsediff --git a/tests/unit/analysis/test_security_scan.py b/tests/unit/analysis/test_security_scan.pyindex 68597cc0e..2117859c6 100644--- a/tests/unit/analysis/test_security_scan.py+++ b/tests/unit/analysis/test_security_scan.py@@ -1171,6 +1171,28 @@ class TestVendorShapeEdges:def test_key_names_and_templates_are_not_secrets(self, source: str) -> None:assert "hardcoded_secret" not in self._kinds(source)+ @pytest.mark.parametrize(+ "value",+ ["COMFY_CLOUD_API_KEY", "NO_REPLY", "HEARTBEAT_OK", "AWS_V2_API_KEY", "TOKEN_123_KEY", "_PRIVATE_KEY"],+ )+ @pytest.mark.parametrize("path", ["config.py", "config.ts", ".env"])+ def test_uppercase_identifiers_are_not_secrets(self, value: str, path: str) -> None:+ assert "hardcoded_secret" not in self._kinds(f'API_KEY = "{value}"\n', path)++ @pytest.mark.parametrize(+ "value",+ ["ABCD_1234_EFGH", "ABCD_1234567890_EFGH", "ABCD_eFGH_12", "ABCD-EFGH-1234"],+ )+ def test_credential_shaped_values_still_fire(self, value: str) -> None:+ assert "hardcoded_secret" in self._kinds(f'API_KEY = "{value}"\n')++ def test_uppercase_password_is_not_exempted(self) -> None:+ assert "hardcoded_password" in self._kinds('password = "SECRET_PHRASE"\n')++ def test_vendor_key_is_not_exempted_by_uppercase_identifier(self) -> None:+ key = "AKIA" + "BCDEFGHIJKLMNOPQ"+ assert "aws_access_key" in self._kinds(f'API_KEY = "{key}"\n')+def test_vendor_shape_and_keyword_report_one_finding(self) -> None:source = 'GITHUB_TOKEN = "ghp_abcdefghijklmnopqrstuvwxyzABCDEFGHIJ"\n' # pragma: allowlist secretassert self._kinds(source) == ["github_token"]