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(security): scope sanitizer credential exception to audited example (#6624)

LearningCircuitb1299d2879c5
diff --git a/.gitleaks.toml b/.gitleaks.toml
index 87e8dd9b00..defdaaed5c 100644
--- a/.gitleaks.toml
+++ b/.gitleaks.toml
@@ -71,6 +71,11 @@ keywords = ["BEGIN PRIVATE KEY", "BEGIN RSA PRIVATE KEY", "BEGIN OPENSSH PRIVATE
# 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(...)`.
+#
+# NOTE on the [[rules.allowlists]] blocks below: TOML attaches each array
+# element to the most recently declared [[rules]] table — here always
+# credential-literal. Insert NEW [[rules]] ABOVE these blocks, never between
+# them, or the allowlists silently re-attach to the wrong rule.
[[rules]]
description = "Quoted credential literal"
id = "credential-literal"
@@ -102,6 +107,19 @@ paths = [
'''src/local_deep_research/web/routers/.*\.py$''',
]
+# Historical log_sanitizer docstrings use one audited placeholder in quoted
+# credential examples (alerts #8263-8265). Require BOTH this exact file and
+# that exact value; other credential literals in the file remain findings.
+# A value-and-path exception survives rebases without exempting the whole file.
+[[rules.allowlists]]
+description = "log_sanitizer: audited historical documentation placeholder"
+condition = "AND"
+regexTarget = "secret"
+paths = [
+ '''(?:^|/)src/local_deep_research/security/log_sanitizer\.py$''',
+]
+regexes = ['''^alice123$''']
+
# Allowlist - exclude common false positives
#
# Some paths below no longer exist in the working tree -- the Flask->FastAPI
diff --git a/.gitleaksignore b/.gitleaksignore
index 2ece477b01..be9c351582 100644
--- a/.gitleaksignore
+++ b/.gitleaksignore
@@ -4,6 +4,11 @@
# This file contains fingerprints of known false positives from historical commits.
# Format: commit:file:rule:line
#
+# For reviewed examples that recur across commits, prefer a rule-scoped
+# exception requiring BOTH the exact path and placeholder value in
+# .gitleaks.toml. Fingerprints do not survive rebases; exempting an entire
+# source file would also hide unrelated credentials.
+#
# These findings are NOT actual secrets - they are:
# - Python variable names containing "key", "password", "secret", "token"
# - Documentation examples with placeholder API keys
diff --git a/changelog.d/6624.security.md b/changelog.d/6624.security.md
new file mode 100644
index 0000000000..f1f63e7b51
--- /dev/null
+++ b/changelog.d/6624.security.md
@@ -0,0 +1 @@
+Limit the Gitleaks exception for historical `log_sanitizer.py` documentation to the exact reviewed placeholder in that file. This addresses alerts #8263-8265 across rebases while keeping other credential literals and provider-token rules active.
diff --git a/src/local_deep_research/security/log_sanitizer.py b/src/local_deep_research/security/log_sanitizer.py
index a77d6eeed7..c54fa1a06e 100644
--- a/src/local_deep_research/security/log_sanitizer.py
+++ b/src/local_deep_research/security/log_sanitizer.py
@@ -125,9 +125,11 @@ def redact_secrets(
replaced.
See ``tests/security/test_log_sanitizer.py::TestRedactSecrets`` for
- worked examples (doctest examples are omitted because the
- repository's gitleaks rule flags any token-shaped literal in
- docstrings).
+ worked examples (doctest examples are constrained because the
+ repository's gitleaks rule flags token-shaped literals in
+ docstrings; ``.gitleaks.toml`` exempts only one audited historical
+ example value in this file, while other credential literals and
+ token-shaped values remain scanned).
"""
if not message:
return message
diff --git a/tests/security/test_gitleaks_credential_rule.py b/tests/security/test_gitleaks_credential_rule.py
index af185ead22..50ef9d64bf 100644
--- a/tests/security/test_gitleaks_credential_rule.py
+++ b/tests/security/test_gitleaks_credential_rule.py
@@ -24,14 +24,15 @@ def _credential_rule() -> dict:
def _is_finding(line: str) -> bool:
+ """Check every literal, applying only the shared placeholder allowlist."""
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"]
+ return any(
+ not any(
+ re.search(pattern, match.group(rule["secretGroup"]))
+ for pattern in allowlist["regexes"]
+ )
+ for match in re.finditer(rule["regex"], line)
)
@@ -61,28 +62,17 @@ def test_credential_literal_rule_ignores_code_and_placeholders():
assert not _is_finding('password = "short"')
-def test_credential_literal_rule_with_gitleaks_cli(tmp_path):
+def gitleaks_cli():
gitleaks = os.environ.get("GITLEAKS_PATH") or 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")
+ return gitleaks
- 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"
+
+def _scan_credentials(gitleaks, scan_root, report):
result = subprocess.run(
[
gitleaks,
@@ -95,16 +85,103 @@ def test_credential_literal_rule_with_gitleaks_cli(tmp_path):
"json",
"--report-path",
str(report),
- str(tmp_path),
+ ".",
],
+ cwd=scan_root,
check=False,
capture_output=True,
text=True,
+ timeout=30,
)
- assert result.returncode == 1, result.stderr
- findings = [
+ assert result.returncode in (0, 1), result.stderr
+ return [
finding
for finding in json.loads(report.read_text(encoding="utf-8"))
if finding["RuleID"] == "credential-literal"
]
+
+
+def test_credential_literal_rule_with_gitleaks_cli(tmp_path, gitleaks_cli):
+ 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",
+ )
+ findings = _scan_credentials(
+ gitleaks_cli, tmp_path, tmp_path / "gitleaks-report.json"
+ )
assert {finding["StartLine"] for finding in findings} == {1, 2, 3, 4}
+
+
+def test_placeholder_does_not_hide_another_literal_on_the_same_line():
+ assert _is_finding(
+ '# {"password": "example-secret"}, {"password": "summer2026"}'
+ )
+ assert _is_finding(
+ '# {"password": "summer2026"}, {"password": "example-secret"}'
+ )
+
+
+def test_log_sanitizer_examples_use_shared_placeholders():
+ source = (
+ CONFIG_PATH.parent / "src/local_deep_research/security/log_sanitizer.py"
+ ).read_text(encoding="utf-8")
+ offenders = [
+ i
+ for i, line in enumerate(source.splitlines(), start=1)
+ if _is_finding(line)
+ ]
+ assert offenders == [], (
+ "Use shared credential placeholders in log_sanitizer.py examples; "
+ f"unexpected credential literals on lines {offenders}"
+ )
+
+
+def test_log_sanitizer_exception_requires_both_path_and_value(
+ tmp_path, gitleaks_cli
+):
+ scan_root = tmp_path / "scan"
+ allowed_path = "src/local_deep_research/security/log_sanitizer.py"
+ other_paths = [
+ "src/local_deep_research/security/other.py",
+ "unrelated_src/local_deep_research/security/log_sanitizer.py",
+ ]
+ source = scan_root / allowed_path
+ source.parent.mkdir(parents=True)
+ source.write_text(
+ "\n".join(
+ [
+ '# {"api_key": "alice123"}',
+ '# {"password": "summer2026"}',
+ '# {"password": "example-secret"}, {"password": "winter2027"}',
+ '# {"password": "alice123"}, {"password": "autumn2028"}',
+ '# {"password": "alice123-more"}',
+ '# {"password": "more-alice123"}',
+ ]
+ ),
+ encoding="utf-8",
+ )
+ for rel_path in other_paths:
+ other = scan_root / rel_path
+ other.parent.mkdir(parents=True, exist_ok=True)
+ other.write_text('# {"password": "alice123"}\n', encoding="utf-8")
+
+ findings = _scan_credentials(
+ gitleaks_cli, scan_root, tmp_path / "gitleaks-report.json"
+ )
+ actual = {
+ (Path(finding["File"]).as_posix(), finding["StartLine"])
+ for finding in findings
+ }
+ expected = {(allowed_path, line) for line in range(2, 7)}
+ expected.update((path, 1) for path in other_paths)
+ assert actual == expected