Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(security): skip values containing shell or template expansions (#3319)

Rishabh Mishra70c2a39a0d9e
diff --git a/packages/core/src/repowise/core/analysis/security_scan.py b/packages/core/src/repowise/core/analysis/security_scan.py
index 0537865bd..6d5ddaf7f 100644
--- a/packages/core/src/repowise/core/analysis/security_scan.py
+++ b/packages/core/src/repowise/core/analysis/security_scan.py
@@ -423,9 +423,9 @@ _SECRET_SPECIFICITY: dict[str, int] = {
# 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.
-_TEMPLATE_VALUE = re.compile(r"\{\{.*\}\}|\$\{[^}]*\}|\$\(.*\)")
+_TEMPLATE_VALUE = re.compile(r"\{\{.*?\}\}|\$\{.*?\}|\$\(.*?\)")
_SCHEME_TEMPLATE_VALUE = re.compile(
- r"(?i:(?:bearer|basic|token))\s+(?:\{\{.*\}\}|\$\{[^}]*\}|\$\(.*\))"
+ r"(?i:(?:bearer|basic|token))\s+(?:\{\{.*?\}\}|\$\{.*?\}|\$\(.*?\))"
)
_OWN_NAME_VALUE = re.compile(r"[A-Za-z_-]+")
_CONSTANT_NAME = re.compile(r"[A-Z][A-Z0-9_]*")
@@ -474,8 +474,8 @@ def _is_secret_value(kind: str, val: str, name: str = "") -> bool:
return False
# A leading ``--`` is a CSS custom property or a CLI flag, not a key.
return not (
- _TEMPLATE_VALUE.fullmatch(value)
- or _SCHEME_TEMPLATE_VALUE.fullmatch(value)
+ _TEMPLATE_VALUE.search(value)
+ or _SCHEME_TEMPLATE_VALUE.search(value)
or _is_plain_word(value)
or value.startswith("--")
)
diff --git a/tests/unit/analysis/test_security_scan.py b/tests/unit/analysis/test_security_scan.py
index b4a0767dc..25def5de4 100644
--- a/tests/unit/analysis/test_security_scan.py
+++ b/tests/unit/analysis/test_security_scan.py
@@ -1205,6 +1205,9 @@ class TestSecretPrecision:
("README.md", 'export OPENAI_API_KEY="your-key-here"\n'),
("README.md", 'API_KEY="sk-<your key>"\n'),
("README.md", 'SECRET="$(op read op://vault/app/secret)"\n'),
+ ("deploy.sh", 'TOKEN="$(kubectl get secret app -o jsonpath=\x27{.data.t}\x27 | base64 -d)"\n'),
+ ("src/app.py", 'API_KEY = "prefix-${VAR}-suffix"\n'),
+ ("src/app.py", 'TOKEN = "prefix-{{var}}-suffix"\n'),
("src/app.py", 'TOKEN = "xxxxxxxxxxxx"\n'),
],
)
@@ -1247,6 +1250,7 @@ class TestSecretPrecision:
('TOKEN = "Bearer eyJhbGciOiJIUzI1NiJ9abc"\n', "hardcoded_secret"),
('const val API_TOKEN = "productionAccessKey"\n', "hardcoded_secret"),
('password="Tr0ub4dor 3xyz"\n', "hardcoded_password"),
+ ('password = "plain$password123"\n', "hardcoded_password"),
],
)
def test_credential_like_values_still_fire(self, source: str, kind: str) -> None: