Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(ci): narrow generic secret detection to credential literals (#5133)

LearningCircuitb4c81d4851f2
diff --git a/.gitleaks.toml b/.gitleaks.toml
index d76511220e..18ae74ded6 100644
--- a/.gitleaks.toml
+++ b/.gitleaks.toml
@@ -60,12 +60,23 @@ id = "private-key"
regex = '''-----BEGIN (RSA |OPENSSH |DSA |EC |PGP )?PRIVATE KEY-----'''
keywords = ["BEGIN PRIVATE KEY", "BEGIN RSA PRIVATE KEY", "BEGIN OPENSSH PRIVATE KEY"]
+# The built-in generic-api-key rule intentionally ignores low-entropy values.
+# Keep a narrow companion rule for quoted credential literals so PR scans still
+# catch values such as `password = "summer2026"` without matching assignments
+# from functions or identifiers such as `password = get_user_password(...)`.
[[rules]]
-description = "Generic secret/password pattern"
-id = "generic-secret"
-regex = '''(?i)(password|secret|token|key)\s*[:=]\s*['"]?([a-zA-Z0-9_\-@#$%^&*]{8,})['"]?'''
-secretGroup = 2
-keywords = ["password", "secret", "token", "key"]
+description = "Quoted credential literal"
+id = "credential-literal"
+regex = '''(?i)(?:^|[\s{,(])['"]?(?:(?:[a-z][a-z0-9]*[_-])+(?:password|passwd|pwd|secret)|password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?token|access[_-]?token)['"]?\s*[:=]\s*['"]([^'"\r\n]{8,})['"]'''
+secretGroup = 1
+keywords = ["password", "passwd", "pwd", "secret", "token", "apikey", "api_key", "api-key"]
+
+[[rules.allowlists]]
+description = "Credential placeholders used in documentation and examples"
+regexTarget = "secret"
+regexes = [
+ '''(?i)^(?:not[-_ ]?a[-_ ]?secret|your[-_ ]?(?:password|secret)|replace[-_ ]?me|change[-_ ]?me|changeme|example[-_ ]?(?:password|secret)|dummy[-_ ]?(?:password|secret)|placeholder)$''',
+]
# Allowlist - exclude common false positives
[allowlist]
diff --git a/.gitleaksignore b/.gitleaksignore
index abf914c30a..0dad4aa0b5 100644
--- a/.gitleaksignore
+++ b/.gitleaksignore
@@ -721,6 +721,12 @@ e865d0bc2c645625b91f98b5208218beee256734:src/local_deep_research/web/routers/set
e865d0bc2c645625b91f98b5208218beee256734:src/local_deep_research/web/routers/settings.py:generic-secret:988
f6bbb00922985a435f542d55e361a116a16e33a4:src/local_deep_research/web/routers/settings.py:generic-secret:629
fd2519a30b003a6b1243589beaec54e11f0ab912:src/local_deep_research/web/routers/rag.py:generic-secret:114
+266b5925182d1b0a812e8a017dc0bd5249760482:README.md:aws-access-token:89
+694c5fec880ded973476943c229bd14ea181750b:README.md:aws-access-token:89
+8368ce435421f329b48f8e9b8b25859cc8f52cc9:README.md:aws-access-token:89
+a646559114f020b889d1275a7ff5c79007606146:README.md:aws-access-token:90
+b84d382ae670af3e6bcbc971d245ebbb60d6f8e8:README.md:aws-access-token:90
+fcecaaa53234fd1596dc29794d0af3bdb07536cb:README.md:aws-access-token:89
# --- Added 2026-07-16: generic-secret false positives from feature-branch
# commit 30557a9c0 (refactor/rag-vector-store), surfaced by the scheduled
diff --git a/tests/security/test_gitleaks_credential_rule.py b/tests/security/test_gitleaks_credential_rule.py
new file mode 100644
index 0000000000..fb591b1029
--- /dev/null
+++ b/tests/security/test_gitleaks_credential_rule.py
@@ -0,0 +1,110 @@
+"""Regression tests for the low-entropy credential-literal Gitleaks rule."""
+
+# allow: no-sut-import — guards the repository-level Gitleaks configuration
+
+import json
+import os
+import re
+import shutil
+import subprocess
+import tomllib
+from pathlib import Path
+
+import pytest
+
+
+CONFIG_PATH = Path(__file__).parents[2] / ".gitleaks.toml"
+
+
+def _credential_rule() -> dict:
+ config = tomllib.loads(CONFIG_PATH.read_text(encoding="utf-8"))
+ return next(
+ rule for rule in config["rules"] if rule["id"] == "credential-literal"
+ )
+
+
+def _is_finding(line: str) -> bool:
+ rule = _credential_rule()
+ match = re.search(rule["regex"], line)
+ if match is None:
+ return False
+ secret = match.group(rule["secretGroup"])
+ allowlist = rule["allowlists"][0]
+ return not any(
+ re.search(pattern, secret) for pattern in allowlist["regexes"]
+ )
+
+
+def test_credential_literal_rule_catches_bare_and_quoted_keys():
+ assert _is_finding('password = "summer2026"')
+ assert _is_finding(' secret: "winter2027"')
+ assert _is_finding('{"password": "autumn2028"}')
+ assert _is_finding("{'pwd': 'spring2029'}")
+ assert _is_finding('DB_PASSWORD="summer2026"')
+ assert _is_finding('db_password = "winter2027"')
+ assert _is_finding('client_secret = "autumn2028"')
+ assert _is_finding('api_key = "spring2029"')
+ assert _is_finding('AUTH_TOKEN = "summer2030"')
+ assert _is_finding('{"access-token": "winter2031"}')
+ assert _is_finding('token = "autumn2032"')
+
+
+def test_credential_literal_rule_ignores_code_and_placeholders():
+ assert not _is_finding("password = get_user_password(username)")
+ assert not _is_finding('password = "not-a-secret"')
+ assert not _is_finding('"password": "your-password"')
+ assert not _is_finding('secret = "replace-me"')
+ assert not _is_finding('secret = "changeme"')
+ assert _is_finding('password = "benchmark123"')
+ assert _is_finding('password = "xxxxxxxx"')
+ assert not _is_finding('key = "summer2026"')
+ assert not _is_finding('password = "short"')
+
+
+def test_credential_literal_rule_with_gitleaks_cli(tmp_path):
+ gitleaks = shutil.which("gitleaks")
+ if gitleaks is None:
+ if os.environ.get("REQUIRE_GITLEAKS") == "1":
+ pytest.fail("REQUIRE_GITLEAKS=1 but gitleaks is not installed")
+ pytest.skip("gitleaks is not installed")
+
+ fixture = tmp_path / "credential-canaries.txt"
+ fixture.write_text(
+ "\n".join(
+ [
+ 'password = "summer2026"',
+ 'DB_PASSWORD = "winter2027"',
+ '"client_secret": "autumn2028"',
+ 'AUTH_TOKEN = "spring2029"',
+ 'password = "not-a-secret"',
+ "password = get_user_password(username)",
+ ]
+ ),
+ encoding="utf-8",
+ )
+ report = tmp_path / "gitleaks-report.json"
+ result = subprocess.run(
+ [
+ gitleaks,
+ "dir",
+ "--no-banner",
+ "--redact",
+ "--config",
+ str(CONFIG_PATH),
+ "--report-format",
+ "json",
+ "--report-path",
+ str(report),
+ str(tmp_path),
+ ],
+ check=False,
+ capture_output=True,
+ text=True,
+ )
+ assert result.returncode == 1, result.stderr
+ findings = [
+ finding
+ for finding in json.loads(report.read_text(encoding="utf-8"))
+ if finding["RuleID"] == "credential-literal"
+ ]
+ assert {finding["StartLine"] for finding in findings} == {1, 2, 3, 4}