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-scan): stop reading kebab-case names and rule prose as findings (#3030)
Raghav Chamadiyabd3b74417419
diff --git a/packages/core/src/repowise/core/analysis/security_scan.py b/packages/core/src/repowise/core/analysis/security_scan.pyindex ffe6b5f44..81244688b 100644--- a/packages/core/src/repowise/core/analysis/security_scan.py+++ b/packages/core/src/repowise/core/analysis/security_scan.py@@ -311,7 +311,14 @@ _SYMBOL_KEYWORDS = re.compile(r"\b(auth|token|password|jwt|session|crypto)\b", r# comments and string literals blanked, so a docstring, a comment or a regex# literal that merely mentions the call does not fire._MASKED_KINDS = frozenset(- {"pickle_loads", "subprocess_shell_true", "os_system", "new_function_call"}+ {+ "pickle_loads",+ "subprocess_shell_true",+ "os_system",+ "new_function_call",+ "tls_verify_false",+ "reject_unauthorized_false",+ })# Prose is documentation, not executable code. Only secret kinds scan it,@@ -347,10 +354,11 @@ SYMBOL_NAME_KINDS: frozenset[str] = frozenset({"security_sensitive_symbol"})_KEYWORD_KINDS: frozenset[str] = frozenset({"hardcoded_password", "hardcoded_secret"})-# A snake_case name is a key's name (a constant holding its own name) and a-# template placeholder or shell substitution is filled in when it runs; none of-# them is a credential.-_KEY_NAME_VALUE = re.compile(r"[a-z_]*_[a-z_]*")+# A snake_case or kebab-case name (``x-api-key``, ``repowise-security-ignore``)+# is a key's or marker's name, a constant holding its own name, and a template+# placeholder or shell substitution is filled in when it runs; none of them is a+# credential. Letters only: a digit or capital makes it look like a key.+_KEY_NAME_VALUE = re.compile(r"[a-z]+(?:[_-][a-z]+)+|[a-z_]*_[a-z_]*")_TEMPLATE_VALUE = re.compile(r"\{\{.*\}\}|\$\{[^}]*\}|\$\(.*\)")diff --git a/tests/unit/analysis/test_security_scan.py b/tests/unit/analysis/test_security_scan.pyindex c1ec007e7..f613ebdd0 100644--- a/tests/unit/analysis/test_security_scan.py+++ b/tests/unit/analysis/test_security_scan.py@@ -511,6 +511,8 @@ class TestScanFile:("const agent = new https.Agent({ rejectUnauthorized: false });\n", True),("axios.get(url, { httpsAgent, rejectUnauthorized: false });\n", True),("const agent = new https.Agent({ rejectUnauthorized: true });\n", False),+ ('const doc = "TLS off (rejectUnauthorized: false).";\n', False),+ ("// rejectUnauthorized: false would disable TLS checks\n", False),],)def test_reject_unauthorized_false(self, source: str, expected: bool) -> None:@@ -518,6 +520,19 @@ class TestScanFile:findings = asyncio.run(scanner.scan_file("client.ts", source, symbols=[]))assert bool([f for f in findings if f["kind"] == "reject_unauthorized_false"]) is expected+ @pytest.mark.parametrize(+ ("source", "expected"),+ [+ ("requests.get(url, verify=False)\n", True),+ ('"tls_verify_false": "TLS verification turned off (verify=False).",\n', False),+ ("# verify=False disables certificate checks\n", False),+ ],+ )+ def test_tls_verify_false_ignores_prose(self, source: str, expected: bool) -> None:+ scanner = SecurityScanner(session=None, repo_id="r1") # type: ignore[arg-type]+ findings = asyncio.run(scanner.scan_file("client.py", source, symbols=[]))+ assert bool([f for f in findings if f["kind"] == "tls_verify_false"]) is expected+class TestPersistSecurityFindings:"""The persist.py wiring: source_map in, idempotent rows out."""@@ -1050,6 +1065,8 @@ class TestSecretPrecision:['client = OpenAI(api_key="ollama")\n','client = OpenAI(api_key="lmstudio")\n',+ '_IGNORE_TOKEN = "repowise-security-ignore"\n',+ 'API_KEY_HEADER = "x-api-key"\n','<Bar token="--chart-1" />\n',],)@@ -1060,6 +1077,8 @@ class TestSecretPrecision:"source",['TOKEN = "sk-live-9f8a7b6c5d4e"\n',+ 'SECRET = "k3y-9f8a-7b6c-5d4e-a1b2"\n',+ 'API_KEY = "Ab-cd-Ef-gh-ij-kl"\n','API_KEY = "sk-a****"\n',f'API_KEY = "{"q" * 40}"\n',],