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.

ci: add pre-commit hook to detect raw console.* calls in JavaScript (#2963)

LearningCircuitaa23e38a30af
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 97410d586b..8bab91f482 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -159,6 +159,13 @@ repos:
exclude: (tests?/|spec\.|test\.|\.test\.|\.spec\.)
description: "Detect escapeHtml() inside functions that already escape internally
(showError, showSuccess, showInfo, showAlert)"
+ - id: check-raw-console
+ name: Check for raw console.* calls in JavaScript
+ entry: .pre-commit-hooks/check-raw-console.py
+ language: script
+ files: \.js$
+ exclude: (tests?/|spec\.|test\.|\.test\.|\.spec\.)
+ description: "Ensure JS files use SafeLogger instead of raw console.log/error/warn"
- id: check-image-pinning
name: Check Docker Image Pinning
entry: .pre-commit-hooks/check-image-pinning.sh
diff --git a/.pre-commit-hooks/check-raw-console.py b/.pre-commit-hooks/check-raw-console.py
new file mode 100755
index 0000000000..3ea1cb14ce
--- /dev/null
+++ b/.pre-commit-hooks/check-raw-console.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+"""
+Pre-commit hook to detect raw console.* calls in JavaScript files.
+
+All JS logging should use SafeLogger (from security/safe-logger.js) which
+sanitises output and prevents accidental leakage of sensitive data.
+
+Allowed exceptions:
+ - safe-logger.js itself (it wraps console.*)
+ - Comment lines (// or *)
+ - Test files (excluded via pre-commit config)
+"""
+
+import re
+import sys
+from pathlib import Path
+
+RAW_CONSOLE_RE = re.compile(r"\bconsole\.(log|error|warn|info|debug)\b")
+
+# Files where raw console.* is legitimate
+ALLOWED_FILES = {"safe-logger.js"}
+
+
+def check_file(file_path):
+ """Return list of (line_number, line_text) for violations."""
+ if Path(file_path).name in ALLOWED_FILES:
+ return []
+
+ violations = []
+ with open(file_path, "r", encoding="utf-8") as f:
+ for lineno, line in enumerate(f, start=1):
+ stripped = line.lstrip()
+ # Skip comment lines
+ if stripped.startswith("//") or stripped.startswith("*"):
+ continue
+ if RAW_CONSOLE_RE.search(line):
+ violations.append((lineno, line.rstrip()))
+ return violations
+
+
+def main():
+ exit_code = 0
+ for file_path in sys.argv[1:]:
+ violations = check_file(file_path)
+ for lineno, line in violations:
+ print(
+ f"{file_path}:{lineno}: Use SafeLogger instead of raw console.*"
+ )
+ print(f" {line}")
+ exit_code = 1
+
+ if exit_code:
+ print()
+ print(
+ "Hint: import SafeLogger and use SafeLogger.log/error/warn/info/debug"
+ )
+
+ return exit_code
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/src/local_deep_research/web/static/js/pages/news.js b/src/local_deep_research/web/static/js/pages/news.js
index c297cea667..e404e65faa 100644
--- a/src/local_deep_research/web/static/js/pages/news.js
+++ b/src/local_deep_research/web/static/js/pages/news.js
@@ -15,7 +15,7 @@ function safeRenderHTML(container, htmlString) {
// be available when this defer script first runs. Fall back to textContent
// (which is always XSS-safe) until DOMPurify is ready.
if (!window.DOMPurify) {
- console.warn('DOMPurify not yet loaded — rendering as plain text (safe fallback)');
+ SafeLogger.warn('DOMPurify not yet loaded — rendering as plain text (safe fallback)');
while (container.firstChild) {
container.removeChild(container.firstChild);
}