~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: address additional review feedback for security check
LearningCircuit1dbc97b41577
diff --git a/.github/scripts/check-file-writes.sh b/.github/scripts/check-file-writes.shnew file mode 100755index 0000000000..5b0787ecc5--- /dev/null+++ b/.github/scripts/check-file-writes.sh@@ -0,0 +1,184 @@+#!/bin/bash++# Security check for potential unencrypted file writes to disk+# This script helps prevent accidentally bypassing encryption at rest++set -e++echo "Checking for potential unencrypted file writes to disk..."+echo "========================================="++# Patterns that might indicate writing sensitive data to disk+# Note: Using basic grep patterns without lookaheads+SUSPICIOUS_PATTERNS=(+ # Python patterns+ "\.write\("+ "\.save\("+ "\.dump\("+ "open\(.*['\"]w['\"].*\)"+ "open\(.*['\"]wb['\"].*\)"+ "with.*open\(.*['\"]w['\"]"+ "with.*open\(.*['\"]wb['\"]"+ "\.to_csv\("+ "\.to_json\("+ "\.to_excel\("+ "\.to_pickle\("+ "tempfile\.NamedTemporaryFile.*delete=False"+ "Path.*\.write_text\("+ "Path.*\.write_bytes\("+ "shutil\.copy"+ "shutil\.move"+ "\.export_to_file\("+ "\.save_to_file\("+ "\.write_pdf\("+ "\.savefig\("+ # JavaScript patterns+ "fs\.writeFile"+ "fs\.writeFileSync"+ "fs\.createWriteStream"+ "fs\.appendFile"+)++# Directories to exclude from checks+EXCLUDE_DIRS=(+ "tests"+ "test"+ "__pycache__"+ ".git"+ "node_modules"+ ".venv"+ "venv"+ "migrations"+ "static/js/lib"+ "static/vendor"+)++# Files to exclude+EXCLUDE_FILES=(+ "*_test.py"+ "test_*.py"+ "*.test.js"+ "*.spec.js"+ "*.test.ts"+ "*.spec.ts"+ "setup.py"+ "webpack.config.js"+ "**/migrations/*.py"+)++# Safe keywords that indicate encrypted or safe operations+# Empty for now - will add on case-by-case basis+SAFE_KEYWORDS=(+)++# Known safe usage patterns (logs, configs, etc.)+# Empty for now - will add on case-by-case basis+SAFE_USAGE_PATTERNS=(+)++# Build exclude arguments for grep+EXCLUDE_ARGS=""+for dir in "${EXCLUDE_DIRS[@]}"; do+ EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude-dir=$dir"+done++for file in "${EXCLUDE_FILES[@]}"; do+ EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$file"+done++# Track if we found any issues+FOUND_ISSUES=0+ALL_MATCHES=""++echo "Scanning codebase for suspicious patterns..."++# Single pass to collect all matches+for pattern in "${SUSPICIOUS_PATTERNS[@]}"; do+ matches=$(grep -rn -- "$pattern" . $EXCLUDE_ARGS --include="*.py" --include="*.js" --include="*.ts" 2>/dev/null || true)+ if [ -n "$matches" ]; then+ ALL_MATCHES="$ALL_MATCHES$matches\n"+ fi+done++# Also check for specific problematic patterns in one pass+temp_matches=$(grep -rn -E "get_report_as_temp_file|tmp_path|tempfile|/tmp/" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null || true)+if [ -n "$temp_matches" ]; then+ ALL_MATCHES="$ALL_MATCHES$temp_matches\n"+fi++db_matches=$(grep -rn -E "report_content.*open|report_content.*write|markdown_content.*open|markdown_content.*write" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null || true)+if [ -n "$db_matches" ]; then+ ALL_MATCHES="$ALL_MATCHES$db_matches\n"+fi++export_matches=$(grep -rn -E "export.*Path|export.*path\.open|export.*\.write" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null || true)+if [ -n "$export_matches" ]; then+ ALL_MATCHES="$ALL_MATCHES$export_matches\n"+fi++# Now filter all matches at once+if [ -n "$ALL_MATCHES" ]; then+ echo "Filtering results for false positives..."++ # Remove duplicates and sort+ ALL_MATCHES=$(echo -e "$ALL_MATCHES" | sort -u)++ filtered_matches=""+ while IFS= read -r line; do+ [ -z "$line" ] && continue++ # Check if line contains safe keywords+ skip_line=0+ for safe_pattern in "${SAFE_KEYWORDS[@]}"; do+ if echo "$line" | grep -qE -- "$safe_pattern"; then+ skip_line=1+ break+ fi+ done++ # Check if line contains safe usage patterns+ if [ "$skip_line" -eq 0 ]; then+ for usage_pattern in "${SAFE_USAGE_PATTERNS[@]}"; do+ if echo "$line" | grep -qE -- "$usage_pattern"; then+ skip_line=1+ break+ fi+ done+ fi++ # Additional filters for test/mock files that might not be caught by path exclusion+ if [ "$skip_line" -eq 0 ]; then+ if echo "$line" | grep -qE "test|mock|stub" && ! echo "$line" | grep -q "#"; then+ skip_line=1+ fi+ fi++ if [ "$skip_line" -eq 0 ]; then+ filtered_matches="$filtered_matches$line\n"+ FOUND_ISSUES=1+ fi+ done <<< "$ALL_MATCHES"++ if [ -n "$filtered_matches" ] && [ "$FOUND_ISSUES" -eq 1 ]; then+ echo "⚠️ Found potential unencrypted file writes:"+ echo "========================================="+ echo -e "$filtered_matches"+ fi+fi++echo "========================================="++if [ $FOUND_ISSUES -eq 1 ]; then+ echo "❌ Security check failed: Found potential unencrypted file writes"+ echo ""+ echo "Please review the above findings and ensure:"+ echo "1. Sensitive data is not written to disk unencrypted"+ echo "2. Temporary files are properly cleaned up"+ echo "3. Use in-memory operations where possible"+ echo "4. If file writes are necessary, ensure they're encrypted or add '# Safe: <reason>' comment"+ echo ""+ echo "For exports, use the in-memory pattern like in export_report_to_memory()"+ exit 1+else+ echo "✅ Security check passed: No suspicious unencrypted file writes detected"+fidiff --git a/.github/workflows/security-file-write-check.yml b/.github/workflows/security-file-write-check.ymlindex 8126bd3660..2bc878dc5e 100644--- a/.github/workflows/security-file-write-check.yml+++ b/.github/workflows/security-file-write-check.yml@@ -25,179 +25,4 @@ jobs:- uses: actions/checkout@v4- name: Check for potential unencrypted file writes- run: |- echo "Checking for potential unencrypted file writes to disk..."- echo "========================================="-- # Patterns that might indicate writing sensitive data to disk- # Note: Using basic grep patterns without lookaheads- SUSPICIOUS_PATTERNS=(- # Python patterns- "\.write\("- "\.save\("- "\.dump\("- "open\(.*['\"]w['\"].*\)"- "open\(.*['\"]wb['\"].*\)"- "\.to_csv\("- "\.to_json\("- "\.to_excel\("- "\.to_pickle\("- "tempfile\.NamedTemporaryFile.*delete=False"- "Path.*\.write_text\("- "Path.*\.write_bytes\("- "shutil\.copy"- "shutil\.move"- "\.export_to_file\("- "\.save_to_file\("- "\.write_pdf\("- "\.savefig\("- # JavaScript patterns- "fs\.writeFile"- "fs\.writeFileSync"- "fs\.createWriteStream"- "fs\.appendFile"- )-- # Directories to exclude from checks- EXCLUDE_DIRS=(- "tests"- "test"- "__pycache__"- ".git"- "node_modules"- ".venv"- "venv"- "migrations"- "static/js/lib"- "static/vendor"- )-- # Files to exclude- EXCLUDE_FILES=(- "*_test.py"- "test_*.py"- "*.test.js"- "*.spec.js"- "*.test.ts"- "*.spec.ts"- "setup.py"- "webpack.config.js"- "**/migrations/*.py"- )-- # Safe keywords that indicate encrypted or safe operations- # Empty for now - will add on case-by-case basis- SAFE_KEYWORDS=(- )-- # Known safe usage patterns (logs, configs, etc.)- # Empty for now - will add on case-by-case basis- SAFE_USAGE_PATTERNS=(- )-- # Build exclude arguments for grep- EXCLUDE_ARGS=""- for dir in "${EXCLUDE_DIRS[@]}"; do- EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude-dir=$dir"- done-- for file in "${EXCLUDE_FILES[@]}"; do- EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$file"- done-- # Track if we found any issues- FOUND_ISSUES=0- ALL_MATCHES=""-- echo "Scanning codebase for suspicious patterns..."-- # Single pass to collect all matches- for pattern in "${SUSPICIOUS_PATTERNS[@]}"; do- matches=$(grep -rn -- "$pattern" . $EXCLUDE_ARGS --include="*.py" --include="*.js" --include="*.ts" 2>/dev/null || true)- if [ -n "$matches" ]; then- ALL_MATCHES="$ALL_MATCHES$matches\n"- fi- done-- # Also check for specific problematic patterns in one pass- temp_matches=$(grep -rn -E "get_report_as_temp_file|tmp_path|tempfile|/tmp/" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null || true)- if [ -n "$temp_matches" ]; then- ALL_MATCHES="$ALL_MATCHES$temp_matches\n"- fi-- db_matches=$(grep -rn -E "report_content.*open|report_content.*write|markdown_content.*open|markdown_content.*write" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null || true)- if [ -n "$db_matches" ]; then- ALL_MATCHES="$ALL_MATCHES$db_matches\n"- fi-- export_matches=$(grep -rn -E "export.*Path|export.*path\.open|export.*\.write" . --include="*.py" 2>/dev/null || true)- if [ -n "$export_matches" ]; then- ALL_MATCHES="$ALL_MATCHES$export_matches\n"- fi-- # Now filter all matches at once- if [ -n "$ALL_MATCHES" ]; then- echo "Filtering results for false positives..."-- # Remove duplicates and sort- ALL_MATCHES=$(echo -e "$ALL_MATCHES" | sort -u)-- filtered_matches=""- while IFS= read -r line; do- [ -z "$line" ] && continue-- # Check if line contains safe keywords- skip_line=0- for safe_pattern in "${SAFE_KEYWORDS[@]}"; do- if echo "$line" | grep -qE -- "$safe_pattern"; then- skip_line=1- break- fi- done-- # Check if line contains safe usage patterns- if [ "$skip_line" -eq 0 ]; then- for usage_pattern in "${SAFE_USAGE_PATTERNS[@]}"; do- if echo "$line" | grep -qE -- "$usage_pattern"; then- skip_line=1- break- fi- done- fi-- # Additional filters for test/mock files that might not be caught by path exclusion- if [ "$skip_line" -eq 0 ]; then- if echo "$line" | grep -qE "test|mock|stub" | grep -qv "#"; then- skip_line=1- fi- fi-- if [ "$skip_line" -eq 0 ]; then- filtered_matches="$filtered_matches$line\n"- FOUND_ISSUES=1- fi- done <<< "$ALL_MATCHES"-- if [ -n "$filtered_matches" ] && [ "$FOUND_ISSUES" -eq 1 ]; then- echo "⚠️ Found potential unencrypted file writes:"- echo "========================================="- echo -e "$filtered_matches"- fi- fi-- echo "========================================="-- if [ $FOUND_ISSUES -eq 1 ]; then- echo "❌ Security check failed: Found potential unencrypted file writes"- echo ""- echo "Please review the above findings and ensure:"- echo "1. Sensitive data is not written to disk unencrypted"- echo "2. Temporary files are properly cleaned up"- echo "3. Use in-memory operations where possible"- echo "4. If file writes are necessary, ensure they're encrypted or add '# Safe: <reason>' comment"- echo ""- echo "For exports, use the in-memory pattern like in export_report_to_memory()"- exit 1- else- echo "✅ Security check passed: No suspicious unencrypted file writes detected"- fi+ run: ./.github/scripts/check-file-writes.sh