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.

feat: Enhanced CI security checks with LDR-specific validations (#433)

LearningCircuit76cc5c0ef516
diff --git a/.github/workflows/file-whitelist-check.yml b/.github/workflows/file-whitelist-check.yml
index 103c784906..e8778e7bf6 100644
--- a/.github/workflows/file-whitelist-check.yml
+++ b/.github/workflows/file-whitelist-check.yml
@@ -30,10 +30,12 @@ jobs:
"\.yaml$"
"\.sh$"
"\.cfg$"
+ "\.flake8$"
"\.ipynb$"
"\.template$"
"^\.gitignore$"
"^\.gitkeep$"
+ ".*\.gitkeep$"
"^\.pre-commit-config\.yaml$"
"^\.isort\.cfg$"
"^\.coveragerc$"
@@ -68,6 +70,12 @@ jobs:
SECRET_VIOLATIONS=()
BINARY_FILES=()
SUSPICIOUS_FILES=()
+ RESEARCH_DATA_VIOLATIONS=()
+ FLASK_SECRET_VIOLATIONS=()
+ ENV_FILE_VIOLATIONS=()
+ HIGH_ENTROPY_VIOLATIONS=()
+ HARDCODED_PATH_VIOLATIONS=()
+ HARDCODED_IP_VIOLATIONS=()
for file in $CHANGED_FILES; do
# Skip deleted files
@@ -103,71 +111,382 @@ jobs:
BINARY_FILES+=("$file")
fi
- # 4. Secret pattern check in file content
+ # 4. Secret pattern check in file content - whitelist approach
if [ -f "$file" ] && [ -r "$file" ]; then
- # Check for common secret patterns
- if grep -iE "(api[_-]?key|secret|password|token|private[_-]?key)" "$file" >/dev/null 2>&1; then
- # Exclude common false positives
- if ! grep -iE "(example|sample|test|mock|placeholder|<.*>|\{\{.*\}\})" "$file" >/dev/null 2>&1; then
- SECRET_VIOLATIONS+=("$file")
+ # Define whitelist patterns for legitimate files that can contain sensitive-looking keywords
+ SAFE_FILE_PATTERNS=(
+ "src/local_deep_research/metrics/.*\.py$"
+ "src/local_deep_research/web_search_engines/.*\.py$"
+ "src/local_deep_research/web/services/.*\.py$"
+ "src/local_deep_research/utilities/.*\.py$"
+ "src/local_deep_research/config/.*\.py$"
+ "src/local_deep_research/.*migrate.*\.py$"
+ "src/local_deep_research/advanced_search_system/.*\.py$"
+ "src/local_deep_research/benchmarks/.*\.py$"
+ "docs/.*\.md$"
+ "tests/.*\.py$"
+ ".*test.*\.py$"
+ ".*mock.*\.py$"
+ ".*example.*\.py$"
+ )
+
+ # Check if file matches whitelist patterns
+ FILE_WHITELISTED=false
+ for pattern in "${SAFE_FILE_PATTERNS[@]}"; do
+ if echo "$file" | grep -qE "$pattern"; then
+ FILE_WHITELISTED=true
+ break
+ fi
+ done
+
+ # Only check for secrets if file is not whitelisted
+ if [ "$FILE_WHITELISTED" = "false" ]; then
+ # Enhanced secret detection with LLM provider keys
+ if grep -iE "(api[_-]?key|secret|password|token|private[_-]?key|sk-[a-zA-Z0-9]{20,}|claude-[a-zA-Z0-9]{20,}|AIzaSy[a-zA-Z0-9_-]{33})" "$file" >/dev/null 2>&1; then
+ # Additional check for obvious false positives
+ if ! grep -iE "(example|sample|test|mock|placeholder|<.*>|\{\{.*\}\})" "$file" >/dev/null 2>&1; then
+ SECRET_VIOLATIONS+=("$file")
+ fi
fi
fi
fi
- # 5. Suspicious filename patterns
+ # 5. Suspicious filename patterns - whitelist approach
+ SAFE_FILENAME_PATTERNS=(
+ ".*token_counter.*\.py$"
+ ".*migrate.*token.*\.py$"
+ ".*enhanced.*token.*\.md$"
+ "docs/.*token.*\.md$"
+ "tests/.*\.py$"
+ ".*test.*\.py$"
+ )
+
+ # Check if filename looks suspicious
if echo "$file" | grep -iE "(secret|password|token|api[_-]?key|\.key$|\.pem$|\.p12$|\.pfx$|\.env$)" >/dev/null; then
- SUSPICIOUS_FILES+=("$file")
+ # Check if filename matches whitelist patterns
+ FILENAME_WHITELISTED=false
+ for pattern in "${SAFE_FILENAME_PATTERNS[@]}"; do
+ if echo "$file" | grep -qE "$pattern"; then
+ FILENAME_WHITELISTED=true
+ break
+ fi
+ done
+
+ if [ "$FILENAME_WHITELISTED" = "false" ]; then
+ SUSPICIOUS_FILES+=("$file")
+ fi
+ fi
+
+ # 6. LDR-specific security checks
+ # Check for research data leakage
+ if [ -f "$file" ] && [ -r "$file" ]; then
+ # Check for hardcoded research queries in non-test files
+ if ! echo "$file" | grep -qE "(test|mock|example)"; then
+ if grep -E "(research_id|session_id|query_id).*=.*[\"'][0-9a-f]{8,}[\"']" "$file" >/dev/null 2>&1; then
+ RESEARCH_DATA_VIOLATIONS+=("$file")
+ fi
+ fi
+
+ # Check for Flask secret keys
+ if grep -E "SECRET_KEY.*=.*[\"'][^\"']{16,}[\"']" "$file" >/dev/null 2>&1; then
+ if ! grep -iE "(os\.environ|getenv|config\[|example|placeholder)" "$file" >/dev/null 2>&1; then
+ FLASK_SECRET_VIOLATIONS+=("$file")
+ fi
+ fi
+
+ # Check for environment files
+ if echo "$file" | grep -E "\.(env|env\.[a-zA-Z]+)$" >/dev/null; then
+ ENV_FILE_VIOLATIONS+=("$file")
+ fi
+
+ # Check for high-entropy strings (potential keys/secrets)
+ if [ -f "$file" ] && [ -r "$file" ]; then
+ # Skip HTML files and other safe file types for entropy checks
+ if ! echo "$file" | grep -qE "\.(html|css|js|json|yml|yaml|md)$"; then
+ # Look for base64-like strings or hex strings that are suspiciously long
+ if grep -E "[a-zA-Z0-9+/]{40,}={0,2}|[a-f0-9]{40,}" "$file" >/dev/null 2>&1; then
+ # Exclude common false positives
+ if ! grep -iE "(sha256|md5|hash|test|example|fixture|integrity)" "$file" >/dev/null 2>&1; then
+ HIGH_ENTROPY_VIOLATIONS+=("$file")
+ fi
+ fi
+ fi
+ fi
+
+ # Check for hardcoded paths (Unix/Windows)
+ if ! echo "$file" | grep -qE "(test|mock|example|\.md$|docker|Docker|\.yml$|\.yaml$)"; then
+ # Look for absolute paths and user home directories
+ if grep -E "(/home/[a-zA-Z0-9_-]+|/Users/[a-zA-Z0-9_-]+|C:\\\\Users\\\\[a-zA-Z0-9_-]+|/opt/|/var/|/etc/|/usr/local/)" "$file" >/dev/null 2>&1; then
+ # Exclude common false positives and Docker volume mounts
+ if ! grep -iE "(example|sample|placeholder|TODO|FIXME|/usr/local/bin|/etc/hosts|documentation|/etc/searxng|volumes?:|docker)" "$file" >/dev/null 2>&1; then
+ HARDCODED_PATH_VIOLATIONS+=("$file")
+ fi
+ fi
+ fi
+
+ # Check for hardcoded IP addresses
+ if ! echo "$file" | grep -qE "(test|mock|example|\.md$)"; then
+ # Look for IPv4 addresses (excluding common safe ones)
+ if grep -E "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" "$file" >/dev/null 2>&1; then
+ # Exclude localhost, documentation IPs, and common examples
+ if ! grep -E "\b(127\.0\.0\.1|0\.0\.0\.0|localhost|192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|255\.255\.255\.|192\.0\.2\.|198\.51\.100\.|203\.0\.113\.)" "$file" >/dev/null 2>&1; then
+ # Additional check to exclude obvious non-IPs (version numbers, etc)
+ if grep -E "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" "$file" | grep -vE "(version|v[0-9]+\.|release|tag)" >/dev/null 2>&1; then
+ HARDCODED_IP_VIOLATIONS+=("$file")
+ fi
+ fi
+ fi
+ fi
fi
done
- # Report all violations
+ # Report all violations with detailed explanations
TOTAL_VIOLATIONS=0
if [ ${#WHITELIST_VIOLATIONS[@]} -gt 0 ]; then
echo ""
- echo "❌ WHITELIST VIOLATIONS:"
+ echo "❌ WHITELIST VIOLATIONS - File types not allowed in repository:"
+ echo " These files don't match any allowed file extension patterns."
+ echo " If these are legitimate files, add them to ALLOWED_PATTERNS in the workflow."
+ echo ""
for violation in "${WHITELIST_VIOLATIONS[@]}"; do
- echo " - $violation (file type not allowed)"
+ echo " 🚫 $violation"
+
+ # Show file type and extension
+ FILE_EXT="${violation##*.}"
+ if [ -f "$violation" ]; then
+ FILE_TYPE=$(file -b "$violation" 2>/dev/null || echo "unknown")
+ echo " → File extension: .$FILE_EXT"
+ echo " → File type: $FILE_TYPE"
+ echo " → First few lines:"
+ head -3 "$violation" 2>/dev/null | while read line; do
+ echo " $line"
+ done
+ fi
+
+ echo " → Issue: File extension/type not in whitelist"
+ echo " → Fix: Add pattern to ALLOWED_PATTERNS or rename file"
+ echo ""
done
TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#WHITELIST_VIOLATIONS[@]}))
fi
if [ ${#LARGE_FILES[@]} -gt 0 ]; then
echo ""
- echo "❌ LARGE FILES (>1MB):"
+ echo "❌ LARGE FILES (>1MB) - Files too big for repository:"
+ echo " Large files should typically be stored externally or compressed."
+ echo ""
for violation in "${LARGE_FILES[@]}"; do
- echo " - $violation"
+ echo " 📏 $violation"
+ echo " → Issue: File size exceeds 1MB limit"
+ echo " → Fix: Use Git LFS, external storage, or compress the file"
+ echo ""
done
TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#LARGE_FILES[@]}))
fi
if [ ${#BINARY_FILES[@]} -gt 0 ]; then
echo ""
- echo "⚠️ BINARY FILES DETECTED:"
+ echo "⚠️ BINARY FILES DETECTED - Review these carefully:"
+ echo " Binary files may contain sensitive data and can't be easily reviewed."
+ echo ""
for violation in "${BINARY_FILES[@]}"; do
- echo " - $violation"
+ echo " 🔒 $violation"
+ echo " → Issue: Binary file detected (contents not reviewable)"
+ echo " → Action: Verify this file doesn't contain sensitive data"
+ echo ""
done
- echo " (Binary files may contain sensitive data)"
fi
if [ ${#SECRET_VIOLATIONS[@]} -gt 0 ]; then
echo ""
- echo "❌ POTENTIAL SECRETS IN FILE CONTENT:"
+ echo "❌ POTENTIAL SECRETS IN FILE CONTENT - Suspicious patterns found:"
+ echo " These files contain keywords like 'api_key', 'secret', 'password', 'token' but"
+ echo " are not in the whitelisted safe directories. Review them carefully!"
+ echo ""
for violation in "${SECRET_VIOLATIONS[@]}"; do
- echo " - $violation"
+ echo " 🔍 EXAMINING: $violation"
+
+ # Show the specific lines that triggered the detection
+ echo " → Suspicious content found:"
+ grep -n -iE "(api[_-]?key|secret|password|token|private[_-]?key)" "$violation" 2>/dev/null | head -5 | while read line; do
+ echo " $line"
+ done
+
+ # Show file type and size for context
+ if [ -f "$violation" ]; then
+ FILE_TYPE=$(file -b "$violation" 2>/dev/null || echo "unknown")
+ FILE_SIZE=$(stat -c%s "$violation" 2>/dev/null || echo "unknown")
+ echo " → File info: $FILE_TYPE (${FILE_SIZE} bytes)"
+ fi
+
+ echo " → Issue: Contains sensitive-looking keywords outside whitelisted areas"
+ echo " → Fix: Either add to SAFE_FILE_PATTERNS whitelist or remove secrets"
+ echo ""
done
TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#SECRET_VIOLATIONS[@]}))
fi
if [ ${#SUSPICIOUS_FILES[@]} -gt 0 ]; then
echo ""
- echo "❌ SUSPICIOUS FILENAMES:"
+ echo "❌ SUSPICIOUS FILENAMES - Files with security-sensitive names:"
+ echo " These filenames contain words that often indicate sensitive files."
+ echo ""
for violation in "${SUSPICIOUS_FILES[@]}"; do
- echo " - $violation"
+ echo " 🚨 $violation"
+
+ # Show which keyword triggered the detection
+ if echo "$violation" | grep -qi "secret"; then
+ echo " → Triggered by: 'secret' in filename"
+ elif echo "$violation" | grep -qi "password"; then
+ echo " → Triggered by: 'password' in filename"
+ elif echo "$violation" | grep -qi "token"; then
+ echo " → Triggered by: 'token' in filename"
+ elif echo "$violation" | grep -qi "api"; then
+ echo " → Triggered by: 'api' in filename"
+ elif echo "$violation" | grep -qi "key"; then
+ echo " → Triggered by: 'key' in filename"
+ fi
+
+ # Show file content preview if it exists
+ if [ -f "$violation" ]; then
+ FILE_TYPE=$(file -b "$violation" 2>/dev/null || echo "unknown")
+ FILE_SIZE=$(stat -c%s "$violation" 2>/dev/null || echo "unknown")
+ echo " → File info: $FILE_TYPE (${FILE_SIZE} bytes)"
+ echo " → Content preview:"
+ head -3 "$violation" 2>/dev/null | while read line; do
+ echo " $line"
+ done
+ fi
+
+ echo " → Issue: Filename contains suspicious keywords (secret/password/token/key)"
+ echo " → Fix: Rename file or add to SAFE_FILENAME_PATTERNS whitelist"
+ echo ""
done
TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#SUSPICIOUS_FILES[@]}))
fi
+ # LDR-specific violation reports
+ if [ ${#RESEARCH_DATA_VIOLATIONS[@]} -gt 0 ]; then
+ echo ""
+ echo "❌ RESEARCH DATA LEAKAGE - Hardcoded research session data found:"
+ echo " Research IDs and session data should never be hardcoded in production code."
+ echo ""
+ for violation in "${RESEARCH_DATA_VIOLATIONS[@]}"; do
+ echo " 📊 $violation"
+
+ # Show the specific lines with research data
+ echo " → Found hardcoded research data:"
+ grep -n -E "(research_id|session_id|query_id).*=.*[\"'][0-9a-f]{8,}[\"']" "$violation" 2>/dev/null | head -3 | while read line; do
+ echo " $line"
+ done
+
+ echo " → Issue: Hardcoded research/session IDs in non-test file"
+ echo " → Fix: Use environment variables or configuration files"
+ echo ""
+ done
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#RESEARCH_DATA_VIOLATIONS[@]}))
+ fi
+
+ if [ ${#FLASK_SECRET_VIOLATIONS[@]} -gt 0 ]; then
+ echo ""
+ echo "❌ FLASK SECRET KEY - Hardcoded Flask secret keys found:"
+ echo " Flask secret keys must never be hardcoded for security reasons."
+ echo ""
+ for violation in "${FLASK_SECRET_VIOLATIONS[@]}"; do
+ echo " 🔐 $violation"
+
+ # Show the specific lines with secret keys
+ echo " → Found hardcoded Flask secret key:"
+ grep -n -E "SECRET_KEY.*=.*[\"'][^\"']{16,}[\"']" "$violation" 2>/dev/null | head -3 | while read line; do
+ echo " $line"
+ done
+
+ echo " → Issue: Hardcoded Flask SECRET_KEY"
+ echo " → Fix: Use os.environ or load from secure config file"
+ echo ""
+ done
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#FLASK_SECRET_VIOLATIONS[@]}))
+ fi
+
+ if [ ${#ENV_FILE_VIOLATIONS[@]} -gt 0 ]; then
+ echo ""
+ echo "❌ ENVIRONMENT FILES - .env files detected:"
+ echo " Environment files contain sensitive configuration and should never be committed."
+ echo ""
+ for violation in "${ENV_FILE_VIOLATIONS[@]}"; do
+ echo " 🌍 $violation"
+ echo " → Issue: Environment file in repository"
+ echo " → Fix: Add to .gitignore and use .env.example instead"
+ echo ""
+ done
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#ENV_FILE_VIOLATIONS[@]}))
+ fi
+
+ if [ ${#HIGH_ENTROPY_VIOLATIONS[@]} -gt 0 ]; then
+ echo ""
+ echo "❌ HIGH ENTROPY STRINGS - Potential secrets or keys detected:"
+ echo " Long random strings may be API keys, tokens, or other secrets."
+ echo ""
+ for violation in "${HIGH_ENTROPY_VIOLATIONS[@]}"; do
+ echo " 🎲 $violation"
+
+ # Show sample of high entropy strings
+ echo " → Found high-entropy strings:"
+ grep -n -E "[a-zA-Z0-9+/]{40,}={0,2}|[a-f0-9]{40,}" "$violation" 2>/dev/null | head -3 | while read line; do
+ # Truncate long lines for readability
+ echo " ${line:0:120}..."
+ done
+
+ echo " → Issue: High-entropy strings that could be secrets"
+ echo " → Fix: Review and move to environment variables if sensitive"
+ echo ""
+ done
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#HIGH_ENTROPY_VIOLATIONS[@]}))
+ fi
+
+ if [ ${#HARDCODED_PATH_VIOLATIONS[@]} -gt 0 ]; then
+ echo ""
+ echo "❌ HARDCODED PATHS - System-specific paths detected:"
+ echo " Absolute paths can expose system structure and break portability."
+ echo ""
+ for violation in "${HARDCODED_PATH_VIOLATIONS[@]}"; do
+ echo " 📁 $violation"
+
+ # Show the specific hardcoded paths
+ echo " → Found hardcoded paths:"
+ grep -n -E "(/home/[a-zA-Z0-9_-]+|/Users/[a-zA-Z0-9_-]+|C:\\\\Users\\\\[a-zA-Z0-9_-]+|/opt/|/var/|/etc/|/usr/local/)" "$violation" 2>/dev/null | head -5 | while read line; do
+ echo " $line"
+ done
+
+ echo " → Issue: Hardcoded absolute paths reduce portability"
+ echo " → Fix: Use relative paths, environment variables, or config files"
+ echo ""
+ done
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#HARDCODED_PATH_VIOLATIONS[@]}))
+ fi
+
+ if [ ${#HARDCODED_IP_VIOLATIONS[@]} -gt 0 ]; then
+ echo ""
+ echo "❌ HARDCODED IP ADDRESSES - External IP addresses detected:"
+ echo " Hardcoded IPs can expose infrastructure and cause connectivity issues."
+ echo ""
+ for violation in "${HARDCODED_IP_VIOLATIONS[@]}"; do
+ echo " 🌐 $violation"
+
+ # Show the specific IP addresses
+ echo " → Found hardcoded IP addresses:"
+ grep -n -E "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" "$violation" 2>/dev/null | grep -v -E "(127\.0\.0\.1|0\.0\.0\.0|localhost|192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|255\.255\.255\.|192\.0\.2\.|198\.51\.100\.|203\.0\.113\.)" | head -5 | while read line; do
+ echo " $line"
+ done
+
+ echo " → Issue: Hardcoded IP addresses (non-private/localhost)"
+ echo " → Fix: Use DNS names, environment variables, or config files"
+ echo ""
+ done
+ TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#HARDCODED_IP_VIOLATIONS[@]}))
+ fi
+
# Final result
if [ $TOTAL_VIOLATIONS -eq 0 ]; then
echo ""
@@ -180,6 +499,10 @@ jobs:
echo " - Use environment variables for secrets"
echo " - Update whitelist for legitimate file types"
echo " - Compress large files or use Git LFS"
+ echo " - Never hardcode research data or session IDs"
+ echo " - Use .env.example files instead of .env"
+ echo " - Replace absolute paths with relative paths or configs"
+ echo " - Use DNS names instead of hardcoded IP addresses"
echo ""
echo "⚠️ SECURITY REMINDER: This is a public repository!"
echo " Never commit sensitive data, API keys, or personal information."
diff --git a/src/local_deep_research/web/templates/pages/cost_analytics.html b/src/local_deep_research/web/templates/pages/cost_analytics.html
index 10bfe6cc8b..e01e04daec 100644
--- a/src/local_deep_research/web/templates/pages/cost_analytics.html
+++ b/src/local_deep_research/web/templates/pages/cost_analytics.html
@@ -468,7 +468,7 @@
<!-- Header -->
<div class="cost-header">
<div class="cost-title">
- <h1><i class="fas fa-dollar-sign"></i> Cost Analytics</h1>
+ <h1><i class="fas fa-dollar-sign"></i> Cost Analytics <span style="color: var(--warning-color, #f39c12); font-size: 0.75em; font-weight: normal;">(Experimental)</span></h1>
<a href="/metrics" class="back-button">
<i class="fas fa-arrow-left"></i> Back to Metrics
</a>